import { Test, TestingModule } from '@nestjs/testing' import { datatype } from 'faker' import { BioimpedanceService } from '../../../services' import { Importation, Notification } from '../domain' import { ImportationErrors } from '../types' import { BioimpedancesController } from './bioimpedances.controller' describe('BioimpedancesController', () => { let spy: any let bioimpedancesController: BioimpedancesController const result = { rowsWithError: {} } const importation = { importBioimpedances: async (_userId: string, _filePath: string): Promise => result, } const bioimpedanceService = { createPatientAnthropometriesCache: jest.fn(), } const notification = { sendNotificatonForBioImports: jest.fn(), scheduleCheckPushConversion: jest.fn(), checkPushConversion: jest.fn(), } beforeEach(async () => { const app: TestingModule = await Test.createTestingModule({ controllers: [BioimpedancesController], providers: [ { provide: Importation, useValue: importation, }, { provide: BioimpedanceService, useValue: bioimpedanceService, }, { provide: Notification, useValue: notification, }, ], }).compile() bioimpedancesController = app.get(BioimpedancesController) }) describe('.import', () => { const params = { input: { file_path: 'bio.csv', users: [datatype.uuid()], smartfit_unit: datatype.uuid() }, session_variables: { 'x-hasura-user-id': '43434', 'x-hasura-role': 'user' }, } it('call bioimpedances importation with correct params', async () => { spy = jest.spyOn(importation, 'importBioimpedances') await bioimpedancesController.import(params) expect(spy).toHaveBeenCalledWith({ filePath: params.input.file_path, smartfitUnitId: params.input.smartfit_unit, userId: params.session_variables['x-hasura-user-id'], users: params.input.users, }) }) }) describe('Check push conversion', () => { const params = { payload: { patient_ids: ['1', '2'] }, headers: [], version: '', } it('call check push conversion', async () => { spy = jest.spyOn(notification, 'checkPushConversion') await bioimpedancesController.checkPushConversion(params) expect(spy).toHaveBeenCalledWith(params.payload.patient_ids) }) }) })