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.

1.9 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import {
  PREFILL_CAP,
  prefillableTeammates,
  removeInviteSlot,
  validInviteEmails,
} from './team';

const contact = (email: string) => email;

describe('prefillableTeammates', () => {
  it('picks same-domain contacts, skipping the user and duplicates', () => {
    expect(
      prefillableTeammates({
        contacts: [
          contact('[email protected]'),
          contact('[email protected]'),
          contact('[email protected]'),
          contact('[email protected]'),
          contact('[email protected]'),
        ],
        domain: 'macro.com',
        ownEmail: '[email protected]',
      })
    ).toEqual(['[email protected]', '[email protected]']);
  });

  it('pre-adds nothing without a suggested domain', () => {
    expect(
      prefillableTeammates({
        contacts: [contact('[email protected]')],
        domain: undefined,
        ownEmail: '[email protected]',
      })
    ).toEqual([]);
  });

  it('caps how many teammates get pre-added', () => {
    const contacts = Array.from({ length: PREFILL_CAP + 3 }, (_, i) =>
      contact(`teammate${i}@macro.com`)
    );
    expect(
      prefillableTeammates({
        contacts,
        domain: 'macro.com',
        ownEmail: '[email protected]',
      })
    ).toHaveLength(PREFILL_CAP);
  });
});

describe('removeInviteSlot', () => {
  it('drops the row at the index, keeping one empty row when the last goes', () => {
    expect(removeInviteSlot(['[email protected]', '[email protected]', ''], 1)).toEqual([
      '[email protected]',
      '',
    ]);
    expect(removeInviteSlot(['[email protected]'], 0)).toEqual(['']);
  });
});

describe('validInviteEmails', () => {
  it('trims, dedupes, and drops blanks, junk, and the user themselves', () => {
    expect(
      validInviteEmails(
        [' [email protected] ', '[email protected]', '', 'nope', '[email protected]'],
        '[email protected]'
      )
    ).toEqual(['[email protected]']);
  });
});