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 type { MessageParent } from '@service-storage/messages';
import { createRoot, createSignal } from 'solid-js';
import { expect, it, vi } from 'vitest';
import { useMessageParticipants } from './use-message-participants';

vi.mock('./use-channel-participants', () => ({
  useChannelParticipants: (channelId: () => string) => ({
    users: () =>
      channelId()
        ? [{ id: 'macro|[email protected]', email: '', name: 'Member' }]
        : [],
    ids: () => [],
  }),
}));
vi.mock('@queries/contacts/contacts', () => ({
  useContacts: () => () => [
    { id: 'macro|[email protected]', email: '', name: 'Contact' },
  ],
}));
vi.mock('@queries/team/teams', () => ({
  useCurrentTeamQuery: () => ({
    isPending: false,
    data: {
      members: [
        { user_id: 'macro|[email protected]' },
        { user_id: 'macro|[email protected]' },
      ],
    },
  }),
}));

it('offers the owning team on CRM records and contacts on documents', () => {
  createRoot((dispose) => {
    const [parent, setParent] = createSignal<MessageParent>({
      type: 'crm_company',
      id: 'company',
    });
    const participants = useMessageParticipants(parent);
    const ids = () => participants().map((user) => user.id);

    expect(ids()).toEqual([
      'macro|[email protected]',
      'macro|[email protected]',
    ]);
    expect(participants()[0].email).toBe('[email protected]');

    setParent({ type: 'crm_contact', id: 'contact' });
    expect(ids()).toEqual([
      'macro|[email protected]',
      'macro|[email protected]',
    ]);

    setParent({ type: 'document', id: 'document' });
    expect(ids()).toEqual(['macro|[email protected]']);

    setParent({ type: 'call', id: 'call' });
    expect(ids()).toEqual(['macro|[email protected]']);

    setParent({ type: 'channel', id: 'channel' });
    expect(ids()).toEqual(['macro|[email protected]']);
    dispose();
  });
});