feat(renovaciones): renewal notification emails over SES
INSURANCE_FEATURES_SPEC §1. The office printed and mailed renewal letters from the legacy CONTROL <ramo> RENEW[2/3] paper log; 91% of policyholders have an email on file, so send the notice instead and keep the paper log as the fallback. A daily cron (06:00 America/Tijuana) sweeps three generations off policyTo — 30 and 15 days before expiry, 7 days after — sends each through SES, and upserts RenewalNotice by [policyId, generation] so a policy is never notified twice for the same milestone. RenewalNotice now records providerMessageId, so a later bounce or complaint webhook can be traced back to the row that sent it. - customers.emailOptOut excludes a customer from every sweep; editable from the customer form - scheduled_job_states holds the sweep's lock and last successful run; the window is widened to cover days the job did not run, so a weekend outage does not silently drop a generation - SES unconfigured is not an error outside production — messages are logged and skipped, so dev and CI never send - /renovaciones (renewal:send, MANAGER+) lists what is pending per generation, runs the sweep by hand, and marks a notice sent by mail for the customers with no email - POST /policies/:id/renewal-notices records that manual mark - the aviso-renovacion report and the emails now share one projection (reports/renewal-letter.ts) instead of two copies of the mapping
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
addUtcDays,
|
||||
dateInTimeZone,
|
||||
renewalWindow,
|
||||
RENEWAL_CADENCE,
|
||||
} from "./renewals.service";
|
||||
|
||||
describe("renewal scheduling dates", () => {
|
||||
it("uses the America/Tijuana calendar date", () => {
|
||||
expect(dateInTimeZone(new Date("2026-08-01T05:00:00.000Z"))).toEqual(
|
||||
new Date("2026-07-31T00:00:00.000Z"),
|
||||
);
|
||||
});
|
||||
|
||||
it("maps generations to 30 days, 15 days, and 7 days overdue", () => {
|
||||
const today = new Date("2026-08-01T00:00:00.000Z");
|
||||
|
||||
expect(
|
||||
RENEWAL_CADENCE.map(({ generation, offsetDays }) => ({
|
||||
generation,
|
||||
target: addUtcDays(today, offsetDays).toISOString().slice(0, 10),
|
||||
})),
|
||||
).toEqual([
|
||||
{ generation: 1, target: "2026-08-31" },
|
||||
{ generation: 2, target: "2026-08-16" },
|
||||
{ generation: 3, target: "2026-07-25" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses an inclusive catch-up window after a missed run", () => {
|
||||
const window = renewalWindow(
|
||||
new Date("2026-08-10T00:00:00.000Z"),
|
||||
30,
|
||||
new Date("2026-08-07T18:00:00.000Z"),
|
||||
);
|
||||
|
||||
expect(window).toEqual({
|
||||
from: new Date("2026-09-07T00:00:00.000Z"),
|
||||
to: new Date("2026-09-09T00:00:00.000Z"),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user