@davidbolaji/termii-node
Version:
Node.js SDK for Termii API – send SMS, voice, OTP, and manage messaging with ease.
63 lines (62 loc) • 2.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TokenService_1 = require("../token/TokenService");
describe("TokenService", () => {
let httpClient;
let service;
beforeEach(() => {
httpClient = { request: jest.fn() };
service = new TokenService_1.TokenService(httpClient);
});
it("sends a token successfully", async () => {
const mockResponse = {
pinId: "29ae67c2-c8e1-4165-8a51-8d3d7c298081",
to: "2348109077743",
smsStatus: "Message Sent",
};
httpClient.request.mockResolvedValue(mockResponse);
const payload = {
message_type: "NUMERIC",
to: "2348109077743",
from: "CompanyName",
channel: "dnd",
pin_attempts: 3,
pin_time_to_live: 5,
pin_length: 6,
pin_placeholder: "< 1234 >",
message_text: "Your pin is < 1234 >",
pin_type: "NUMERIC",
};
const result = await service.sendToken(payload);
expect(httpClient.request).toHaveBeenCalledWith("/sms/otp/send", {
method: "POST",
data: payload,
authLocation: 'body',
});
expect(result).toEqual(mockResponse);
});
it("sends a voice token successfully", async () => {
const mockResponse = {
code: "ok",
message_id: "453166532802459832",
pinId: "29ae67c2-c8e1-4165-8a51-8d3d7c298081",
message: "Successfully Sent",
balance: 77.5,
user: "Termii Test",
};
httpClient.request.mockResolvedValue(mockResponse);
const payload = {
phone_number: "23409800000000",
pin_attempts: 5,
pin_time_to_live: 3,
pin_length: 6,
};
const result = await service.sendVoiceToken(payload);
expect(httpClient.request).toHaveBeenCalledWith("/sms/otp/send/voice", {
method: "POST",
data: payload,
authLocation: 'body',
});
expect(result).toEqual(mockResponse);
});
});