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 { message } from '../../email-message/tests/messages';
import { fromInboxOptions, replySenderAddress } from './email-sender';
const inbox = {
id: 'inbox',
email_address: '[email protected]',
sendAs: [
{ email_address: '[email protected]', displayName: 'Resident' },
{ email_address: '[email protected]' },
{ email_address: '[email protected]' },
],
};
describe('email sender identities', () => {
it('deduplicates case-insensitively within an inbox without merging different inboxes', () => {
const options = fromInboxOptions([inbox, { ...inbox, id: 'delegated' }]);
expect(options).toHaveLength(4);
expect(new Set(options.map((option) => option.id)).size).toBe(4);
expect(options.filter((option) => option.isAlias)).toHaveLength(2);
});
it.each(['to', 'cc', 'bcc'] as const)(
'defaults to the verified alias in %s',
(field) => {
expect(
replySenderAddress(
inbox,
message('parent', {
to: [],
cc: [],
bcc: [],
[field]: [{ email: '[email protected]' }],
})
)
).toBe('[email protected]');
}
);
it('preserves the base address for direct mail and prefers To over Cc', () => {
expect(
replySenderAddress(
inbox,
message('parent', {
to: [{ email: '[email protected]' }],
cc: [{ email: '[email protected]' }],
})
)
).toBe('[email protected]');
});
it('prefers an alias over the base address when both are To recipients', () => {
expect(
replySenderAddress(
inbox,
message('parent', {
to: [
{ email: '[email protected]' },
{ email: '[email protected]' },
],
})
)
).toBe('[email protected]');
});
it('continues outgoing chains from the previous sender', () => {
expect(
replySenderAddress(
inbox,
message('sent', {
from: { email: '[email protected]' },
to: [{ email: '[email protected]' }],
})
)
).toBe('[email protected]');
});
it('keeps healthy inbox aliases if another inbox lookup failed', () => {
expect(
fromInboxOptions([
inbox,
{ id: 'unavailable', email_address: '[email protected]', sendAs: null },
])
).toHaveLength(3);
});
});