import 'reflect-metadata' ; import { AzureServicesIocTypes , CredentialsProvider , CredentialType , SecretProvider } from 'azure-services' ; import { ServiceConfiguration } from 'common' ; import * as inversify from 'inversify' ; import { GlobalLogger } from 'logger' ; import { IMock , Mock } from 'typemoq' ; import { A11yServiceClientProvider , a11yServiceClientTypeNames } from 'web-api-client' ; import { getProcessLifeCycleContainer } from './get-process-life-cycle-container' ; describe ( getProcessLifeCycleContainer , ( ) => { let testSubject ; let secretProviderMock ; beforeEach ( ( ) => { testSubject = getProcessLifeCycleContainer ( ) ; secretProviderMock = Mock . ofType ( SecretProvider ) ; testSubject . unbind ( SecretProvider ) ; testSubject . bind ( SecretProvider ) . toConstantValue ( secretProviderMock . object ) ; } ) ; it ( 'verifies dependencies resolution' , ( ) => { expect ( testSubject . get ( ServiceConfiguration ) ) . toBeDefined ( ) ; expect ( testSubject . get ( GlobalLogger ) ) . toBeDefined ( ) ; expect ( testSubject . get ( CredentialsProvider ) ) . toBeDefined ( ) ; expect ( testSubject . get ( SecretProvider ) ) . toBeDefined ( ) ; expect ( testSubject . get ( CredentialsProvider ) ) . toBeDefined ( ) ; } ) ; it ( 'verifies A11yServiceClient registration' , async ( ) => { secretProviderMock . setup ( async ( s ) => s . getSecret ( 'restApiSpAppId' ) ) . returns ( async ( ) => Promise . resolve ( 'sp app id' ) ) . verifiable ( ) ; secretProviderMock . setup ( async ( s ) => s . getSecret ( 'restApiSpSecret' ) ) . returns ( async ( ) => Promise . resolve ( 'sp app secret' ) ) . verifiable ( ) ; secretProviderMock . setup ( async ( s ) => s . getSecret ( 'authorityUrl' ) ) . returns ( async ( ) => Promise . resolve ( 'https://login.microsoft.com/tenantid' ) ) . verifiable ( ) ; const a11yServiceClientProvider1 = testSubject . get < A11yServiceClientProvider > ( a11yServiceClientTypeNames . A11yServiceClientProvider ) ; const a11yServiceClientProvider2 = testSubject . get < A11yServiceClientProvider > ( a11yServiceClientTypeNames . A11yServiceClientProvider ) ; await expect ( a11yServiceClientProvider1 ( ) ) . resolves . toBeDefined ( ) ; expect ( await a11yServiceClientProvider1 ( ) ) . toBe ( await a11yServiceClientProvider2 ( ) ) ; secretProviderMock . verifyAll ( ) ; } ) ; it ( 'should not create more than one instance of container' , ( ) => { expect ( getProcessLifeCycleContainer ( ) ) . toBe ( testSubject ) ; } ) ; it ( 'verifies credential type to be app service' , ( ) => { expect ( testSubject . get ( AzureServicesIocTypes . CredentialType ) ) . toBe ( CredentialType . AppService ) ; } ) ; } ) ;