mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(notifications): take today from the instance's TZ and catch up missed trip reminders
The reminder crons run at 09:00 in the instance's TZ but computed today in UTC, so east of Greenwich a trip reminder arrived a day late. A day the job did not run also lost that day's trip reminders for good: the match was 'starts exactly N days from today'. Trips now record the start date a reminder went out for, and the job sends every reminder that is due and not yet sent. The active-trip redirect and the upcoming reservations use the instance's date and clock as well.
This commit is contained in:
@@ -32,6 +32,7 @@ const UNNUMBERED = [
|
||||
BASELINE,
|
||||
'Migration20200101040200_trek_photo_cache_meta_cache_key_not_null',
|
||||
'Migration20200101042000_tours',
|
||||
'Migration20200101042100_a_trip_reminder_remembers_it_was_sent',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { appClock } from '../../../src/nest/common/timezoneService';
|
||||
|
||||
describe('appClock', () => {
|
||||
const realTz = process.env.TZ;
|
||||
afterEach(() => {
|
||||
process.env.TZ = realTz;
|
||||
});
|
||||
|
||||
it('APPCLOCK-001: reads the date and time where the instance runs, not in UTC', () => {
|
||||
process.env.TZ = 'Australia/Sydney';
|
||||
// 23:30 UTC on the 6th is 10:30 on the 7th in Sydney.
|
||||
expect(appClock(new Date('2026-10-06T23:30:00Z'))).toEqual({ date: '2026-10-07', time: '10:30' });
|
||||
});
|
||||
|
||||
it('APPCLOCK-002: falls back to UTC without a TZ, and for one Intl does not know', () => {
|
||||
delete process.env.TZ;
|
||||
expect(appClock(new Date('2026-10-06T23:30:00Z'))).toEqual({ date: '2026-10-06', time: '23:30' });
|
||||
process.env.TZ = 'Not/AZone';
|
||||
expect(appClock(new Date('2026-10-06T23:30:00Z'))).toEqual({ date: '2026-10-06', time: '23:30' });
|
||||
});
|
||||
});
|
||||
@@ -165,6 +165,28 @@ describe('trip reminder tick', () => {
|
||||
expect(logMock.logInfo).toHaveBeenCalledWith(expect.stringMatching(/^Trip reminders sent for 2 trip\(s\): /));
|
||||
});
|
||||
|
||||
it('RJOB-012 — catches up a reminder the job missed, sends each one once, and again for a moved trip', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
// Due yesterday (start in 2 days, reminder 3 days ahead): the job did not run then.
|
||||
const missed = createTrip(testDb, user.id, { title: 'Missed' });
|
||||
testDb.prepare("UPDATE trips SET reminder_days = 3, start_date = date('now', '+2 days') WHERE id = ?").run(missed.id);
|
||||
// Already started: no reminder any more.
|
||||
const started = createTrip(testDb, user.id, { title: 'Started' });
|
||||
testDb.prepare("UPDATE trips SET reminder_days = 3, start_date = date('now', '-1 days') WHERE id = ?").run(started.id);
|
||||
|
||||
const { svc, send } = makeJobs();
|
||||
await svc.tripTick();
|
||||
expect(send.mock.calls.map(([p]) => p.targetId)).toEqual([missed.id]);
|
||||
|
||||
send.mockClear();
|
||||
await svc.tripTick();
|
||||
expect(send).not.toHaveBeenCalled();
|
||||
|
||||
testDb.prepare("UPDATE trips SET start_date = date('now', '+1 days') WHERE id = ?").run(missed.id);
|
||||
await svc.tripTick();
|
||||
expect(send.mock.calls.map(([p]) => p.targetId)).toEqual([missed.id]);
|
||||
});
|
||||
|
||||
it('RJOB-006 — the per-tick gate skips everything when notify_trip_reminder is false', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
tripWithReminder(user.id, 3);
|
||||
|
||||
Reference in New Issue
Block a user