@@ -40,96 +40,136 @@ describe('Unit | Identity Access Management | Application | HttpErrorMapperConfi
4040
4141 context ( 'when mapping "DifferentExternalIdentifierError"' , function ( ) {
4242 it ( 'returns an ConflictError Http Error' , function ( ) {
43- //given
43+ // given
4444 const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
4545 ( httpErrorMapper ) => httpErrorMapper . name === DifferentExternalIdentifierError . name ,
4646 ) ;
4747
48- //when
48+ // when
4949 const error = httpErrorMapper . httpErrorFn ( new DifferentExternalIdentifierError ( ) ) ;
5050
51- //then
51+ // then
5252 expect ( error ) . to . be . instanceOf ( HttpErrors . ConflictError ) ;
5353 } ) ;
5454 } ) ;
5555
5656 context ( 'when mapping "MissingOrInvalidCredentialsError"' , function ( ) {
57- it ( 'returns an UnauthorizedError Http Error' , function ( ) {
58- //given
59- const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
60- ( httpErrorMapper ) => httpErrorMapper . name === MissingOrInvalidCredentialsError . name ,
61- ) ;
57+ context ( 'when isLoginFailureWithUsername is true' , function ( ) {
58+ it ( 'returns a UnauthorizedError with isLoginFailureWithUsername set to true' , function ( ) {
59+ // given
60+ const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
61+ ( httpErrorMapper ) => httpErrorMapper . name === MissingOrInvalidCredentialsError . name ,
62+ ) ;
63+
64+ // when
65+ const error = httpErrorMapper . httpErrorFn (
66+ new MissingOrInvalidCredentialsError ( { isLoginFailureWithUsername : true } ) ,
67+ ) ;
68+
69+ // then
70+ expect ( error ) . to . be . instanceOf ( HttpErrors . UnauthorizedError ) ;
71+ expect ( error . meta . isLoginFailureWithUsername ) . to . be . true ;
72+ } ) ;
73+ } ) ;
6274
63- //when
64- const error = httpErrorMapper . httpErrorFn ( new MissingOrInvalidCredentialsError ( ) ) ;
75+ context ( 'when isLoginFailureWithUsername is false' , function ( ) {
76+ it ( 'returns a UnauthorizedError with isLoginFailureWithUsername set to false' , function ( ) {
77+ // given
78+ const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
79+ ( httpErrorMapper ) => httpErrorMapper . name === MissingOrInvalidCredentialsError . name ,
80+ ) ;
81+
82+ // when
83+ const error = httpErrorMapper . httpErrorFn (
84+ new MissingOrInvalidCredentialsError ( { isLoginFailureWithUsername : false } ) ,
85+ ) ;
86+
87+ // then
88+ expect ( error ) . to . be . instanceOf ( HttpErrors . UnauthorizedError ) ;
89+ expect ( error . meta . isLoginFailureWithUsername ) . to . be . false ;
90+ } ) ;
91+ } ) ;
6592
66- //then
67- expect ( error ) . to . be . instanceOf ( HttpErrors . UnauthorizedError ) ;
93+ context ( 'when remainingAttempts is provided' , function ( ) {
94+ it ( 'returns a UnauthorizedError with remainingAttempts set' , function ( ) {
95+ // given
96+ const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
97+ ( httpErrorMapper ) => httpErrorMapper . name === MissingOrInvalidCredentialsError . name ,
98+ ) ;
99+ const remainingAttempts = 3 ;
100+
101+ // when
102+ const error = httpErrorMapper . httpErrorFn ( new MissingOrInvalidCredentialsError ( { remainingAttempts } ) ) ;
103+
104+ // then
105+ expect ( error ) . to . be . instanceOf ( HttpErrors . UnauthorizedError ) ;
106+ expect ( error . meta . remainingAttempts ) . to . equal ( remainingAttempts ) ;
107+ } ) ;
68108 } ) ;
69109 } ) ;
70110
71111 context ( 'when mapping "MissingUserAccountError"' , function ( ) {
72112 it ( 'returns an BadRequestError Http Error' , function ( ) {
73- //given
113+ // given
74114 const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
75115 ( httpErrorMapper ) => httpErrorMapper . name === MissingUserAccountError . name ,
76116 ) ;
77117
78- //when
118+ // when
79119 const error = httpErrorMapper . httpErrorFn ( new MissingUserAccountError ( ) ) ;
80120
81- //then
121+ // then
82122 expect ( error ) . to . be . instanceOf ( HttpErrors . BadRequestError ) ;
83123 } ) ;
84124 } ) ;
85125
86126 context ( 'when mapping "PasswordResetDemandNotFoundError"' , function ( ) {
87127 it ( 'returns a NotFoundError Http Error' , function ( ) {
88- //given
128+ // given
89129 const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
90130 ( httpErrorMapper ) => httpErrorMapper . name === PasswordResetDemandNotFoundError . name ,
91131 ) ;
92132 const message = 'Test message error' ;
93133
94- //when
134+ // when
95135 const error = httpErrorMapper . httpErrorFn ( new PasswordResetDemandNotFoundError ( message ) ) ;
96136
97- //then
137+ // then
98138 expect ( error ) . to . be . instanceOf ( HttpErrors . NotFoundError ) ;
99139 expect ( error . message ) . to . equal ( message ) ;
100140 } ) ;
101141 } ) ;
102142
103143 context ( 'when mapping "UserCantBeCreatedError"' , function ( ) {
104144 it ( 'returns an UnauthorizedError Http Error' , function ( ) {
105- //given
145+ // given
106146 const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
107147 ( httpErrorMapper ) => httpErrorMapper . name === UserCantBeCreatedError . name ,
108148 ) ;
109149 const message = 'Test message error' ;
110150
111- //when
151+ // when
112152 const error = httpErrorMapper . httpErrorFn ( new UserCantBeCreatedError ( message ) ) ;
113153
114- //then
154+ // then
115155 expect ( error ) . to . be . instanceOf ( HttpErrors . UnauthorizedError ) ;
116156 expect ( error . message ) . to . equal ( message ) ;
117157 } ) ;
118158 } ) ;
119159
120160 context ( 'when mapping "UserShouldChangePasswordError"' , function ( ) {
121161 it ( 'returns an PasswordShouldChangeError Http Error' , function ( ) {
122- //given
162+ // given
123163 const httpErrorMapper = authenticationDomainErrorMappingConfiguration . find (
124164 ( httpErrorMapper ) => httpErrorMapper . name === UserShouldChangePasswordError . name ,
125165 ) ;
126166 const message = 'Test message error' ;
127167 const meta = 'Test meta' ;
128168
129- //when
169+ // when
130170 const error = httpErrorMapper . httpErrorFn ( new UserShouldChangePasswordError ( message , meta ) ) ;
131171
132- //then
172+ // then
133173 expect ( error ) . to . be . instanceOf ( HttpErrors . PasswordShouldChangeError ) ;
134174 expect ( error . message ) . to . equal ( message ) ;
135175 expect ( error . meta ) . to . equal ( meta ) ;
0 commit comments