Files
HealthLog/src/lib/jobs/__tests__/cycle-reminder-queue.test.ts
T
Marc-André Bombeck 9bd46ff25d refactor(jobs): decompose reminder-worker into domain queue registrars
Split the 2143-LOC startReminderWorker boot file into five domain
registrars under src/lib/jobs/reminder/ (integration-sync, status,
rollup, reminders, maintenance), each owning its queue-name constants,
its allQueues membership, its schedule tuples, and its boss.work
bindings. A shared createAndSchedule helper provisions every queue
before scheduling it. The boot file is now a 115-LOC registration table
that composes the registrars and runs the boot one-shots + discovery
enqueues.

Every queue declaration, schedule, boss.work binding, and boot-discovery
enqueue is preserved verbatim — verified by diffing the old monolith
against the union of the registrars (66/66 queues, 66/66 bindings,
identical schedule tuples and boot enqueues). The diff caught one
withings-oauth-state-cleanup binding that was dropped mid-refactor and
restored it.

Update the 18 queue-registration guard tests to follow the wiring into
its registrar module so the dead-queue protection moves with the code
rather than weakening: each grep guard now reads its queue's registrar,
the stress-strain-retention guard unions the allQueues blocks across the
status + rollup registrars, and the intake-slot-dedup schedules regex
tracks the new module-level indentation.
2026-06-16 23:28:48 +02:00

69 lines
2.3 KiB
TypeScript

/**
* v1.15 — cycle-reminder queue registration guard.
*
* Same source-text-grep approach as the mood-reminder / drain / mean-
* consolidation registration guards: assert the cycle-reminder queue is
* declared, listed in `allQueues` (the v1.4.37 dead-queue lesson — an
* unregistered queue is never provisioned and the schedule silently
* no-ops), scheduled on its cron, and wired to a `boss.work` handler that
* delegates to `runCycleReminderTick`. No pg-boss / Prisma boot.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
// v1.18.1 — the reminder-dispatch wiring moved out of the 2143-LOC
// reminder-worker boot file into the reminders registrar. The dead-queue guard
// follows the wiring there (the handler module is still concatenated for the
// handler-symbol assertions).
const REGISTRAR_PATH = join(
__dirname,
"..",
"reminder",
"register-reminders.ts",
);
const source =
readFileSync(REGISTRAR_PATH, "utf8") +
readFileSync(
join(__dirname, "..", "reminder", "mood-cycle-checks.ts"),
"utf8",
);
describe("reminder-worker — cycle-reminder wiring", () => {
it("imports the cycle-reminder tick runner", () => {
expect(source).toMatch(/from\s*["']@\/lib\/jobs\/cycle-reminder["']/);
expect(source).toMatch(/\brunCycleReminderTick\b/);
});
it("declares the queue + cron constants", () => {
expect(source).toMatch(
/CYCLE_REMINDER_QUEUE\s*=\s*["']cycle-reminder-check["']/,
);
expect(source).toMatch(
/CYCLE_REMINDER_CRON\s*=\s*["']\*\/15 \* \* \* \*["']/,
);
});
it("registers the cycle-reminder queue in the allQueues loop", () => {
const allQueuesMatch = source.match(
/const allQueues\s*=\s*\[([\s\S]*?)\];/,
);
expect(allQueuesMatch).not.toBeNull();
expect(allQueuesMatch![1]).toMatch(/\bCYCLE_REMINDER_QUEUE\b/);
});
it("schedules the cycle-reminder cron", () => {
expect(source).toMatch(/\[CYCLE_REMINDER_QUEUE,\s*CYCLE_REMINDER_CRON\]/);
});
it("registers a boss.work handler that runs the cycle-reminder tick", () => {
expect(source).toMatch(
/boss\.work[\s\S]{0,200}CYCLE_REMINDER_QUEUE[\s\S]{0,200}handleCycleReminderCheck/,
);
expect(source).toMatch(
/handleCycleReminderCheck[\s\S]{0,400}runCycleReminderTick/,
);
});
});