feat(shared,api): add pause + sort_order columns and contracts
Adds server-side pause accounting and activity ordering primitives. - WorkSession contract gains paused_seconds (number) and paused_at (ISO string | null). - Activity contract gains sort_order (number); new ReorderActivitiesInput zod. - work_sessions += paused_seconds (int NOT NULL DEFAULT 0) + paused_at (timestamp_ms nullable). - activities += sort_order (int NOT NULL DEFAULT 0). - toWorkSession / toActivity map the new fields; generated migration 0003. The new fields are additive; existing api/worker/admin tests stay green. Products affected: SoleLog backend (apps/api), shared contracts (packages/shared)
This commit is contained in:
39
apps/api/test/work-session.test.ts
Normal file
39
apps/api/test/work-session.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { toWorkSession } from '../src/lib/work-session';
|
||||
import type { workSessions } from '../src/db/schema';
|
||||
|
||||
type WorkSessionRow = typeof workSessions.$inferSelect;
|
||||
|
||||
function baseRow(overrides: Partial<WorkSessionRow> = {}): WorkSessionRow {
|
||||
return {
|
||||
id: 1,
|
||||
userId: 'user-1',
|
||||
activityId: 1,
|
||||
insoleType: 'Kurk',
|
||||
pairCount: 2,
|
||||
startTime: new Date('2026-06-17T08:00:00.000Z'),
|
||||
endTime: null,
|
||||
durationSeconds: null,
|
||||
pausedSeconds: 0,
|
||||
pausedAt: null,
|
||||
status: 'active',
|
||||
source: 'app',
|
||||
notes: null,
|
||||
createdAt: new Date('2026-06-17T08:00:00.000Z'),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('toWorkSession paused fields', () => {
|
||||
it('maps pausedSeconds and a null pausedAt', () => {
|
||||
const result = toWorkSession(baseRow({ pausedSeconds: 120, pausedAt: null }));
|
||||
expect(result.paused_seconds).toBe(120);
|
||||
expect(result.paused_at).toBeNull();
|
||||
});
|
||||
|
||||
it('maps a pausedAt Date to its ISO string', () => {
|
||||
const pausedAt = new Date('2026-06-17T08:05:00.000Z');
|
||||
const result = toWorkSession(baseRow({ pausedSeconds: 0, pausedAt }));
|
||||
expect(result.paused_at).toBe(pausedAt.toISOString());
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user