fix(02): populate hasRrule on every sync upsert so recurring masters are flagged

- Use ICAL.Event.isRecurring() (parity with expand.ts) to detect RRULE/RDATE
- Add hasRrule to .values() INSERT and .onDuplicateKeyUpdate() SET so the flag
  is set on first sync and self-heals on every subsequent re-sync
- Without this fix every event had has_rrule=0 (column default), causing the
  events route recurring-master pre-filter to return zero recurring occurrences
- Add sync.test.ts cases: hasRrule=true for timed+all-day recurring VEVENTs,
  hasRrule=false for non-recurring, and hasRrule in onDuplicateKeyUpdate.set
This commit is contained in:
Lucas Berger
2026-06-05 14:50:18 -04:00
parent 5d82f859fd
commit f70496871a
3 changed files with 127 additions and 0 deletions
+90
View File
@@ -14,6 +14,8 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
import {
SAMPLE_VEVENT_TIMED,
SAMPLE_VEVENT_ALLDAY,
SAMPLE_VEVENT_RECURRING_TIMED,
SAMPLE_VEVENT_RECURRING_ALLDAY,
} from '../helpers/db.js'
// Track calls for assertions
@@ -157,6 +159,94 @@ describe('syncCalendar', () => {
expect(eventArg.rawVevent).toBe(SAMPLE_VEVENT_TIMED)
})
it('sets hasRrule=true for a VEVENT with RRULE (timed recurring)', async () => {
const { syncCalendar } = await import('../../src/broker/sync.js')
const mockClient = {
fetchCalendarObjects: vi.fn().mockResolvedValue([
{ data: SAMPLE_VEVENT_RECURRING_TIMED, etag: '"etag-rrule"', url: '/rrule.ics' },
]),
}
const mockDavCal = {
url: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/',
displayName: 'Test Calendar',
ctag: 'ctag-v1',
syncToken: null,
}
await syncCalendar(mockClient as never, mockDavCal as never, 1)
expect(mockInsert).toHaveBeenCalledTimes(2)
const eventValuesArg = mockValues.mock.calls[1][0]
expect(eventValuesArg.hasRrule).toBe(true)
})
it('sets hasRrule=true for an all-day VEVENT with RRULE (all-day recurring)', async () => {
const { syncCalendar } = await import('../../src/broker/sync.js')
const mockClient = {
fetchCalendarObjects: vi.fn().mockResolvedValue([
{ data: SAMPLE_VEVENT_RECURRING_ALLDAY, etag: '"etag-rrule-allday"', url: '/rrule-allday.ics' },
]),
}
const mockDavCal = {
url: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/',
displayName: 'Test Calendar',
ctag: 'ctag-v1',
syncToken: null,
}
await syncCalendar(mockClient as never, mockDavCal as never, 1)
expect(mockInsert).toHaveBeenCalledTimes(2)
const eventValuesArg = mockValues.mock.calls[1][0]
expect(eventValuesArg.hasRrule).toBe(true)
})
it('sets hasRrule=false for a non-recurring timed VEVENT', async () => {
const { syncCalendar } = await import('../../src/broker/sync.js')
const mockClient = {
fetchCalendarObjects: vi.fn().mockResolvedValue([
{ data: SAMPLE_VEVENT_TIMED, etag: '"etag-oneoff"', url: '/oneoff.ics' },
]),
}
const mockDavCal = {
url: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/',
displayName: 'Test Calendar',
ctag: 'ctag-v1',
syncToken: null,
}
await syncCalendar(mockClient as never, mockDavCal as never, 1)
expect(mockInsert).toHaveBeenCalledTimes(2)
const eventValuesArg = mockValues.mock.calls[1][0]
expect(eventValuesArg.hasRrule).toBe(false)
})
it('includes hasRrule in onDuplicateKeyUpdate set so re-syncs self-heal the flag', async () => {
const { syncCalendar } = await import('../../src/broker/sync.js')
const mockClient = {
fetchCalendarObjects: vi.fn().mockResolvedValue([
{ data: SAMPLE_VEVENT_RECURRING_TIMED, etag: '"etag-v2"', url: '/rrule.ics' },
]),
}
const mockDavCal = {
url: 'https://caldav.fastmail.com/dav/calendars/user/test@fm.com/Default/',
displayName: 'Test Calendar',
ctag: 'ctag-v2',
syncToken: null,
}
await syncCalendar(mockClient as never, mockDavCal as never, 1)
// The second onDuplicateKeyUpdate call is for the event upsert
const eventUpdateArg = mockOnDuplicateKeyUpdate.mock.calls[1][0]
expect(eventUpdateArg.set).toHaveProperty('hasRrule', true)
})
it('updates the calendar ctag/syncToken after a successful sync', async () => {
const { syncCalendar } = await import('../../src/broker/sync.js')