Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mes-9939: changes for new user service #1791

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('RekeyReasonEffects', () => {
asyncSuccess(
new HttpResponse({
status: HttpStatusCode.Ok,
statusText: 'OK',
statusText: 'User found with staff number 789',
})
)
);
Expand All @@ -98,17 +98,16 @@ describe('RekeyReasonEffects', () => {
done();
});
});
it('should return a failure action with a true payload when the staff number is not valid', (done) => {
it('should return a failure action with a true payload when the staff number is not found', (done) => {
// ARRANGE
store$.dispatch(testActions.StartTest(12345, TestCategory.B));
store$.dispatch(SetExaminerBooked(333));
store$.dispatch(SetExaminerConducted(57463524));
spyOn(findUserProvider, 'userExists').and.returnValue(
asyncError(
new HttpErrorResponse({
error: 'Error message',
status: HttpStatusCode.NotFound,
statusText: 'Not Found',
asyncSuccess(
new HttpResponse({
status: HttpStatusCode.NoContent,
statusText: null,
})
)
);
Expand Down Expand Up @@ -139,7 +138,7 @@ describe('RekeyReasonEffects', () => {
actions$.next(rekeyReasonActions.ValidateTransferRekey());
// ASSERT
effects.rekeyReasonValidateTransferEffect$.subscribe((res) => {
expect(res).toEqual(rekeyReasonActions.ValidateTransferRekeyFailed(false));
expect(res).toEqual(rekeyReasonActions.ValidateTransferRekeyFailed(true));
expect(findUserProvider.userExists).toHaveBeenCalled();
done();
});
Expand Down
15 changes: 10 additions & 5 deletions src/app/pages/rekey-reason/rekey-reason.effects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { HttpResponse, HttpStatusCode } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { TestResultCommonSchema } from '@dvsa/mes-test-schema/categories/common';
import { Actions, createEffect, ofType } from '@ngrx/effects';
Expand Down Expand Up @@ -33,10 +33,15 @@ export class RekeyReasonEffects {
}

return this.findUserProvider.userExists(test.examinerConducted).pipe(
switchMap(() => of(testActions.SendCurrentTest())),
catchError((error: HttpErrorResponse) =>
of(rekeyActions.ValidateTransferRekeyFailed(error.status === HttpStatusCode.NotFound))
)
switchMap((response: HttpResponse<any>) => {
if (response.status === HttpStatusCode.NoContent) {
// user does not exist
return of(rekeyActions.ValidateTransferRekeyFailed(true));
}
// user exists
return of(testActions.SendCurrentTest());
}),
catchError(() => of(rekeyActions.ValidateTransferRekeyFailed(true)))
);
})
)
Expand Down
Loading