UNPKG

@davidbolaji/termii-node

Version:

Node.js SDK for Termii API – send SMS, voice, OTP, and manage messaging with ease.

53 lines (52 loc) 2.1 kB
import { ContactService } from "../messaging/campaign/ContactService"; import FormData from "form-data"; describe("ContactService", () => { let httpClient; let service; beforeEach(() => { httpClient = { request: jest.fn() }; service = new ContactService(httpClient); }); it("fetches contacts", async () => { httpClient.request.mockResolvedValueOnce({ data: [] }); const result = await service.fetchContacts("123"); expect(httpClient.request).toHaveBeenCalledWith("/phonebooks/123/contacts", expect.any(Object)); expect(result.data).toEqual([]); }); it("adds a contact", async () => { httpClient.request.mockResolvedValueOnce({ data: { phone_number: "12345" }, }); const result = await service.addContact("123", { phone_number: "12345" }); expect(httpClient.request).toHaveBeenCalledWith("/phonebooks/123/contacts", expect.objectContaining({ method: "POST", data: { phone_number: "12345" }, })); expect(result.data.phone_number).toBe("12345"); }); it("uploads contacts", async () => { httpClient.request.mockResolvedValueOnce({ message: "Upload started", }); const result = await service.uploadContacts({ file: Buffer.from("fake"), country_code: "234", pid: "123", }); expect(httpClient.request).toHaveBeenCalledWith("/contacts/upload", expect.objectContaining({ method: "POST", data: expect.any(FormData), })); expect(result.message).toBe("Upload started"); }); it("deletes a contact", async () => { httpClient.request.mockResolvedValueOnce({ message: "Contact deleted successfully", }); const result = await service.deleteContact("999"); expect(httpClient.request).toHaveBeenCalledWith("/contacts/999", expect.objectContaining({ method: "DELETE", })); expect(result.message).toBe("Contact deleted successfully"); }); });