Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
import { describe, expect, it } from 'vitest';
import {
isCalendarEventOngoing,
isMeetingEvent,
selectUpcomingCalendarEvents,
type UpcomingCalendarEvent,
} from './upcoming-calendar-events';
const call = (hour: number): UpcomingCalendarEvent => ({
id: `call-${hour}`,
eventId: 'recurring-event',
occurrenceKey: `occurrence-${hour}`,
title: 'Planning',
color: 'var(--color-accent)',
url: 'https://meet.google.com/one-room',
start: `2026-09-23T${hour}:00:00Z`,
end: `2026-09-23T${hour + 1}:00:00Z`,
allDay: false,
isMeeting: true,
});
const guest = {
email: '[email protected]',
isSelf: false,
isOrganizer: false,
isOptional: false,
responseStatus: 'accepted' as const,
};
const self = { ...guest, email: '[email protected]', isSelf: true };
const room = 'https://meet.google.com/one-room';
describe('isMeetingEvent', () => {
it('counts busy regular events with a call link or another guest', () => {
expect(isMeetingEvent({ attendees: [] }, room)).toBe(true);
expect(
isMeetingEvent(
{ eventType: 'default', transparency: 'opaque', attendees: [guest] },
undefined
)
).toBe(true);
});
it('skips solo blocks without a call link', () => {
expect(isMeetingEvent({ attendees: [] }, undefined)).toBe(false);
expect(isMeetingEvent({ attendees: [self] }, undefined)).toBe(false);
});
it('skips events that show the viewer as free', () => {
expect(
isMeetingEvent(
{ transparency: 'transparent', attendees: [self, guest] },
room
)
).toBe(false);
});
it('skips status-style event types', () => {
for (const eventType of [
'out_of_office',
'focus_time',
'working_location',
'birthday',
'from_gmail',
] as const) {
expect(isMeetingEvent({ eventType, attendees: [guest] }, room)).toBe(
false
);
}
});
});
describe('upcoming calendar calls', () => {
it('keeps ordinary events without a meeting link and uses exact ongoing boundaries', () => {
const event = { ...call(13), url: undefined };
expect(
selectUpcomingCalendarEvents([event], new Date('2026-09-23T12:00:00Z'))
).toEqual([event]);
expect(
isCalendarEventOngoing(event, new Date('2026-09-23T12:59:59Z'))
).toBe(false);
expect(isCalendarEventOngoing(event, new Date(event.start))).toBe(true);
expect(isCalendarEventOngoing(event, new Date(event.end))).toBe(false);
});
it('sorts before limiting and keeps an ongoing call until its end', () => {
expect(
selectUpcomingCalendarEvents(
[call(18), call(17), call(16), call(15), call(14), call(13), call(12)],
new Date('2026-09-23T13:30:00Z'),
5
).map((item) => item.id)
).toEqual(['call-13', 'call-14', 'call-15', 'call-16', 'call-17']);
expect(
selectUpcomingCalendarEvents([call(13)], new Date(call(13).end))
).toEqual([]);
});
it('keeps a future timed point without treating it as an ongoing meeting', () => {
const point = { ...call(13), end: call(13).start };
expect(
selectUpcomingCalendarEvents([point], new Date('2026-09-23T12:00:00Z'))
).toEqual([point]);
expect(
selectUpcomingCalendarEvents([point], new Date(point.start))
).toEqual([]);
expect(isCalendarEventOngoing(point, new Date(point.start))).toBe(false);
const emptyAllDay = {
...point,
allDay: true,
start: '2026-09-23',
end: '2026-09-23',
};
expect(
selectUpcomingCalendarEvents([emptyAllDay], new Date(2026, 8, 22))
).toEqual([]);
});
it('deduplicates overlapping windows without merging recurring calls sharing a URL', () => {
const first = call(13);
expect(
selectUpcomingCalendarEvents(
[first, call(14), { ...first, title: 'Updated planning' }],
new Date('2026-09-23T12:00:00Z')
)
).toEqual([{ ...first, title: 'Updated planning' }, call(14)]);
});
it('uses exclusive local date boundaries for all-day calls', () => {
const allDay = {
...call(13),
start: '2026-09-23',
end: '2026-09-24',
allDay: true,
};
expect(
selectUpcomingCalendarEvents([allDay], new Date(2026, 8, 23, 23, 59))
).toEqual([allDay]);
expect(
selectUpcomingCalendarEvents([allDay], new Date(2026, 8, 24))
).toEqual([]);
});
it('ignores invalid dates and reversed time ranges', () => {
expect(
selectUpcomingCalendarEvents(
[
{ ...call(13), start: 'invalid' },
{ ...call(14), end: 'invalid' },
{ ...call(15), end: call(13).end },
],
new Date('2026-09-23T12:00:00Z')
)
).toEqual([]);
});
});