import { Test, TestingModule } from '@nestjs/testing' import { datatype } from 'faker' import { PatientRepository } from '../../../repositories' import { BioimpedanceNotificationService } from '../../../services' import { Patient } from '../../../models' import { MockedModule } from '../../../../test/types' import { factory } from '../../../../test/factories' import { Notification, NOTIFICATION_TYPE_SMS } from './notification' describe('Notification', () => { let subject: Notification let bioimpedanceNotificationService: MockedModule let patientRepository: MockedModule beforeAll(async () => { bioimpedanceNotificationService = { send: jest.fn(), } patientRepository = { findByDocumentNumber: jest.fn(), getMany: jest.fn(), } const app: TestingModule = await Test.createTestingModule({ controllers: [], providers: [ { provide: BioimpedanceNotificationService, useValue: bioimpedanceNotificationService, }, { provide: PatientRepository, useValue: patientRepository, }, Notification, ], }).compile() subject = app.get(Notification) }) afterEach(() => { jest.clearAllMocks() }) afterAll(() => { jest.restoreAllMocks() }) describe('#checkPushConversion', () => { const patientIds = [datatype.uuid()] describe('when has patients', () => { let patient: Patient beforeAll(async () => { patient = await factory.build('patient') }) beforeEach(() => { patientRepository.getMany.mockResolvedValue([patient]) }) it('send notification', async () => { await subject.checkPushConversion(patientIds) patientIds.forEach(() => expect(bioimpedanceNotificationService.send).toHaveBeenCalledWith(patient, null, NOTIFICATION_TYPE_SMS), ) }) }) describe('when hasn`t patients', () => { it('does nothing', async () => { await subject.checkPushConversion([]) expect(bioimpedanceNotificationService.send).not.toHaveBeenCalled() }) }) }) })