import { Test , TestingModule } from '@nestjs/testing' ; import { ScopesService } from './scopes.service' ; describe ( 'ScopesService' , ( ) => { let service ; beforeEach ( async ( ) => { const module = await Test . createTestingModule ( { providers : [ ScopesService ] , } ) . compile ( ) ; service = module . get < ScopesService > ( ScopesService ) ; } ) ; describe ( 'mapScopesToLabel' , ( ) => { TODO see https it ( 'should return labels for scopes' , async ( ) => { const scopesParamMock = [ 'openid' , 'email' , 'address' , 'phone' , 'birthcountry' , 'birthplace' , 'birthdate' , 'given_name' , 'family_name' , 'gender' , 'preferred_username' , ] ; const resultsMock = [ 'Adresse email' , 'Adresse postale' , 'Pays de naissance' , 'Lieu de naissance' , 'Date de naissance' , 'Prénom(s)' , 'Nom de naissance' , 'Sexe' , "Nom d'usage" , 'Téléphone' , ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return labels for profile scope' , async ( ) => { const scopesParamMock = [ 'profile' ] ; const resultsMock = [ 'Prénom(s)' , 'Nom de naissance' , 'Date de naissance' , 'Sexe' , "Nom d'usage" , ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return labels for identite_pivot scope' , async ( ) => { const scopesParamMock = [ 'identite_pivot' ] ; const resultsMock = [ 'Prénom(s)' , 'Nom de naissance' , 'Date de naissance' , 'Sexe' , 'Lieu de naissance' , 'Pays de naissance' , ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return labels for birth scope' , async ( ) => { const scopesParamMock = [ 'birth' ] ; const resultsMock = [ 'Lieu de naissance' , 'Pays de naissance' ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( "should return scope if scope label doesn't exist" , async ( ) => { const scopesParamMock = [ 'foo' ] ; const resultsMock = [ 'foo' ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return empty labels if array is empty' , async ( ) => { const scopesParamMock = [ ] ; const resultsMock = [ ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return empty label if array is undefined' , async ( ) => { const scopesParamMock = undefined ; const resultsMock = [ ] ; const results = await service . mapScopesToLabel ( scopesParamMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return labels if scopes are string not array' , async ( ) => { const scopesParamMock = 'openid gender family_name' as any ; const errorMessage = 'Scopes must be Array and not string' ; try { await service . mapScopesToLabel ( scopesParamMock ) ; } catch ( error ) { expect ( error ) . toBeInstanceOf ( Error ) ; expect ( error . message ) . toEqual ( errorMessage ) ; } } ) ; it ( 'should return no void labels for scopes with openid, given_name and profile' , async ( ) => { const queryMock = [ 'openid' , 'given_name' , 'profile' ] ; const resultsMock = [ 'Prénom(s)' , 'Nom de naissance' , 'Date de naissance' , 'Sexe' , "Nom d'usage" , ] ; const results = await service . mapScopesToLabel ( queryMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; describe ( '(duplicate)' , ( ) => { it ( 'should return labels once for duplicate scopes' , async ( ) => { const queryMock = [ 'gender' , 'gender' , 'gender' ] ; const resultsMock = [ 'Sexe' ] ; const results = await service . mapScopesToLabel ( queryMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; it ( 'should return labels once for duplicate scopes with profile' , async ( ) => { const queryMock = [ 'gender' , 'profile' ] ; const resultsMock = [ 'Sexe' , 'Prénom(s)' , 'Nom de naissance' , 'Date de naissance' , "Nom d'usage" , ] ; const results = await service . mapScopesToLabel ( queryMock ) ; expect ( results ) . toEqual ( resultsMock ) ; } ) ; } ) ; } ) ; describe ( 'getClaimsFromScopes' , ( ) => { it ( 'should return mapped claims for scope' , ( ) => { const scopesMock = [ 'openid' , 'phone' ] ; const result = service . getClaimsFromScopes ( scopesMock ) ; expect ( result ) . toEqual ( [ 'sub' , 'phone_number' ] ) ; } ) ; it ( 'should return given input if key is not in map' , ( ) => { const scopesMock = [ 'openid' , 'phone' , 'foo' ] ; const result = service . getClaimsFromScopes ( scopesMock ) ; expect ( result ) . toEqual ( [ 'sub' , 'phone_number' , 'foo' ] ) ; } ) ; } ) ; } ) ;