test: check that a range read stops at an account switch

This commit is contained in:
Linus Rath
2026-10-29 03:03:21 +01:00
parent c0c3429c75
commit c84c9ddde7
@@ -45,6 +45,8 @@ import {
selectVisibleCalendars,
selectVisibleEvents,
ImportRefusedError,
CalendarAccountChangedError,
loadEventsInRange,
} from '../calendar-store';
const mockGetCalendars = calendarApi.getCalendars as ReturnType<typeof vi.fn>;
@@ -214,6 +216,39 @@ describe('calendar-store', () => {
expect(state.loadedRange).toBeNull();
expect(state.error).toBeNull();
});
// The reminders and the widget read ranges with loadEventsInRange
// directly, without a store generation of their own.
it('hands no events read before the reset to a range read outside the store', async () => {
// The reset comes while the account's events are being read. (The
// test above leaves its answer unread: its load stops before asking.)
mockQueryEvents.mockReset();
mockQueryEvents.mockImplementationOnce(async () => {
useCalendarStore.getState().reset();
return ['e-old'];
});
mockGetEvents.mockResolvedValue([{ id: 'e-old', title: 'Old account event', start: '2026-03-20T15:00:00', calendarIds: { 'cal-1': true } }]);
await expect(loadEventsInRange([{ id: 'cal-1' }] as never, ['cal-1'], '2026-03-01T00:00:00Z', '2026-04-01T00:00:00Z'))
.rejects.toBeInstanceOf(CalendarAccountChangedError);
});
it('reads no further account after the reset', async () => {
mockQueryEvents.mockReset();
mockQueryEvents.mockImplementationOnce(async () => {
useCalendarStore.getState().reset();
return [];
});
const calendars = [
{ id: 'cal-1' },
{ id: 'acc-2:cal-9', originalId: 'cal-9', accountId: 'acc-2' },
];
const read = loadEventsInRange(calendars as never, ['cal-1', 'acc-2:cal-9'], '2026-03-01T00:00:00Z', '2026-04-01T00:00:00Z');
await expect(read).rejects.toBeInstanceOf(CalendarAccountChangedError);
// The shared account would be read under the next login.
expect(mockQueryEvents).toHaveBeenCalledTimes(1);
});
});
describe('fetchTasks', () => {