Skip to content

Commit 6a534cd

Browse files
test: add unit test for MailtrapClient to validate error handling when testInboxId is missing in sandbox mode
1 parent 0a2d134 commit 6a534cd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/__tests__/lib/mailtrap-client.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TemplatesBaseAPI from "../../lib/api/Templates";
1515

1616
const { ERRORS, CLIENT_SETTINGS } = CONFIG;
1717
const { TESTING_ENDPOINT, BULK_ENDPOINT, SENDING_ENDPOINT } = CLIENT_SETTINGS;
18-
const { TEST_INBOX_ID_MISSING, ACCOUNT_ID_MISSING, BULK_SANDBOX_INCOMPATIBLE } =
18+
const { ACCOUNT_ID_MISSING, BULK_SANDBOX_INCOMPATIBLE, TEST_INBOX_ID_MISSING } =
1919
ERRORS;
2020

2121
describe("lib/mailtrap-client: ", () => {
@@ -331,6 +331,23 @@ describe("lib/mailtrap-client: ", () => {
331331
}
332332
});
333333

334+
it("throws MailtrapError(TEST_INBOX_ID_MISSING) when sending in sandbox mode without testInboxId", async () => {
335+
const client = new MailtrapClient({
336+
token: "MY_API_TOKEN",
337+
sandbox: true,
338+
accountId: 123,
339+
});
340+
341+
await expect(
342+
client.send({
343+
from: { email: "[email protected]", name: "Sender" },
344+
to: [{ email: "[email protected]" }],
345+
subject: "Test",
346+
text: "Body",
347+
})
348+
).rejects.toEqual(new MailtrapError(TEST_INBOX_ID_MISSING));
349+
});
350+
334351
describe("batch sending:", () => {
335352
it("rejects with Mailtrap error when bulk and sandbox modes are used together", async () => {
336353
const batchClient = new MailtrapClient({
@@ -664,20 +681,6 @@ describe("lib/mailtrap-client: ", () => {
664681
});
665682

666683
describe("get testing(): ", () => {
667-
it("rejects with Mailtrap error, when `testInboxId` is missing.", () => {
668-
const client = new MailtrapClient({
669-
token: "MY_API_TOKEN",
670-
});
671-
672-
expect.assertions(1);
673-
674-
try {
675-
client.testing;
676-
} catch (error) {
677-
expect(error).toEqual(new MailtrapError(TEST_INBOX_ID_MISSING));
678-
}
679-
});
680-
681684
it("rejects with Mailtrap error, when `accountId` is missing.", () => {
682685
const client = new MailtrapClient({
683686
token: "MY_API_TOKEN",

0 commit comments

Comments
 (0)