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 { canMarkNotDone } from '@app/features/next-soup/actions/can-mark-not-done';
import type { SoupApiItem } from '@service-storage/generated/schemas';
import { describe, expect, it, vi } from 'vitest';
import {
isDisplayableSoupItem,
mapApiSoupItemToEntity,
} from './transform-utils';
vi.mock('@core/constant/allBlocks', () => ({
blockNameToDefaultFile: {},
itemToSafeName: vi.fn(),
}));
vi.mock('@core/context/channels', () => ({ useChannelsContext: vi.fn() }));
vi.mock('@core/user', () => ({ emailToId: vi.fn() }));
it('preserves channel team identity for section assignment checks', () => {
const item = {
tag: 'channel',
frecency_score: 0,
is_favorited: false,
data: {
channel: {
id: 'channel',
name: 'Design',
channel_type: 'team',
team_id: 'team',
owner_id: 'owner',
created_at: '2026-01-01T00:00:00Z',
updated_at: '2026-01-01T00:00:00Z',
},
participants: [],
is_participant: true,
},
} satisfies SoupApiItem;
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'channel',
channelType: 'team',
teamId: 'team',
});
});
describe('email soup entities', () => {
it.each([true, false])(
'preserves server Signal membership (%s) for Home activity',
(isSignal) => {
const item = {
tag: 'emailThread',
frecency_score: 0,
is_favorited: false,
data: {
id: 'email',
ownerId: 'owner',
properties: [],
attachments: [],
labels: [],
participants: [],
createdAt: '2026-09-01T00:00:00Z',
updatedAt: '2026-09-01T00:00:00Z',
sortTs: '2026-09-01T00:00:00Z',
inboxVisible: true,
isDraft: false,
isRead: false,
isImportant: !isSignal,
isSignal,
},
} satisfies SoupApiItem;
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'email',
isSignal,
isImportant: !isSignal,
});
}
);
it.each([
['no attachments', [], false],
[
'an attached PDF',
[{ filename: 'contract.pdf', mimeType: 'application/pdf' }],
true,
],
[
'a PDF that carries a Content-ID',
[
{
filename: 'contract.pdf',
mimeType: 'application/pdf',
contentId: '<contract@outlook>',
},
],
true,
],
[
'an attached photo',
[{ filename: 'photo.jpg', mimeType: 'image/jpeg' }],
true,
],
[
'only an inline signature logo',
[
{
filename: 'logo.png',
mimeType: 'image/png',
contentId: '<logo@signature>',
},
],
false,
],
[
'only a calendar invite',
[{ filename: 'invite.ics', mimeType: 'text/calendar' }],
false,
],
[
'an inline logo alongside a spreadsheet',
[
{
filename: 'logo.png',
mimeType: 'image/png',
contentId: '<logo@signature>',
},
{
filename: 'budget.xlsx',
mimeType:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
],
true,
],
])('flags a file attachment for %s', (_case, files, hasFileAttachment) => {
const item = {
tag: 'emailThread',
frecency_score: 0,
is_favorited: false,
data: {
id: 'email',
ownerId: 'owner',
properties: [],
attachments: files.map((file, index) => ({
...file,
id: `attachment-${index}`,
messageId: 'message',
createdAt: '2026-09-01T00:00:00Z',
})),
labels: [],
participants: [],
createdAt: '2026-09-01T00:00:00Z',
updatedAt: '2026-09-01T00:00:00Z',
sortTs: '2026-09-01T00:00:00Z',
inboxVisible: true,
isDraft: false,
isRead: false,
isImportant: false,
isSignal: false,
},
} satisfies SoupApiItem;
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'email',
hasFileAttachment,
});
});
it.each([
[false, false],
[true, true],
[undefined, true],
])(
'an archived row with received mail %s offers Mark not done: %s',
(hasReceivedMail, offered) => {
// GraphQL rows carry the flag beyond the REST preview type.
const data = {
id: 'email',
ownerId: 'owner',
properties: [],
attachments: [],
labels: [],
participants: [],
createdAt: '2026-09-01T00:00:00Z',
updatedAt: '2026-09-01T00:00:00Z',
sortTs: '2026-09-01T00:00:00Z',
inboxVisible: false,
hasReceivedMail,
isDraft: false,
isRead: true,
isImportant: false,
isSignal: false,
};
const item = {
tag: 'emailThread',
frecency_score: 0,
is_favorited: false,
data,
} satisfies SoupApiItem;
const entity = mapApiSoupItemToEntity(item);
expect(entity).toMatchObject({ type: 'email', done: true });
expect(canMarkNotDone(entity)).toBe(offered);
}
);
});
describe('initiative soup entities', () => {
it('keeps projects separate from folders and backing description documents', () => {
const item = {
tag: 'initiative',
frecency_score: 0,
is_favorited: false,
data: {
id: 'initiative',
name: 'Launch',
ownerId: 'owner',
properties: [],
createdAt: '2026-09-01T00:00:00Z',
updatedAt: '2026-09-26T00:00:00Z',
},
} satisfies SoupApiItem;
expect(isDisplayableSoupItem(item)).toBe(true);
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'initiative',
id: 'initiative',
name: 'Launch',
properties: [],
});
});
});
describe('chat soup entities', () => {
it.each(['openai/gpt-5.6', 'anthropic/claude-sonnet-5', null, undefined])(
'preserves an optional saved model (%s) from REST or mapped GraphQL data',
(model) => {
const item = {
tag: 'chat',
frecency_score: 0,
is_favorited: false,
data: {
id: 'chat-model',
name: 'Chat',
model,
ownerId: 'macro|[email protected]',
isPersistent: true,
properties: [],
createdAt: '2026-09-11T00:00:00Z',
updatedAt: '2026-09-11T00:00:00Z',
},
} satisfies SoupApiItem;
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'chat',
id: item.data.id,
model,
isFavorited: false,
});
}
);
});
describe('document soup entities', () => {
it('excludes backing descriptions from lists while keeping direct document materialization', () => {
const document = (
id: string,
subType: Extract<SoupApiItem, { tag: 'document' }>['data']['subType']
): Extract<SoupApiItem, { tag: 'document' }> => ({
tag: 'document',
frecency_score: 0,
is_favorited: false,
data: {
id,
name: 'Same title',
ownerId: 'macro|[email protected]',
fileType: 'md',
subType,
documentVersionId: 1,
properties: [],
createdAt: '2026-09-11T00:00:00Z',
updatedAt: '2026-09-11T00:00:00Z',
},
});
const description = document('description', {
type: 'initiative_description',
});
const folder: SoupApiItem = {
tag: 'project',
frecency_score: 0,
is_favorited: false,
data: {
id: 'folder',
name: 'Same title',
ownerId: 'macro|[email protected]',
properties: [],
createdAt: '2026-09-11T00:00:00Z',
updatedAt: '2026-09-11T00:00:00Z',
},
};
const items = [
description,
document('note', null),
document('task', { type: 'task', is_completed: false }),
folder,
];
expect(
items.filter(isDisplayableSoupItem).map((item) => item.data.id)
).toEqual(['note', 'task', 'folder']);
expect(mapApiSoupItemToEntity(description)).toMatchObject({
id: 'description',
type: 'document',
});
});
it.each([
[
{ type: 'task', is_completed: true },
{ type: 'task', is_completed: true },
],
[{ type: 'skill' }, { type: 'skill' }],
[{ type: 'initiative_description' }, undefined],
] as const)(
'maps the wire sub type %j to the app sub type %j',
(subType, expected) => {
const item = {
tag: 'document',
frecency_score: 0,
is_favorited: false,
data: {
id: 'doc-sub-type',
name: 'Plan',
ownerId: 'macro|[email protected]',
fileType: 'md',
subType,
documentVersionId: 1,
properties: [],
createdAt: '2026-09-11T00:00:00Z',
updatedAt: '2026-09-11T00:00:00Z',
},
} satisfies SoupApiItem;
expect(mapApiSoupItemToEntity(item)).toMatchObject({
type: 'document',
id: item.data.id,
subType: expected,
});
}
);
});
describe('unknown soup entities', () => {
it('maps a tag from a newer server to a placeholder row instead of throwing', () => {
const fromNewerServer = JSON.parse(
'{"tag":"whiteboard","frecency_score":0,"is_favorited":false,"data":{"id":"board"}}'
);
expect(mapApiSoupItemToEntity(fromNewerServer)).toMatchObject({
type: 'document',
id: 'board',
});
});
});