client-only-events.test.ts2.6 KBView on GitHub
import { isClientOnlyEvent } from '@/modules/calendar/hooks/use-event-manipulation';
import type { CalendarEvent } from '@/modules/calendar/types/calendar-types';

/**
 * Which calendar events exist only in this browser.
 *
 * This predicate is load-bearing for a failure that looks like the app is broken rather than
 * like a mistake. `CalendarView` paints a ghost of the unsaved `draftCalendarEvent` on the
 * grid so the draft can be dragged, and gives it the literal id `next-meeting-preview` —
 * deliberately NOT a `new-…` id, so the sync effect can tell the two apart. Everything that
 * mutated an event keyed off `isNewEvent`, which is `id.startsWith('new-')`, so the preview
 * fell through to the real Google path: adding a guest returned 404 Not Found, and then the
 * block could not be deleted either, because delete was asking Google to remove an id it had
 * never issued. Prod logs for the reported session are 16 straight 404s, update then delete.
 *
 * Drag and resize never had the bug — they always routed the preview back into the draft
 * store. This is the same rule, stated once, for every other handler.
 */
const event = (fields: Partial<CalendarEvent>): CalendarEvent => ({
  summary: 'Intro call',
  start: { dateTime: '2026-08-28T16:00:00Z' },
  end: { dateTime: '2026-08-28T16:30:00Z' },
  ...fields,
});

describe('isClientOnlyEvent', () => {
  it('claims the next-meeting preview, which no calendar has ever heard of', () => {
    expect(isClientOnlyEvent(event({ id: 'next-meeting-preview' }))).toBe(true);
  });

  it('claims it by its flag too, whatever id the ghost is given', () => {
    expect(isClientOnlyEvent(event({ id: 'anything', isNextMeetingPreview: true }))).toBe(true);
  });

  it('claims a block the create flow still owns', () => {
    expect(isClientOnlyEvent(event({ id: 'new-9f3c' }))).toBe(true);
  });

  it("claims the scheduler's proposed slots", () => {
    expect(isClientOnlyEvent(event({ id: 'proposed-1', isProposed: true }))).toBe(true);
  });

  it('claims an event with no id at all', () => {
    expect(isClientOnlyEvent(event({}))).toBe(true);
  });

  it('leaves a real Google event alone', () => {
    expect(isClientOnlyEvent(event({ id: '5b7k2q9m1v3n8p0r4t6y8u1i3o' }))).toBe(false);
  });

  it('leaves a recurring INSTANCE alone — its suffixed id is Google’s own', () => {
    expect(isClientOnlyEvent(event({ id: '5b7k2q9m_20260828T160000Z' }))).toBe(false);
  });

  it('leaves an event merely MENTIONED in chat alone: it is a real event being pointed at', () => {
    expect(isClientOnlyEvent(event({ id: '5b7k2q9m1v3n8p0r4t6y8u1i3o', isMentioned: true }))).toBe(
      false,
    );
  });
});