aboutsummaryrefslogtreecommitdiff
path: root/src/lib/server/services/routines.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/server/services/routines.test.ts')
-rw-r--r--src/lib/server/services/routines.test.ts33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/lib/server/services/routines.test.ts b/src/lib/server/services/routines.test.ts
index 22b49ff..eda8824 100644
--- a/src/lib/server/services/routines.test.ts
+++ b/src/lib/server/services/routines.test.ts
@@ -12,8 +12,6 @@ import {
loadOverview,
} from './routines';
-const DAY_MS = 24 * 60 * 60 * 1000;
-
describe('routines service', () => {
let db: Awaited<ReturnType<typeof createTestDb>>['db'];
let projectId: number;
@@ -84,7 +82,11 @@ describe('routines service', () => {
expect(versions[0].archived).toBe(false);
expect(versions[1].archived).toBe(true);
- const dashboard = await loadProjectDashboard(projectId, Date.now(), db);
+ const dashboard = await loadProjectDashboard(
+ projectId,
+ Temporal.Now.instant(),
+ db,
+ );
expect(dashboard.routines).toHaveLength(0);
expect(dashboard.healthScore).toBe(100);
});
@@ -116,15 +118,19 @@ describe('routines service', () => {
const archived = await loadArchived(projectId, db);
expect(archived).toHaveLength(2);
// Descending archive date; equal timestamps keep insertion order.
- expect(new Date(archived[0].archivedAt).getTime()).toBeGreaterThanOrEqual(
- new Date(archived[1].archivedAt).getTime(),
+ expect(
+ Temporal.Instant.from(archived[0].archivedAt).epochMilliseconds,
+ ).toBeGreaterThanOrEqual(
+ Temporal.Instant.from(archived[1].archivedAt).epochMilliseconds,
);
});
it('complete records the snapshot version it was made against', async () => {
const r = await add(projectId, 'clean kitchen', 7, db);
await edit(r.id, { frequencyDays: 5 }, db);
- const doneAt = new Date().toISOString();
+ const doneAt = Temporal.Now.instant().toString({
+ smallestUnit: 'millisecond',
+ });
const completion = await complete(r.id, 'with vinegar', doneAt, db);
expect(completion.routineVersion).toBe(2);
expect(completion.note).toBe('with vinegar');
@@ -132,16 +138,21 @@ describe('routines service', () => {
it('dashboard computes urgency and health from completions', async () => {
const r = await add(projectId, 'clean kitchen', 7, db);
- const createdAt = Date.parse(r.createdAt);
- await complete(r.id, null, new Date(createdAt).toISOString(), db);
+ const created = Temporal.Instant.from(r.createdAt);
+ await complete(
+ r.id,
+ null,
+ created.toString({ smallestUnit: 'millisecond' }),
+ db,
+ );
// 22 days after completion with a 7-day routine => two periods overdue
- const now = createdAt + 22 * DAY_MS;
+ const now = created.toZonedDateTimeISO('UTC').add({ days: 22 }).toInstant();
const dashboard = await loadProjectDashboard(projectId, now, db);
expect(dashboard.routines).toHaveLength(1);
expect(dashboard.routines[0].status).toBe('veryLate');
expect(dashboard.healthScore).toBe(0);
const last = dashboard.healthSeries[dashboard.healthSeries.length - 1];
- expect(last.at).toBe(now);
+ expect(last.at).toBe(now.epochMilliseconds);
expect(last.health).toBe(dashboard.healthScore);
});
@@ -150,7 +161,7 @@ describe('routines service', () => {
const growth = await addProject('Personal growth', db);
await add(growth.id, 'read 30 minutes', 1, db);
- const now = Date.now();
+ const now = Temporal.Now.instant();
const overview = await loadOverview(now, db);
expect(overview.projects).toHaveLength(2);
expect(overview.globalScore).toBe(