fix(03): CR-01 preserve RRULE on edit-as-move (forward source rule to create row)
This commit is contained in:
@@ -413,6 +413,60 @@ describe('PATCH /api/events/:uid/edit', () => {
|
||||
})
|
||||
expect(res.status).toBe(202)
|
||||
})
|
||||
|
||||
// CR-01 (iteration 2): edit-as-move must carry the source event's RRULE through
|
||||
// to the create row so a moved recurring series does not silently collapse into a
|
||||
// single occurrence. The edit payload omits `recurrence`; the route must extract the
|
||||
// RRULE from the source event's rawVevent and stash it on the create payload as
|
||||
// `_preservedRrule` so the worker re-applies it.
|
||||
it('CR-01: move of a recurring event stashes the source RRULE on the create outbox row', async () => {
|
||||
// Seed a recurring source event (RRULE:FREQ=WEEKLY;BYDAY=MO) on the user's calendar.
|
||||
mockDbRows = [
|
||||
{
|
||||
uid: 'uid-001@familysync',
|
||||
etag: '"etag-abc"',
|
||||
objectUrl: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/uid-001.ics',
|
||||
calendarId: 1,
|
||||
calendarUrl: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/',
|
||||
userId: 1,
|
||||
rawVevent: SAMPLE_VEVENT_RECURRING_TIMED,
|
||||
},
|
||||
]
|
||||
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 })
|
||||
|
||||
const { app } = await import('../../src/index.js')
|
||||
const res = await app.request('/api/events/uid-001%40familysync/edit', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
title: 'Moved event',
|
||||
allDay: false,
|
||||
start: '2026-06-15T10:00:00Z',
|
||||
end: '2026-06-15T11:00:00Z',
|
||||
// Different calendarUrl than the source → triggers the edit-as-move path (D-04)
|
||||
calendarUrl: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Family/',
|
||||
}),
|
||||
})
|
||||
expect(res.status).toBe(202)
|
||||
|
||||
// The move inserts a delete+create pair inside a transaction. Find the create row's
|
||||
// payload and assert the preserved RRULE survived.
|
||||
const createInsertCall = mockInsertValuesFn.mock.calls.find((call) => {
|
||||
const arg = call[0] as { operation?: string; payload?: string }
|
||||
return arg?.operation === 'create'
|
||||
})
|
||||
expect(createInsertCall).toBeDefined()
|
||||
const createArg = createInsertCall![0] as { payload: string }
|
||||
const parsed = JSON.parse(createArg.payload) as { _preservedRrule?: string }
|
||||
expect(parsed._preservedRrule).toBe('FREQ=WEEKLY;BYDAY=MO')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user