import { Test , TestingModule } from '@nestjs/testing' ; import { LoggerService } from '@fc/logger' ; import { ISessionService } from '@fc/session' ; import { AppSession , AuthorizeParamsDto } from '../dto' ; import { OidcProviderController } from './oidc-provider.controller' ; const loggerServiceMock = { setContext : jest . fn ( ) , trace : jest . fn ( ) , } as unknown as LoggerService ; describe ( 'OidcProviderController' , ( ) => { let oidcProviderController ; const appSessionServiceMock = { set : jest . fn ( ) , } as unknown as ISessionService < AppSession > ; beforeEach ( async ( ) => { const app = await Test . createTestingModule ( { controllers : [ OidcProviderController ] , providers : [ LoggerService ] , } ) . overrideProvider ( LoggerService ) . useValue ( loggerServiceMock ) . compile ( ) ; oidcProviderController = await app . get < OidcProviderController > ( OidcProviderController ) ; jest . resetAllMocks ( ) ; } ) ; describe ( 'getAuthorize()' , ( ) => { it ( 'should set the finalSpId into the session' , async ( ) => { const nextMock = jest . fn ( ) ; const queryMock = { sp_id : 'abcdefghijklmnopqrstuvwxyz0123456789' , } as AuthorizeParamsDto ; await oidcProviderController . getAuthorize ( nextMock , queryMock , appSessionServiceMock ) ; expect ( appSessionServiceMock . set ) . toHaveBeenCalledTimes ( 1 ) ; expect ( appSessionServiceMock . set ) . toHaveBeenCalledWith ( 'finalSpId' , queryMock . sp_id ) ; } ) ; it ( 'should call next' , async ( ) => { const nextMock = jest . fn ( ) ; const queryMock = { } as AuthorizeParamsDto ; await oidcProviderController . getAuthorize ( nextMock , queryMock , appSessionServiceMock ) ; expect ( nextMock ) . toHaveReturnedTimes ( 1 ) ; } ) ; } ) ; describe ( 'postAuthorize()' , ( ) => { it ( 'should call next' , ( ) => { const nextMock = jest . fn ( ) ; const bodyMock = { } as AuthorizeParamsDto ; oidcProviderController . postAuthorize ( nextMock , bodyMock ) ; expect ( nextMock ) . toHaveReturnedTimes ( 1 ) ; } ) ; } ) ; describe ( 'postToken()' , ( ) => { it ( 'should call next' , ( ) => { const nextMock = jest . fn ( ) ; const bodyMock = { } as AuthorizeParamsDto ; oidcProviderController . postToken ( nextMock , bodyMock ) ; expect ( nextMock ) . toHaveReturnedTimes ( 1 ) ; } ) ; it ( 'should call logger.trace' , ( ) => { const nextMock = jest . fn ( ) ; const bodyMock = { } as AuthorizeParamsDto ; oidcProviderController . postToken ( nextMock , bodyMock ) ; expect ( loggerServiceMock . trace ) . toHaveBeenCalledTimes ( 1 ) ; } ) ; } ) ; } ) ;