feat: integrate reminder payloads into appointment creation and update notification jobs and adjust quiet hours logic
This commit is contained in:
@@ -105,6 +105,7 @@ jest.mock("../../Notifications/Notifications", () => ({
|
||||
NotificationsManager: {
|
||||
sendSystemNotification: jest.fn(),
|
||||
sendPushNotification: jest.fn(),
|
||||
sendEmail: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -119,6 +120,7 @@ jest.mock("../../PlanSubscriptions/PlanSubscriptons", () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
findOne: jest.fn(),
|
||||
checkFeature: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -187,6 +189,9 @@ import ClientsManager from "../../Clients/Clients";
|
||||
import ServiceList from "../../Services/Service";
|
||||
import CompaniesManager from "../../Companies/Companies";
|
||||
import Templates from "../../Templates/Templates";
|
||||
import PlanSubscriptionsList from "../../PlanSubscriptions/PlanSubscriptons";
|
||||
import { NotificationsManager } from "../../Notifications/Notifications";
|
||||
import { APPOINTMENT_NOTIFICATION_TYPE } from "../Appointments.Interface";
|
||||
|
||||
describe("getAppointmentEvent — historical read snapshot fallback", () => {
|
||||
let originalAdapter: any;
|
||||
@@ -503,6 +508,10 @@ describe("cancellation notification jobs", () => {
|
||||
expect.objectContaining({
|
||||
type: "cancellation",
|
||||
payload: expect.objectContaining({
|
||||
email: "ada@example.com",
|
||||
phoneNumber: "5491112345678",
|
||||
userId: "client-user-001",
|
||||
companyOwnerId: "owner-001",
|
||||
emailSubject: "TurnosXpress :: Turno cancelado",
|
||||
emailMessage: "EMAIL CANCEL Ada Lovelace Contabilidad clases llavallol 22/07/2026 08:00hs.",
|
||||
wapMessage: "WAP CANCEL Ada Lovelace Contabilidad clases llavallol 22/07/2026 08:00hs.",
|
||||
@@ -512,6 +521,23 @@ describe("cancellation notification jobs", () => {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("sends update email notifications with a non-empty subject", async () => {
|
||||
(PlanSubscriptionsList.checkFeature as jest.Mock).mockResolvedValue(true);
|
||||
|
||||
await (AppointmentsList as any).sendEmailNotification({
|
||||
appointmentId: "appt-001",
|
||||
sessionUser: "owner-001",
|
||||
type: APPOINTMENT_NOTIFICATION_TYPE.UPDATE,
|
||||
});
|
||||
|
||||
expect(NotificationsManager.sendEmail).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
email: "ada@example.com",
|
||||
subject: "TurnosXpress :: Turno actualizado",
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("creation notification jobs", () => {
|
||||
@@ -619,6 +645,8 @@ describe("creation notification jobs", () => {
|
||||
appointmentStart: new Date("2026-07-22T11:00:00.000Z"),
|
||||
emailMessage: emailContent.message,
|
||||
wapMessage: wapContent.message,
|
||||
reminderEmailMessage: "EMAIL REMINDER Ada Lovelace",
|
||||
reminderWapMessage: "WAP REMINDER Ada Lovelace",
|
||||
});
|
||||
|
||||
expect((AppointmentsList as any).jobService.createJob).toHaveBeenCalledWith(
|
||||
@@ -631,6 +659,15 @@ describe("creation notification jobs", () => {
|
||||
systemSubject: "Turno reservado en clases llavallol",
|
||||
systemMessage: "EMAIL ALTA Ada Lovelace Historia clases llavallol 22/07/2026 08:00hs.",
|
||||
}),
|
||||
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",
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -653,4 +690,62 @@ describe("creation notification jobs", () => {
|
||||
|
||||
expect(emailContent.message).toBe("WAP ALTA Ada Lovelace Historia clases llavallol 22/07/2026 08:00hs.");
|
||||
});
|
||||
|
||||
it("stores organization-rendered update template content with contact snapshot fields", async () => {
|
||||
const emailContent = await (AppointmentsList as any).tryToSendNotification({
|
||||
appointmentId: "appt-001",
|
||||
sessionUser: "owner-001",
|
||||
type: "update",
|
||||
channel: "email",
|
||||
});
|
||||
const wapContent = await (AppointmentsList as any).tryToSendNotification({
|
||||
appointmentId: "appt-001",
|
||||
sessionUser: "owner-001",
|
||||
type: "update",
|
||||
channel: "whatsapp",
|
||||
});
|
||||
|
||||
await (AppointmentsList as any).createUpdateNotificationJobs({
|
||||
appointmentId: "appt-001",
|
||||
companyId: "company-001",
|
||||
clientId: "client-001",
|
||||
clientUserId: "client-user-001",
|
||||
clientEmail: "ada@example.com",
|
||||
clientPhoneNumber: "5491112345678",
|
||||
companyOwnerId: "owner-001",
|
||||
companyName: "clases llavallol",
|
||||
appointmentStart: new Date("2026-07-22T11:00:00.000Z"),
|
||||
emailMessage: emailContent.message,
|
||||
wapMessage: wapContent.message,
|
||||
reminderEmailMessage: "EMAIL REMINDER Ada Lovelace",
|
||||
reminderWapMessage: "WAP REMINDER Ada Lovelace",
|
||||
});
|
||||
|
||||
expect((AppointmentsList as any).jobService.createJob).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "update",
|
||||
appointmentStart: new Date("2026-07-22T11:00:00.000Z"),
|
||||
payload: expect.objectContaining({
|
||||
email: "ada@example.com",
|
||||
phoneNumber: "5491112345678",
|
||||
userId: "client-user-001",
|
||||
companyOwnerId: "owner-001",
|
||||
emailSubject: "TurnosXpress :: Turno actualizado",
|
||||
emailMessage: "EMAIL ALTA Ada Lovelace Historia clases llavallol 22/07/2026 08:00hs.",
|
||||
wapMessage: "WAP ALTA Ada Lovelace Historia clases llavallol 22/07/2026 08:00hs.",
|
||||
systemSubject: "Turno actualizado en clases llavallol",
|
||||
systemMessage: "EMAIL ALTA Ada Lovelace Historia clases llavallol 22/07/2026 08:00hs.",
|
||||
}),
|
||||
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",
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user