fix(03): update event lookup test mocks for CR-01/CR-02 query-chain changes

The CR-01 fix appended .orderBy().limit(1) to the edit/delete event lookups
and CR-02 added .innerJoin(calendars).limit(1) to the freshest-etag re-read.
The existing test doubles terminated the mock chain at .where(), so the new
chain calls hit undefined methods → handlers caught the throw and returned 503
(events.test.ts) and the worker skipped the PUT (outboxWorker.test.ts).

Extend the mocks to match the corrected production chains. Behaviour-preserving:
mockWhereCalEvents stays the awaited terminal so etag override assertions still drive.

8 failing tests now green; full suite: api 103, pwa 141.
This commit is contained in:
Lucas Berger
2026-06-09 10:51:10 -04:00
parent 6d2fd79209
commit 7a48659cae
2 changed files with 39 additions and 12 deletions
+30 -11
View File
@@ -385,9 +385,14 @@ describe('PATCH /api/events/:uid/edit', () => {
userId: 1,
},
]
// After BUG 1 fix, the edit lookup uses .from(calendarEvents).innerJoin(calendars, ...).where(...)
// Wire mockFromFn to expose innerJoin → where so the handler resolves mockDbRows.
const mockInnerJoinWhere = vi.fn().mockImplementation(() => Promise.resolve(mockDbRows))
// After BUG 1 + CR-01 fix, the edit lookup uses
// .from(calendarEvents).innerJoin(calendars, ...).where(...).orderBy(...).limit(1).
// Wire mockFromFn to expose innerJoin → where → orderBy → limit so the handler resolves mockDbRows.
const mockInnerJoinWhere = vi.fn().mockReturnValue({
orderBy: vi.fn().mockReturnValue({
limit: vi.fn().mockImplementation(() => Promise.resolve(mockDbRows)),
}),
})
const mockInnerJoin = vi.fn().mockReturnValue({ where: mockInnerJoinWhere })
mockFromFn.mockReturnValue({ innerJoin: mockInnerJoin })
mockSelectFn.mockReturnValue({ from: mockFromFn })
@@ -426,9 +431,14 @@ describe('DELETE /api/events/:uid', () => {
userId: 1,
},
]
// After BUG 1 fix, the delete lookup uses .from(calendarEvents).innerJoin(calendars, ...).where(...)
// Wire mockFromFn to expose innerJoin → where so the handler resolves mockDbRows.
const mockInnerJoinWhere = vi.fn().mockImplementation(() => Promise.resolve(mockDbRows))
// After BUG 1 + CR-01 fix, the delete lookup uses
// .from(calendarEvents).innerJoin(calendars, ...).where(...).orderBy(...).limit(1).
// Wire mockFromFn to expose innerJoin → where → orderBy → limit so the handler resolves mockDbRows.
const mockInnerJoinWhere = vi.fn().mockReturnValue({
orderBy: vi.fn().mockReturnValue({
limit: vi.fn().mockImplementation(() => Promise.resolve(mockDbRows)),
}),
})
const mockInnerJoin = vi.fn().mockReturnValue({ where: mockInnerJoinWhere })
mockFromFn.mockReturnValue({ innerJoin: mockInnerJoin })
mockSelectFn.mockReturnValue({ from: mockFromFn })
@@ -543,8 +553,12 @@ describe('CR-01: canonical client payload (title/start/end) accepted by server',
userId: 1,
},
]
// Edit lookup uses innerJoin after BUG 1 fix
const mockInnerJoinWhere = vi.fn().mockImplementation(() => Promise.resolve(mockDbRows))
// Edit lookup uses innerJoin → where → orderBy → limit after BUG 1 + CR-01 fix
const mockInnerJoinWhere = vi.fn().mockReturnValue({
orderBy: vi.fn().mockReturnValue({
limit: vi.fn().mockImplementation(() => Promise.resolve(mockDbRows)),
}),
})
const mockInnerJoin = vi.fn().mockReturnValue({ where: mockInnerJoinWhere })
mockFromFn.mockReturnValue({ innerJoin: mockInnerJoin })
mockSelectFn.mockReturnValue({ from: mockFromFn })
@@ -674,9 +688,14 @@ describe('regression: edit/delete lookups join calendars (BUG 1)', () => {
beforeEach(() => {
mockDbRows = [seededRow]
// Wire from() → innerJoin() → where(); the innerJoin spy proves the handler
// routes through the join rather than calling .where() directly on from().
const innerJoinWhere = vi.fn().mockImplementation(() => Promise.resolve(mockDbRows))
// Wire from() → innerJoin() → where() → orderBy() → limit(); the innerJoin spy
// proves the handler routes through the join rather than calling .where() directly
// on from(). The CR-01 fix appends .orderBy(...).limit(1) after .where(...).
const innerJoinWhere = vi.fn().mockReturnValue({
orderBy: vi.fn().mockReturnValue({
limit: vi.fn().mockImplementation(() => Promise.resolve(mockDbRows)),
}),
})
innerJoinSpy = vi.fn().mockReturnValue({ where: innerJoinWhere })
mockFromFn.mockReturnValue({ innerJoin: innerJoinSpy })
mockSelectFn.mockReturnValue({ from: mockFromFn })