fix(03): CR-01 preserve RRULE on edit-as-move (forward source rule to create row)

This commit is contained in:
Lucas Berger
2026-06-09 10:59:19 -04:00
parent 7a48659cae
commit 5168920eb1
4 changed files with 146 additions and 2 deletions
@@ -281,6 +281,58 @@ describe('runOutboxDrain — ICS building from form JSON (CR-02)', () => {
const setArg = mockUpdateSet.mock.calls[0]?.[0] as { status?: string }
expect(setArg?.status).toBe('failed')
})
// CR-01 (iteration 2): the edit-as-move create branch must re-apply the RRULE the
// route stashed on the payload as `_preservedRrule`, so a moved recurring series keeps
// its RRULE instead of collapsing into a single occurrence.
it('CR-01: create row re-applies _preservedRrule → emitted ICS contains RRULE:', async () => {
const { createCalendarEvent } = await import('../../src/broker/write.js')
let capturedIcsString: unknown = null
vi.mocked(createCalendarEvent).mockImplementation(async (_client, _cal, _uid, icsString) => {
capturedIcsString = icsString
return makeResponse(201)
})
// Move payload: no explicit `recurrence`, but the route stashed the source RRULE.
const movePayload = JSON.stringify({
title: 'Moved weekly standup',
allDay: false,
start: '2026-06-10T12:00:00',
end: '2026-06-10T13:00:00',
_preservedRrule: 'FREQ=WEEKLY;BYDAY=MO',
})
mockPendingRows = [makeRow({ operation: 'create', payload: movePayload, groupId: 'move-grp-1' })]
await runOutboxDrain()
expect(typeof capturedIcsString).toBe('string')
expect(capturedIcsString as string).toContain('RRULE:')
expect(capturedIcsString as string).toContain('FREQ=WEEKLY')
})
// CR-01 corollary: an explicit `recurrence` on a create still wins over any preserved
// RRULE (deliberate user choice); recurrence:'none' must emit no RRULE.
it("CR-01: explicit recurrence:'none' wins → emitted ICS has no RRULE even if _preservedRrule present", async () => {
const { createCalendarEvent } = await import('../../src/broker/write.js')
let capturedIcsString: unknown = null
vi.mocked(createCalendarEvent).mockImplementation(async (_client, _cal, _uid, icsString) => {
capturedIcsString = icsString
return makeResponse(201)
})
const payload = JSON.stringify({
title: 'One-off',
allDay: false,
start: '2026-06-10T12:00:00',
end: '2026-06-10T13:00:00',
recurrence: 'none',
_preservedRrule: 'FREQ=WEEKLY;BYDAY=MO',
})
mockPendingRows = [makeRow({ operation: 'create', payload })]
await runOutboxDrain()
expect(typeof capturedIcsString).toBe('string')
expect(capturedIcsString as string).not.toContain('RRULE:')
})
})
describe('runOutboxDrain — edit-as-move ordering (D-04)', () => {