Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

3.6 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import {
  groupCalendarInvitations,
  invitationCanBeAdded,
  invitationDisplayTitle,
  invitationSchedule,
  safeInvitationUrl,
} from './calendar-invitation';
import {
  invitationFixture,
  invitationFixtures,
} from './calendar-invitation-fixtures';
import { decodeCalendarInvitations } from './calendar-invitation-schema';

describe('saved invitation presentation', () => {
  it('keeps all-day DTEND exclusive across viewer timezones', () => {
    const value = invitationSchedule(
      invitationFixtures.allDay,
      true,
      'America/Los_Angeles'
    );
    expect(value.when).toContain('24');
    expect(value.when).toContain('25');
    expect(value.when).not.toContain('26,');
    expect(value.secondary).toBe('All day');
    expect(value.when).not.toContain('12:00');
  });
  it('honors 24-hour preference and explains unresolved zones', () => {
    expect(
      invitationSchedule(invitationFixture, false, 'America/Los_Angeles').when
    ).toContain('10:00–10:30');
    expect(
      invitationSchedule(invitationFixtures.floating, true, 'UTC').secondary
    ).toContain('Timezone unresolved');
  });
  it('groups recurring components without dropping overrides or unrelated events', () => {
    const override = {
      ...invitationFixture,
      id: 'override',
      recurrence_id_raw: 'RECURRENCE-ID:20260924T170000Z',
    };
    const groups = groupCalendarInvitations([
      invitationFixture,
      override,
      { ...invitationFixture, uid: 'another' },
    ]);
    expect(groups).toHaveLength(2);
    expect(groups[0].primary).toBe(invitationFixture);
    expect(groups[0].related).toEqual([override]);
  });
  it('adds only a whole shared event with a readable time and recorded recurrence', () => {
    const shared = invitationFixtures.shared;
    expect(invitationCanBeAdded(shared)).toBe(true);
    expect(
      invitationCanBeAdded({
        ...invitationFixtures.allDay,
        method: 'publish',
        recurrence: [],
      })
    ).toBe(true);
    expect(invitationCanBeAdded(invitationFixture)).toBe(false);
    expect(invitationCanBeAdded({ ...shared, status: 'CANCELLED' })).toBe(
      false
    );
    expect(
      invitationCanBeAdded({
        ...shared,
        recurrence_id_raw: 'RECURRENCE-ID:20260924T170000Z',
      })
    ).toBe(false);
    expect(invitationCanBeAdded({ ...shared, recurrence: undefined })).toBe(
      false
    );
    expect(
      invitationCanBeAdded({
        ...invitationFixtures.floating,
        method: 'publish',
        recurrence: [],
      })
    ).toBe(false);
  });
  it('drops unsupported cache payloads and unsafe action URLs', () => {
    expect(decodeCalendarInvitations([{}])).toBeUndefined();
    expect(decodeCalendarInvitations([invitationFixture])).toHaveLength(1);
    for (const url of [
      'javascript:alert(1)',
      'data:text/html,bad',
      'https://user:[email protected]',
      '/relative',
    ])
      expect(safeInvitationUrl(url)).toBeUndefined();
  });
  it('drops scheduling prefixes that restate the card status', () => {
    for (const [title, responder, expected] of [
      ['Accepted: Product review', undefined, 'Product review'],
      ['Canceled event: Launch check-in', undefined, 'Launch check-in'],
      ['Cancelled: Launch check-in', undefined, 'Launch check-in'],
      ['Proposed time: Planning', undefined, 'Planning'],
      ['Sam accepted Product review', 'Sam', 'Product review'],
      ['Invitation strategy sync', undefined, 'Invitation strategy sync'],
      ['Product review', 'Sam', 'Product review'],
    ] as const)
      expect(invitationDisplayTitle(title, responder)).toBe(expected);
  });
});