refactor: modularize notification job creation to support reminder-only flow for recurring appointments
This commit is contained in:
@@ -681,6 +681,73 @@ describe("creation notification jobs", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("routes customer notification jobs for creation, repeat reminder-only, and disabled notifications", () => {
|
||||
expect((AppointmentsList as any).shouldCreateCustomerNotificationJobs(true, undefined)).toBe(true);
|
||||
expect((AppointmentsList as any).shouldCreateCustomerNotificationJobs(false, "repeat-001")).toBe(true);
|
||||
expect((AppointmentsList as any).shouldCreateCustomerNotificationJobs(false, undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("creates reminder-only jobs without rendering Alta content for repeat-created appointments", async () => {
|
||||
const tryToSendNotificationSpy = jest
|
||||
.spyOn(AppointmentsList as any, "tryToSendNotification")
|
||||
.mockImplementation(({ type, channel }: any) => {
|
||||
if (type === APPOINTMENT_NOTIFICATION_TYPE.CREATION) {
|
||||
throw new Error("Creation content should not be rendered");
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
message: channel === "email" ? "EMAIL REMINDER Ada Lovelace" : "WAP REMINDER Ada Lovelace",
|
||||
});
|
||||
});
|
||||
const getOptionalClientWapNumberSpy = jest
|
||||
.spyOn(AppointmentsList as any, "getOptionalClientWapNumber")
|
||||
.mockResolvedValue("5491112345678");
|
||||
|
||||
try {
|
||||
await (AppointmentsList as any).createAppointmentNotificationJobs({
|
||||
appointmentId: "appt-001",
|
||||
companyId: "company-001",
|
||||
clientId: "client-001",
|
||||
clientUserId: "client-user-001",
|
||||
clientEmail: "ada@example.com",
|
||||
client: { _id: "client-001" },
|
||||
companyOwnerId: "owner-001",
|
||||
companyName: "clases llavallol",
|
||||
appointmentStart: new Date("2026-07-22T11:00:00.000Z"),
|
||||
notification: false,
|
||||
});
|
||||
|
||||
expect(tryToSendNotificationSpy).toHaveBeenCalledTimes(2);
|
||||
expect(tryToSendNotificationSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: APPOINTMENT_NOTIFICATION_TYPE.REMINDER, channel: "email" })
|
||||
);
|
||||
expect(tryToSendNotificationSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: APPOINTMENT_NOTIFICATION_TYPE.REMINDER, channel: "whatsapp" })
|
||||
);
|
||||
expect((AppointmentsList as any).jobService.createMandatoryCreationJob).not.toHaveBeenCalled();
|
||||
expect((AppointmentsList as any).jobService.createReminderJobs).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "reminder",
|
||||
appointmentStart: new Date("2026-07-22T11:00:00.000Z"),
|
||||
reminderPayload: expect.objectContaining({
|
||||
email: "ada@example.com",
|
||||
phoneNumber: "5491112345678",
|
||||
userId: "client-user-001",
|
||||
companyOwnerId: "owner-001",
|
||||
emailSubject: "TurnosXpress :: Recordatorio",
|
||||
emailMessage: "EMAIL REMINDER Ada Lovelace",
|
||||
wapMessage: "WAP REMINDER Ada Lovelace",
|
||||
systemSubject: "Recordatorio de turno en clases llavallol",
|
||||
systemMessage: "EMAIL REMINDER Ada Lovelace",
|
||||
}),
|
||||
})
|
||||
);
|
||||
} finally {
|
||||
tryToSendNotificationSpy.mockRestore();
|
||||
getOptionalClientWapNumberSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back to organization WAP Alta template for email when email Alta is absent", async () => {
|
||||
(CompaniesManager.companies.findOne as jest.Mock).mockResolvedValue({
|
||||
_id: "company-001",
|
||||
|
||||
Reference in New Issue
Block a user