Skip to content

Commit c297b7a

Browse files
test: add unit tests for contacts and contactLists getters in MailtrapClient to validate accountId handling
1 parent d98a28f commit c297b7a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import MailtrapError from "../../lib/MailtrapError";
99
import CONFIG from "../../config";
1010
import GeneralAPI from "../../lib/api/General";
1111
import TestingAPI from "../../lib/api/Testing";
12+
import ContactLists from "../../lib/api/ContactLists";
13+
import Contacts from "../../lib/api/Contacts";
1214

1315
const { ERRORS, CLIENT_SETTINGS } = CONFIG;
1416
const { TESTING_ENDPOINT, BULK_ENDPOINT, SENDING_ENDPOINT } = CLIENT_SETTINGS;
@@ -728,5 +730,57 @@ describe("lib/mailtrap-client: ", () => {
728730
expect(generalClient).toBeInstanceOf(GeneralAPI);
729731
});
730732
});
733+
734+
describe("get contacts(): ", () => {
735+
it("rejects with Mailtrap error, when `accountId` is missing.", () => {
736+
const client = new MailtrapClient({
737+
token: "MY_API_TOKEN",
738+
});
739+
expect.assertions(1);
740+
741+
try {
742+
client.contacts;
743+
} catch (error) {
744+
expect(error).toEqual(new MailtrapError(ACCOUNT_ID_MISSING));
745+
}
746+
});
747+
748+
it("returns contacts API object when accountId is provided.", () => {
749+
const client = new MailtrapClient({
750+
token: "MY_API_TOKEN",
751+
accountId: 10,
752+
});
753+
expect.assertions(1);
754+
755+
const contactsClient = client.contacts;
756+
expect(contactsClient).toBeInstanceOf(Contacts);
757+
});
758+
});
759+
760+
describe("get contactLists(): ", () => {
761+
it("rejects with Mailtrap error, when `accountId` is missing.", () => {
762+
const client = new MailtrapClient({
763+
token: "MY_API_TOKEN",
764+
});
765+
expect.assertions(1);
766+
767+
try {
768+
client.contactLists;
769+
} catch (error) {
770+
expect(error).toEqual(new MailtrapError(ACCOUNT_ID_MISSING));
771+
}
772+
});
773+
774+
it("returns contact lists API object when accountId is provided.", () => {
775+
const client = new MailtrapClient({
776+
token: "MY_API_TOKEN",
777+
accountId: 10,
778+
});
779+
expect.assertions(1);
780+
781+
const contactListsClient = client.contactLists;
782+
expect(contactListsClient).toBeInstanceOf(ContactLists);
783+
});
784+
});
731785
});
732786
});

0 commit comments

Comments
 (0)