feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services

This commit is contained in:
2026-07-21 18:53:11 -03:00
parent 40090cdec5
commit 10ca449f88
82 changed files with 10249 additions and 171 deletions
@@ -0,0 +1,71 @@
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 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" },
}
);
});
});