resolve-compose-targets.test.ts1.7 KBView on GitHub import { resolveSlackTargets } from '@/modules/conversations/components/timeline/composer/resolve-compose-targets';
import type { Conversation } from '@/modules/crm/types';
function makeConversation(
overrides: Partial<Conversation> = {},
): Conversation {
return {
id: 'conv_1',
userId: 'user_1',
name: 'Test',
status: null,
priority: null,
nextSteps: null,
nextStepDate: null,
statusOverview: null,
dealValue: null,
lastContactedAt: null,
lastEmailAt: null,
aopId: null,
important: false,
integrationMetadata: null,
createdAt: new Date(),
updatedAt: new Date(),
events: [],
customFields: [],
...overrides,
} as Conversation;
}
describe('resolveSlackTargets', () => {
it('returns [] when no slack metadata is linked', () => {
expect(resolveSlackTargets(makeConversation())).toEqual([]);
});
it('returns one target per slack metadata entry, labelled by channel name', () => {
const conv = makeConversation({
integrationMetadata: [
{ type: 'slack', workspaceId: 'T01', channelId: 'C09', channelName: 'acme-cedar' },
{ type: 'slack', workspaceId: 'T01', channelId: 'CXX' /* no channelName */ },
{ type: 'salesforce' /* unrelated */ } as never,
],
});
const targets = resolveSlackTargets(conv);
expect(targets).toHaveLength(2);
expect(targets[0]).toMatchObject({
id: 'slack:T01:C09',
workspaceId: 'T01',
channelId: 'C09',
channelName: 'acme-cedar',
label: '#acme-cedar',
});
expect(targets[1]).toMatchObject({
id: 'slack:T01:CXX',
channelName: 'CXX',
label: '#CXX',
});
});
});