import { Test, TestingModule } from '@nestjs/testing' import { Notifications } from '../domain/notifications' import { MockedModule } from '../../../../test/types' import { factory } from '../../../../test/factories' import { NotificationController } from './notification.controller' describe('NotificationController', () => { let notificationController: NotificationController let notifications: MockedModule beforeAll(async () => { notifications = { sendMessage: jest.fn(), deleteMessage: jest.fn(), processNotificationReports: jest.fn(), } const moduleRef: TestingModule = await Test.createTestingModule({ controllers: [NotificationController], providers: [ { provide: Notifications, useValue: notifications, }, ], }).compile() notificationController = moduleRef.get(NotificationController) }) afterEach(() => { jest.clearAllMocks() }) afterAll(() => { jest.restoreAllMocks() }) describe('#processNotificationsQueue', () => { it('call to delete message on SQS and send SMS', async () => { const record = await factory.build('sqs_record') await notificationController.processNotificationsQueue(record) expect(notifications.deleteMessage).toHaveBeenCalledWith(record) expect(notifications.sendMessage).toHaveBeenCalledWith(JSON.parse(record.body)) }) }) describe('#processDeliveryReport', () => { it('call to process delivery reports', async () => { await notificationController.processDeliveryReport() expect(notifications.processNotificationReports).toHaveBeenCalled() }) }) })