Platform backbone (plan 2026-10-13-plattform-rueckgrat), all tasks reviewed: - webhooks with delivery table, retries and stable delivery id - calendar handlers; a finished task removes its Outlook event - tasks, automations, inspections, varroa, treatments, feedings, harvests, colonies, wintering, stock and bottling record domain events in the same transaction; legacy post-commit calls removed - row locks through one helper (lockRowForUpdate, lockRowsForShare, lockRowsForUpdate) - job framework with JobRun, cli exit codes, cleanup, task templates, daily evaluation, hourly app-backup and the rekey job - system API and page "Verwaltung > System" with retry - @nestjs/schedule removed, guard tests against in-process schedulers Field capture T3 (plan 2026-10-13-t3-erfassung-am-stand), all tasks reviewed: - inspection photo offline without metadata - bulk capture for treatments, feedings and varroa (backend + frontend) - offline stand mode with service worker, offline pages and packs - offline session, cold start and logout on shared devices Docs: ARCHITECTURE.md assumptions and sections updated, TASKS.md. Gates: backend lint, typecheck, 1770 unit, 420 e2e, build, no schema drift; frontend lint, typecheck, 913 tests, build. Not rolled out. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
import { runInNewContext } from 'node:vm';
|
|
import { BACKUP_SCHEDULE_TIME_ZONE, isBackupDue } from './backup-due';
|
|
|
|
describe('isBackupDue', () => {
|
|
it('reads the schedule in Europe/Berlin by default', () => {
|
|
expect(BACKUP_SCHEDULE_TIME_ZONE).toBe('Europe/Berlin');
|
|
});
|
|
|
|
it('is due when there is no backup yet', () => {
|
|
expect(
|
|
isBackupDue('0 3 * * *', null, new Date('2026-10-13T00:30:00Z')),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('is not due again on the same day for "0 3 * * *"', () =>
|
|
expect(
|
|
isBackupDue(
|
|
'0 3 * * *',
|
|
new Date('2026-10-12T01:00:00Z'),
|
|
new Date('2026-10-13T00:30:00Z'),
|
|
),
|
|
).toBe(false));
|
|
|
|
it('is due after the next 03:00 Europe/Berlin', () =>
|
|
expect(
|
|
isBackupDue(
|
|
'0 3 * * *',
|
|
new Date('2026-10-12T01:00:00Z'),
|
|
new Date('2026-10-13T01:05:00Z'),
|
|
),
|
|
).toBe(true));
|
|
|
|
it('is due exactly at the next scheduled time', () =>
|
|
expect(
|
|
isBackupDue(
|
|
'0 3 * * *',
|
|
new Date('2026-10-12T01:00:00Z'),
|
|
new Date('2026-10-13T01:00:00Z'),
|
|
),
|
|
).toBe(true));
|
|
|
|
it('counts a backup written after the scheduled time (e.g. "Jetzt sichern") as covering it', () =>
|
|
expect(
|
|
isBackupDue(
|
|
'0 3 * * *',
|
|
new Date('2026-10-13T01:10:00Z'),
|
|
new Date('2026-10-13T02:00:00Z'),
|
|
),
|
|
).toBe(false));
|
|
|
|
it('stays due after a missed run until a backup exists', () =>
|
|
expect(
|
|
isBackupDue(
|
|
'0 3 * * *',
|
|
new Date('2026-10-10T01:00:00Z'),
|
|
new Date('2026-10-13T05:00:00Z'),
|
|
),
|
|
).toBe(true));
|
|
|
|
it('uses the given time zone', () => {
|
|
const lastBackupAt = new Date('2026-10-12T03:00:00Z');
|
|
const now = new Date('2026-10-13T02:00:00Z');
|
|
|
|
// Next 03:00 UTC is 03:00Z, next 03:00 Berlin was 01:00Z.
|
|
expect(isBackupDue('0 3 * * *', lastBackupAt, now, 'UTC')).toBe(false);
|
|
expect(isBackupDue('0 3 * * *', lastBackupAt, now)).toBe(true);
|
|
});
|
|
|
|
// fs.Stats.mtime is created by Node's core; under Jest it is not an
|
|
// instance of the test's Date (cron checks `instanceof Date`).
|
|
it('accepts a Date from another realm', () => {
|
|
const foreign = runInNewContext('new Date("2026-10-12T01:00:00Z")') as Date;
|
|
|
|
expect(
|
|
isBackupDue('0 3 * * *', foreign, new Date('2026-10-13T00:30:00Z')),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('rejects an invalid schedule even without a backup', () => {
|
|
expect(() => isBackupDue('every night', null, new Date())).toThrow();
|
|
});
|
|
});
|