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.

2.5 KB
Raw Blame
import type { CalendarAttendee } from '@service-storage/generated/schemas/calendarAttendee';
import { describe, expect, it } from 'vitest';
import {
  type CalendarEvent,
  DEFAULT_GUEST_POLICY,
  NO_VIEWER_CAPABILITIES,
} from '../types';
import { eventEmailRecipients, guestEmails } from './guest-emails';

function attendee(
  email: string,
  overrides: Partial<CalendarAttendee> = {}
): CalendarAttendee {
  return {
    email,
    isOptional: false,
    isOrganizer: false,
    isSelf: false,
    responseStatus: 'accepted',
    ...overrides,
  };
}

function event(attendees: CalendarAttendee[]): CalendarEvent {
  return {
    id: '["event","occurrence"]',
    eventId: 'event',
    occurrenceKey: 'occurrence',
    isCancelled: false,
    isReadOnly: false,
    guestPolicy: DEFAULT_GUEST_POLICY,
    viewerCan: NO_VIEWER_CAPABILITIES,
    attendees,
    recurrenceLines: [],
    sourceCalendarIds: [],
    title: 'Demo call',
    start: '2026-09-14T19:00:00.000Z',
    end: '2026-09-14T19:30:00.000Z',
    allDay: false,
    calendar: {
      id: 'jacob-cal',
      name: 'Jacob Beckerman',
      color: 'orange',
      emailAddress: '[email protected]',
      isPrimary: true,
    },
    visibleCalendars: [],
  };
}

describe('guestEmails', () => {
  it('lists every guest, the viewer included, in guest-list order', () => {
    expect(
      guestEmails([
        attendee('[email protected]'),
        attendee('[email protected]', { isSelf: true }),
        attendee('[email protected]', { isOptional: true }),
      ])
    ).toEqual(['[email protected]', '[email protected]', '[email protected]']);
  });

  it('lists an address once however it is cased or padded', () => {
    expect(
      guestEmails([
        attendee('[email protected]'),
        attendee(' [email protected] '),
        attendee(''),
      ])
    ).toEqual(['[email protected]']);
  });
});

describe('eventEmailRecipients', () => {
  it('addresses every guest but the viewer', () => {
    expect(
      eventEmailRecipients(
        event([
          attendee('[email protected]'),
          attendee('[email protected]', { isSelf: true }),
          attendee('[email protected]', { isOrganizer: true }),
        ])
      )
    ).toEqual(['[email protected]', '[email protected]']);
  });

  it('is empty when the viewer is the only guest', () => {
    expect(
      eventEmailRecipients(
        event([attendee('[email protected]', { isSelf: true })])
      )
    ).toEqual([]);
  });

  it('is empty for an event without guests', () => {
    expect(eventEmailRecipients(event([]))).toEqual([]);
  });
});