Skip to content

Commit 5dd25ab

Browse files
test: add unit tests for MailtrapClient templates getter to validate error handling and initialization
1 parent 66ae5c3 commit 5dd25ab

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import GeneralAPI from "../../lib/api/General";
1111
import TestingAPI from "../../lib/api/Testing";
1212
import ContactLists from "../../lib/api/ContactLists";
1313
import Contacts from "../../lib/api/Contacts";
14+
import TemplatesBaseAPI from "../../lib/api/Templates";
1415

1516
const { ERRORS, CLIENT_SETTINGS } = CONFIG;
1617
const { TESTING_ENDPOINT, BULK_ENDPOINT, SENDING_ENDPOINT } = CLIENT_SETTINGS;
@@ -782,5 +783,31 @@ describe("lib/mailtrap-client: ", () => {
782783
expect(contactListsClient).toBeInstanceOf(ContactLists);
783784
});
784785
});
786+
787+
describe("get templates(): ", () => {
788+
it("rejects with Mailtrap error, when `accountId` is missing.", () => {
789+
const client = new MailtrapClient({
790+
token: "MY_API_TOKEN",
791+
});
792+
expect.assertions(1);
793+
794+
try {
795+
client.templates;
796+
} catch (error) {
797+
expect(error).toEqual(new MailtrapError(ACCOUNT_ID_MISSING));
798+
}
799+
});
800+
801+
it("returns templates API object when accountId is provided.", () => {
802+
const client = new MailtrapClient({
803+
token: "MY_API_TOKEN",
804+
accountId: 10,
805+
});
806+
expect.assertions(1);
807+
808+
const templatesClient = client.templates;
809+
expect(templatesClient).toBeInstanceOf(TemplatesBaseAPI);
810+
});
811+
});
785812
});
786813
});

0 commit comments

Comments
 (0)