-
Notifications
You must be signed in to change notification settings - Fork 1
/
NotifySlackChannel.unit.ts
25 lines (22 loc) · 958 Bytes
/
NotifySlackChannel.unit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { SlackService } from '../../services/slack';
import { NotifySlackChannel } from './NotifySlackChannel';
import { UserCreatedEvent } from '../../../users/domain/events/UserCreatedEvent';
import { createUser } from '../../../../shared/utils/test';
test('Slack service is called when notifying on a channel', async () => {
const slackService = new SlackService();
const spyOnSendMsg = jest
.spyOn(slackService, 'sendMessage')
.mockImplementation(() => new Promise((resolve) => resolve('mocked')));
const notifySlackChannelUseCase = new NotifySlackChannel(slackService);
const userOrError = createUser({
email: '[email protected]',
username: 'test_user',
});
const event = new UserCreatedEvent(userOrError).toDTO();
await notifySlackChannelUseCase.execute(event);
expect(spyOnSendMsg).toHaveBeenCalledWith(
expect.stringContaining('[email protected]') &&
expect.stringContaining('test_user'),
'growth'
);
});