import * as _ from 'lodash' ; import { EidasAttributes } from '@fc/eidas' ; import { ClaimsToAttributesMap } from './oidc-to-eidas.mapper' ; describe ( 'OidcToEidasMapper' , ( ) => { describe ( 'ClaimsToAttributesMap' , ( ) => { const claims = { sub : '57770c28716497d912e64399024b0d70acd9f7e325198f04df29ce0d0572d50fv2' , gender : 'female' , birthdate : '1962-08-24' , birthcountry : '99100' , birthplace : '75107' , given_name : 'Angela Claire Louise' , family_name : 'DUBOIS' , email : 'wossewodda-3728@yopmail.com' , preferred_username : 'DUMEUBLE' , } ; describe ( 'getPersonIdentifier' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . PERSON_IDENTIFIER ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the sub within claims in an array' , ( ) => { const expected = [ claims . sub ] ; const result = ClaimsToAttributesMap [ EidasAttributes . PERSON_IDENTIFIER ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getCurrentGivenName' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . CURRENT_GIVEN_NAME ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the given_name within claims splited by space' , ( ) => { const expected = claims . given_name . split ( ' ' ) ; const result = ClaimsToAttributesMap [ EidasAttributes . CURRENT_GIVEN_NAME ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getCurrentFamilyName' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . CURRENT_FAMILY_NAME ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the preferred_username within claims as an Array if present' , ( ) => { const expected = [ claims . preferred_username ] ; const result = ClaimsToAttributesMap [ EidasAttributes . CURRENT_FAMILY_NAME ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; it ( 'should return the family_name within claims as an Array if preferred_username is not present' , ( ) => { const claimsWithoutPreferredUsername = { ... claims , preferred_username : undefined , } ; const expected = [ claims . family_name ] ; const result = ClaimsToAttributesMap [ EidasAttributes . CURRENT_FAMILY_NAME ] ( claimsWithoutPreferredUsername ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getBirthName' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . BIRTH_NAME ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the family_name within claims as an Array' , ( ) => { const expected = [ claims . family_name ] ; const result = ClaimsToAttributesMap [ EidasAttributes . BIRTH_NAME ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getDateOfBirth' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . DATE_OF_BIRTH ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the birthdate within claims as an Array' , ( ) => { const expected = [ claims . birthdate ] ; const result = ClaimsToAttributesMap [ EidasAttributes . DATE_OF_BIRTH ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; it ( 'should return the birthdate within claims as an Array replacing the "-00" for presumed born day by "-01"' , ( ) => { const claimsPresumedBornDay = { sub : '57770c28716497d912e64399024b0d70acd9f7e325198f04df29ce0d0572d50fv2' , gender : 'female' , birthdate : '1962-08-00' , birthcountry : '99100' , birthplace : '75107' , given_name : 'Angela Claire Louise' , family_name : 'DUBOIS' , email : 'wossewodda-3728@yopmail.com' , preferred_username : 'DUMEUBLE' , } ; const expected = [ '1962-08-01' ] ; const result = ClaimsToAttributesMap [ EidasAttributes . DATE_OF_BIRTH ] ( claimsPresumedBornDay ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; it ( 'should return the birthdate within claims as an Array replacing the "-00" for presumed born day and month by "-01"' , ( ) => { const claimsPresumedBornDayMonth = { sub : '57770c28716497d912e64399024b0d70acd9f7e325198f04df29ce0d0572d50fv2' , gender : 'female' , birthdate : '1962-00-00' , birthcountry : '99100' , birthplace : '75107' , given_name : 'Angela Claire Louise' , family_name : 'DUBOIS' , email : 'wossewodda-3728@yopmail.com' , preferred_username : 'DUMEUBLE' , } ; const expected = [ '1962-01-01' ] ; const result = ClaimsToAttributesMap [ EidasAttributes . DATE_OF_BIRTH ] ( claimsPresumedBornDayMonth ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; it ( 'should return undefined as an Array if there is no birthdate within the claims' , ( ) => { const claimsPresumedBornDayMonth = { sub : '57770c28716497d912e64399024b0d70acd9f7e325198f04df29ce0d0572d50fv2' , gender : 'female' , birthcountry : '99100' , birthplace : '75107' , given_name : 'Angela Claire Louise' , family_name : 'DUBOIS' , email : 'wossewodda-3728@yopmail.com' , preferred_username : 'DUMEUBLE' , } ; const expected = [ undefined ] ; const result = ClaimsToAttributesMap [ EidasAttributes . DATE_OF_BIRTH ] ( claimsPresumedBornDayMonth ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getPlaceOfBirth' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . PLACE_OF_BIRTH ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the birthplace within claims as an Array' , ( ) => { const expected = [ claims . birthplace ] ; const result = ClaimsToAttributesMap [ EidasAttributes . PLACE_OF_BIRTH ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; it ( 'should return the birthcopuntry within claims as an Array if there is no birthplace within claims ' , ( ) => { const claimsWithoutBirthplace = { sub : '57770c28716497d912e64399024b0d70acd9f7e325198f04df29ce0d0572d50fv2' , gender : 'female' , birthdate : '1962-08-24' , birthcountry : '99217' , given_name : 'Angela Claire Louise' , family_name : 'DUBOIS' , email : 'wossewodda-3728@yopmail.com' , preferred_username : 'DUMEUBLE' , } ; const expected = [ claimsWithoutBirthplace . birthcountry ] ; const result = ClaimsToAttributesMap [ EidasAttributes . PLACE_OF_BIRTH ] ( claimsWithoutBirthplace ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; describe ( 'getGender' , ( ) => { it ( 'should be a function' , ( ) => { expect ( ClaimsToAttributesMap [ EidasAttributes . GENDER ] ) . toBeInstanceOf ( Function ) ; } ) ; it ( 'should return the gender within claims with first letter uppercase as an Array' , ( ) => { const expected = [ _ . upperFirst ( claims . gender ) ] ; const result = ClaimsToAttributesMap [ EidasAttributes . GENDER ] ( claims ) ; expect ( result ) . toStrictEqual ( expected ) ; } ) ; } ) ; } ) ; } ) ;