feat(notificaciones): global send flags + editable schedules
The "Flags del envío" panel lived inside the Servicios tab and only
governed the four bulk jobs. The pólizas half had no debug at all, so
there was no way to test a renewal notice without mailing a real
customer. The panel now lives in the /notificaciones shell above the
tabs and both halves read it.
`debug` on the renewal path diverts to the same override inbox as the
servicios jobs and deliberately does NOT write the `RenewalNotice` row
or advance the sweep's `lastSuccessfulAt` — the customer was not
notified, so nothing may gate the letter they are still owed.
`ignoreDayRestriction` and `useEmailLimit` stay estado-de-cuenta-only
and are labelled as such.
Both automatic sweeps are now operator-editable. The renewal cadence
was a `@Cron("0 6 * * *")` literal and servicios had no automatic run
at all; both now resolve through `NotificationScheduleService`, which
stores the cadence in `app_settings` and reinstalls the cron job on
save — no redeploy, no restart. Defaults preserve current behaviour:
pólizas 06:00 daily, servicios off. A scheduled run never inherits the
UI flags; it always sends for real.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,11 +72,15 @@ function build(overrides: {
|
||||
},
|
||||
};
|
||||
|
||||
// `register` is a no-op here: these tests drive the sweep directly, so no
|
||||
// cron job is ever installed.
|
||||
const schedule = { register: jest.fn().mockResolvedValue(undefined) };
|
||||
const service = new RenewalsService(
|
||||
prisma as never,
|
||||
{ available: true, send } as never,
|
||||
{ log: jest.fn() } as never,
|
||||
{ record } as never,
|
||||
schedule as never,
|
||||
);
|
||||
|
||||
return { service, record, send, prisma };
|
||||
@@ -142,6 +146,43 @@ describe("renewal notices write the shared notification log", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("diverts a debug sweep and leaves the notice pending", async () => {
|
||||
const { service, record, send, prisma } = build({});
|
||||
|
||||
const result = await service.sweep("user-1", { debug: true });
|
||||
|
||||
expect(result.sent).toBe(1);
|
||||
expect(result.debug).toBe(true);
|
||||
// The customer's own address is never contacted.
|
||||
expect(jest.mocked(send).mock.calls[0][0]).toMatchObject({
|
||||
to: "rmancinas@freakma.net",
|
||||
xTracking: "debug",
|
||||
});
|
||||
expect(record.mock.calls[0][0]).toMatchObject({
|
||||
status: "SENT",
|
||||
customerEmail: "rmancinas@freakma.net",
|
||||
debug: true,
|
||||
});
|
||||
// The letter is still owed, so nothing may gate it: no RenewalNotice row,
|
||||
// and `lastSuccessfulAt` must not advance past the days we only tested.
|
||||
expect(prisma.renewalNotice.upsert).not.toHaveBeenCalled();
|
||||
const release = prisma.scheduledJobState.update.mock.calls.at(-1)?.[0];
|
||||
expect(release.data.lastSuccessfulAt).toBeUndefined();
|
||||
});
|
||||
|
||||
it("sends one notice on demand in debug without marking it sent", async () => {
|
||||
const { service, send, prisma } = build({});
|
||||
|
||||
const result = await service.sendOne(POLICY_ID, 1, "user-1", {
|
||||
debug: true,
|
||||
});
|
||||
|
||||
expect(result.debug).toBe(true);
|
||||
expect(result.to).toBe("rmancinas@freakma.net");
|
||||
expect(send).toHaveBeenCalledTimes(1);
|
||||
expect(prisma.renewalNotice.upsert).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not fail a delivered notice when the log write throws", async () => {
|
||||
const { service, record } = build({});
|
||||
record.mockRejectedValue(new Error("log table gone"));
|
||||
|
||||
Reference in New Issue
Block a user