import { Test , TestingModule } from '@nestjs/testing' ; import { LoggerService } from '@fc/logger' ; import { CsmrTracksService } from '../services/csmr-tracks.service' ; import { CsmrTracksController } from './csmr-tracks.controller' ; describe ( 'CsmrTracksController' , ( ) => { let controller ; const loggerMock = { debug : jest . fn ( ) , trace : jest . fn ( ) , setContext : jest . fn ( ) , } ; const csmrTracksMock = { getList : jest . fn ( ) , } ; const payloadMock = { pattern : 'SOME_PATTERN' , data : { } , } ; beforeEach ( async ( ) => { const app = await Test . createTestingModule ( { controllers : [ CsmrTracksController ] , providers : [ LoggerService , CsmrTracksService ] , } ) . overrideProvider ( LoggerService ) . useValue ( loggerMock ) . overrideProvider ( CsmrTracksService ) . useValue ( csmrTracksMock ) . compile ( ) ; controller = app . get < CsmrTracksController > ( CsmrTracksController ) ; } ) ; describe ( 'getTracks()' , ( ) => { it ( 'Should return result of CsmrTracksService.getList()' , async ( ) => { const expected = 'some string' ; csmrTracksMock . getList . mockResolvedValueOnce ( expected ) ; const result = await controller . getTracks ( payloadMock ) ; expect ( result ) . toEqual ( expected ) ; } ) ; it ( 'Should return an empty array if an error is throwed by csmrTracks.getList()' , async ( ) => { csmrTracksMock . getList . mockImplementationOnce ( ( ) => { throw new Error ( ) ; } ) ; const result = await controller . getTracks ( payloadMock ) ; expect ( result ) . toEqual ( [ ] ) ; } ) ; } ) ; } ) ;