@davidbolaji/termii-node
Version:
Node.js SDK for Termii API – send SMS, voice, OTP, and manage messaging with ease.
41 lines (40 loc) • 1.52 kB
JavaScript
import { HistoryService } from "../insights/HistoryService";
describe("HistoryService", () => {
let httpClient;
let service;
beforeEach(() => {
httpClient = { request: jest.fn() };
service = new HistoryService(httpClient);
});
it("fetches message history without filter", async () => {
const mockResponse = [
{
sender: "sender",
receiver: "receiver",
message: "hi",
amount: 1,
reroute: 0,
status: "DELIVERED",
sms_type: "plain",
send_by: "sender",
media_url: null,
message_id: "mid",
notify_url: null,
notify_id: null,
created_at: "now",
},
];
httpClient.request.mockResolvedValue(mockResponse);
const result = await service.getHistory();
expect(httpClient.request).toHaveBeenCalledWith("/sms/inbox", { method: "GET", params: undefined });
expect(result).toEqual(mockResponse);
});
it("fetches message history with filter", async () => {
const payload = { message_id: "mid" };
const mockResponse = [];
httpClient.request.mockResolvedValue(mockResponse);
const result = await service.getHistory(payload);
expect(httpClient.request).toHaveBeenCalledWith("/sms/inbox", { method: "GET", params: payload });
expect(result).toEqual(mockResponse);
});
});