@@ -15,7 +15,10 @@ import {
1515 type ClientKey ,
1616} from '../client/client-helper' ;
1717
18- export type UserIdentityAttributes = 'given_name' | 'family_name' | 'preferred_username' ;
18+ export type UserIdentityAttributes =
19+ | 'given_name'
20+ | 'family_name'
21+ | 'preferred_username' ;
1922
2023type TestUserStaticDetails = {
2124 userId : string ;
@@ -169,12 +172,16 @@ export class CognitoAuthHelper {
169172 }
170173
171174 if ( userCtx . refreshToken ) {
172- return ( await this . refreshUserSessionTokens ( id , userCtx . refreshToken ) )
173- . accessToken ;
175+ const refeshedTokens = await this . refreshUserSessionTokens (
176+ id ,
177+ userCtx . refreshToken
178+ ) ;
179+ return refeshedTokens . accessToken ;
174180 }
175181 }
176182
177- return ( await this . passwordAuth ( id ) ) . accessToken ;
183+ const authTokens = await this . passwordAuth ( id ) ;
184+ return authTokens . accessToken ;
178185 }
179186
180187 public async getIdToken ( id : string ) : Promise < string > {
@@ -185,11 +192,15 @@ export class CognitoAuthHelper {
185192 }
186193
187194 if ( userCtx ?. refreshToken ) {
188- return ( await this . refreshUserSessionTokens ( id , userCtx . refreshToken ) )
189- . idToken ;
195+ const refeshedTokens = await this . refreshUserSessionTokens (
196+ id ,
197+ userCtx . refreshToken
198+ ) ;
199+ return refeshedTokens . idToken ;
190200 }
191201
192- return ( await this . passwordAuth ( id ) ) . idToken ;
202+ const authTokens = await this . passwordAuth ( id ) ;
203+ return authTokens . idToken ;
193204 }
194205
195206 public async getTestUser ( id : string ) : Promise < TestUser > {
@@ -220,25 +231,28 @@ export class CognitoAuthHelper {
220231 const email = faker . internet . exampleEmail ( ) ;
221232 const tempPassword = CognitoAuthHelper . generatePassword ( ) ;
222233
223- const clientName = ( clientKey : string ) : string =>
224- `NHS Test ${ clientKey . replaceAll ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1 $2' ) } ` ;
225-
226234 const clientId = `${ userDetails . clientKey } --${ this . runId } ` ;
235+ const clientName = `NHS Test ${ userDetails . clientKey . replaceAll ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1 $2' ) } ` ;
227236
228237 const clientAttributes = [
229238 { Name : 'custom:sbx_client_id' , Value : clientId } ,
230239 {
231240 Name : 'custom:sbx_client_name' ,
232- Value : clientName ( userDetails . clientKey ) ,
241+ Value : clientName ,
233242 } ,
234243 ] ;
235244
236245 const {
237246 userId,
238- userAttributes = [ 'preferred_username' , 'given_name' , 'family_name' ] as UserIdentityAttributes [ ] ,
247+ userAttributes = [
248+ 'preferred_username' ,
249+ 'given_name' ,
250+ 'family_name' ,
251+ ] as UserIdentityAttributes [ ] ,
239252 } = userDetails ;
240253
241- const identityAttributes : Partial < Record < UserIdentityAttributes , string > > = { } ;
254+ const identityAttributes : Partial < Record < UserIdentityAttributes , string > > =
255+ { } ;
242256
243257 if ( userAttributes . includes ( 'given_name' ) )
244258 identityAttributes . given_name = 'Test' ;
@@ -284,7 +298,7 @@ export class CognitoAuthHelper {
284298 '' ,
285299 clientId : clientId ,
286300 clientKey : userDetails . clientKey ,
287- clientName : clientName ( userDetails . clientKey ) ,
301+ clientName : clientName ,
288302 identityAttributes,
289303 password : tempPassword ,
290304 }
0 commit comments