96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import axios from "axios";
|
|
import { dispatchEmail, dispatchWhatsApp } from "../ChannelDispatchers.js";
|
|
|
|
jest.mock("axios");
|
|
|
|
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
|
|
|
describe("ChannelDispatchers", () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
process.env.API_URL = "https://api.example.com/base";
|
|
process.env.API_KEY = "system-token";
|
|
mockedAxios.post.mockResolvedValue({
|
|
data: { success: true },
|
|
status: 200,
|
|
statusText: "OK",
|
|
headers: {},
|
|
config: { url: "" },
|
|
});
|
|
});
|
|
|
|
it("sends the job type in the email notification payload", async () => {
|
|
await dispatchEmail({
|
|
appointmentId: "appointment-1",
|
|
systemToken: "system-token",
|
|
type: "creation",
|
|
email: "client@example.com",
|
|
subject: "Appointment created",
|
|
message: "Creation message",
|
|
});
|
|
|
|
expect(mockedAxios.post).toHaveBeenCalledWith(
|
|
"https://api.example.com/notifications/send-email",
|
|
{
|
|
systemToken: "system-token",
|
|
email: "client@example.com",
|
|
subject: "Appointment created",
|
|
message: "Creation message",
|
|
},
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
}
|
|
);
|
|
});
|
|
|
|
it("sends email template data when provided", async () => {
|
|
await dispatchEmail({
|
|
appointmentId: "appointment-1",
|
|
systemToken: "system-token",
|
|
type: "reminder",
|
|
email: "client@example.com",
|
|
templateId: "template-1",
|
|
context: { username: "Client Name" },
|
|
});
|
|
|
|
expect(mockedAxios.post).toHaveBeenCalledWith(
|
|
"https://api.example.com/notifications/send-email",
|
|
{
|
|
systemToken: "system-token",
|
|
email: "client@example.com",
|
|
templateId: "template-1",
|
|
context: { username: "Client Name" },
|
|
},
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
}
|
|
);
|
|
});
|
|
|
|
it("sends the job type in the WhatsApp system notification payload", async () => {
|
|
await dispatchWhatsApp({
|
|
companyId: "company-1",
|
|
appointmentId: "appointment-1",
|
|
type: "creation",
|
|
systemToken: "system-token",
|
|
phoneNumber: "5491112345678",
|
|
message: "Creation message",
|
|
companyOwnerId: "owner-1",
|
|
});
|
|
|
|
expect(mockedAxios.post).toHaveBeenCalledWith(
|
|
"https://api.example.com/notifications/send-wap",
|
|
{
|
|
systemToken: "system-token",
|
|
phoneNumber: "5491112345678",
|
|
message: "Creation message",
|
|
companyId: "company-1",
|
|
sessionUser: "owner-1",
|
|
},
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
}
|
|
);
|
|
});
|
|
});
|