feat: implement automated job cleanup, update notification presets, and upgrade Baileys library

This commit is contained in:
2026-07-21 21:12:29 -03:00
parent aac53e13cc
commit 98f0ec3102
8 changed files with 388 additions and 35 deletions
@@ -1,5 +1,5 @@
import { dispatchEmail, dispatchWhatsApp } from "../ChannelDispatchers.js";
import { buildPendingJobQuery, calculateNextRetryAt, JobProcessor } from "../JobProcessor.js";
import { buildPendingJobQuery, buildStartOfDay, calculateNextRetryAt, JobProcessor } from "../JobProcessor.js";
import { resolveNotificationContent } from "../NotificationContentResolver.js";
jest.mock("../ChannelDispatchers.js", () => ({
@@ -94,6 +94,28 @@ describe("JobProcessor", () => {
});
});
describe("buildStartOfDay", () => {
it("returns the start of the local day", () => {
const result = buildStartOfDay(new Date(2026, 6, 21, 15, 30, 45, 123));
expect(result).toEqual(new Date(2026, 6, 21, 0, 0, 0, 0));
});
});
describe("old job cleanup", () => {
it("deletes jobs scheduled before the start of the current day", async () => {
const deleteBeforeScheduledAt = jest.fn().mockResolvedValue(3);
const now = new Date(2026, 6, 21, 15, 30, 0, 0);
await (JobProcessor.prototype as any).cleanupOldJobs.call(
{ jobModel: { deleteBeforeScheduledAt } },
now
);
expect(deleteBeforeScheduledAt).toHaveBeenCalledWith(new Date(2026, 6, 21, 0, 0, 0, 0));
});
});
describe("WhatsApp dispatch", () => {
beforeEach(() => {
jest.clearAllMocks();