From b0404780251eeb65b1571f6d7ae3812bb970ba54 Mon Sep 17 00:00:00 2001 From: andrew setterfield Date: Thu, 19 Sep 2024 15:33:34 +0100 Subject: [PATCH] correct logic for no connection --- .../__tests__/mot-card.component.spec.ts | 80 +++++++++++++++---- .../mot-card/mot-card.component.html | 8 +- .../mot-card/mot-card.component.ts | 24 ++++-- src/app/shared/models/http-status-codes.ts | 3 + 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/__tests__/mot-card.component.spec.ts b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/__tests__/mot-card.component.spec.ts index 6dd3fe800f..c05f8f9cce 100644 --- a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/__tests__/mot-card.component.spec.ts +++ b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/__tests__/mot-card.component.spec.ts @@ -30,19 +30,20 @@ describe('MotCardComponent', () => { describe('isValidMOT', () => { it('should return true if data.status is "Valid"', () => { component.data = { status: MotStatusCodes.VALID } as MotHistory; - expect(component.isValidMOT()).toBeTruthy(); + expect(component.isValidMOT()).toEqual(true); }); it('should return false if data.status is not "Valid"', () => { component.data = { status: MotStatusCodes.NOT_VALID } as MotHistory; - expect(component.isValidMOT()).toBeFalsy(); + expect(component.isValidMOT()).toEqual(false); }); }); + describe('callWasSuccessful', () => { it('should return true if status is 200, data.status is not "No details" and the app is online', () => { spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE); component.data = { status: MotStatusCodes.VALID } as MotHistory; component.status = '200'; - expect(component.callWasSuccessful()).toBeTruthy(); + expect(component.isCallWasSuccessful()).toEqual(true); }); it( 'should return false if status is not 200 or Already Saved, data.status is ' + @@ -51,66 +52,111 @@ describe('MotCardComponent', () => { spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE); component.data = { status: MotStatusCodes.VALID } as MotHistory; component.status = '100'; - expect(component.callWasSuccessful()).toBeFalsy(); + expect(component.isCallWasSuccessful()).toEqual(false); } ); it('should return false if status is 200, data.status is ' + '"No details" and the app is online', () => { spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE); component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory; component.status = '200'; - expect(component.callWasSuccessful()).toBeFalsy(); + expect(component.isCallWasSuccessful()).toBeFalsy(); }); it('should return false if status is 200, data.status is ' + 'not "No details" and the app is not online', () => { spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.OFFLINE); component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory; component.status = '200'; - expect(component.callWasSuccessful()).toBeFalsy(); + expect(component.isCallWasSuccessful()).toEqual(false); }); }); - describe('noDetails', () => { + + describe('isNoDetails', () => { it('should return true if status is NO_CONTENT', () => { component.status = HttpStatusCodes.NO_CONTENT.toString(); - expect(component.noDetails()).toBeTruthy(); + expect(component.isNoDetails()).toEqual(true); }); it('should return true if data.status is NO_DETAILS', () => { + spyOn(component, 'is404').and.returnValue(false); + spyOn(component, 'isSearchFailed').and.returnValue(false); component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory; - expect(component.noDetails()).toBeTruthy(); + expect(component.isNoDetails()).toEqual(true); }); it('should return true if data.status is AGE_EXEMPTION', () => { + spyOn(component, 'is404').and.returnValue(false); + spyOn(component, 'isSearchFailed').and.returnValue(false); component.data = { status: MotStatusCodes.AGE_EXEMPTION } as MotHistory; - expect(component.noDetails()).toBeTruthy(); + expect(component.isNoDetails()).toEqual(true); }); it('should return false if status and data.status do not match NO_CONTENT, NO_DETAILS, or AGE_EXEMPTION', () => { + spyOn(component, 'is404').and.returnValue(false); + spyOn(component, 'isSearchFailed').and.returnValue(false); component.status = HttpStatusCodes.OK.toString(); component.data = { status: MotStatusCodes.VALID } as MotHistory; - expect(component.noDetails()).toBeFalsy(); + expect(component.isNoDetails()).toEqual(false); + }); + + it('should return true if status is equal to 404', () => { + spyOn(component, 'is404').and.returnValue(true); + spyOn(component, 'isSearchFailed').and.returnValue(false); + component.status = HttpStatusCodes.NOT_FOUND.toString(); + component.data = { status: MotStatusCodes.VALID } as MotHistory; + expect(component.isNoDetails()).toEqual(true); + }); + + it('should return true if searchFailed', () => { + spyOn(component, 'is404').and.returnValue(false); + spyOn(component, 'isSearchFailed').and.returnValue(true); + component.status = HttpStatusCodes.NOT_FOUND.toString(); + component.data = { status: MotStatusCodes.VALID } as MotHistory; + expect(component.isNoDetails()).toEqual(false); }); }); + describe('is404', () => { it('should return true if status is NOT_FOUND', () => { component.status = HttpStatusCodes.NOT_FOUND.toString(); - expect(component.is404()).toBeTruthy(); + expect(component.is404()).toEqual(true); }); it('should return false if status is not NOT_FOUND', () => { component.status = HttpStatusCodes.OK.toString(); - expect(component.is404()).toBeFalsy(); + expect(component.is404()).toEqual(false); }); }); - describe('searchFailed', () => { + describe('isSearchFailed', () => { it('should return true if status is UNDEFINED', () => { component.status = HttpStatusCodes.UNDEFINED.toString(); - expect(component.searchFailed()).toBeTruthy(); + expect(component.isSearchFailed()).toEqual(true); + }); + + it('should return true if status is INTERNAL_SERVER_ERROR', () => { + component.status = HttpStatusCodes.INTERNAL_SERVER_ERROR.toString(); + expect(component.isSearchFailed()).toEqual(true); + }); + + it('should return true if status is BAD_GATEWAY', () => { + component.status = HttpStatusCodes.BAD_GATEWAY.toString(); + expect(component.isSearchFailed()).toEqual(true); }); - it('should return false if status is not UNDEFINED', () => { + it('should return true if status is SERVICE_UNAVAILABLE', () => { + component.status = HttpStatusCodes.SERVICE_UNAVAILABLE.toString(); + expect(component.isSearchFailed()).toEqual(true); + }); + + it('should return true if status is GATEWAY_TIMEOUT', () => { + component.status = HttpStatusCodes.GATEWAY_TIMEOUT.toString(); + expect(component.isSearchFailed()).toEqual(true); + }); + + it('should return false if status is a listed status code', () => { component.status = HttpStatusCodes.OK.toString(); - expect(component.searchFailed()).toBeFalsy(); + expect(component.isSearchFailed()).toEqual(false); }); }); + describe('evidenceRadioSelected', () => { it('should emit the passed value and set alternateEvidenceRadioCheck to its value', () => { component.alternateEvidenceRadioCheck = false; diff --git a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.html b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.html index 7d820a487c..dd55af8721 100644 --- a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.html +++ b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.html @@ -1,4 +1,4 @@ -
+
@@ -34,15 +34,15 @@ [formGroup]="formGroup" >
-
+
- Unable to determine MOT status. - Unable to connect. This feature is not available. + Unable to determine MOT status. + Unable to connect. This feature is not available.
diff --git a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.ts b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.ts index 5eb95610f9..82bc740d47 100644 --- a/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.ts +++ b/src/app/pages/waiting-room-to-car/components/mot-components/mot-card/mot-card.component.ts @@ -28,7 +28,7 @@ export class MotCardComponent { constructor(public networkState: NetworkStateProvider) {} - callWasSuccessful() { + isCallWasSuccessful(): boolean { return ( (+this.status === HttpStatusCodes.OK || this.status === 'Already Saved') && this?.data?.status !== MotStatusCodes.NO_DETAILS && @@ -36,11 +36,13 @@ export class MotCardComponent { ); } - noDetails(): boolean { + isNoDetails(): boolean { return ( - +this.status === HttpStatusCodes.NO_CONTENT || - this.data?.status === MotStatusCodes.NO_DETAILS || - this?.data?.status === MotStatusCodes.AGE_EXEMPTION + !this.isSearchFailed() && + (+this.status === HttpStatusCodes.NO_CONTENT || + this.data?.status === MotStatusCodes.NO_DETAILS || + this?.data?.status === MotStatusCodes.AGE_EXEMPTION || + this.is404()) ); } @@ -48,7 +50,7 @@ export class MotCardComponent { return +this.status === HttpStatusCodes.NOT_FOUND; } - isValidMOT() { + isValidMOT(): boolean { return this.data.status === MotStatusCodes.VALID; } @@ -57,7 +59,13 @@ export class MotCardComponent { this.alternateEvidenceChange.emit(event); } - searchFailed() { - return +this.status === HttpStatusCodes.UNDEFINED; + isSearchFailed() { + return ( + +this.status === HttpStatusCodes.UNDEFINED || + +this.status === HttpStatusCodes.INTERNAL_SERVER_ERROR || + +this.status === HttpStatusCodes.BAD_GATEWAY || + +this.status === HttpStatusCodes.SERVICE_UNAVAILABLE || + +this.status === HttpStatusCodes.GATEWAY_TIMEOUT + ); } } diff --git a/src/app/shared/models/http-status-codes.ts b/src/app/shared/models/http-status-codes.ts index 4de2d05069..a97c869e4e 100644 --- a/src/app/shared/models/http-status-codes.ts +++ b/src/app/shared/models/http-status-codes.ts @@ -13,4 +13,7 @@ export enum HttpStatusCodes { CONFLICT = 409, UNPROCESSABLE_ENTITY = 422, INTERNAL_SERVER_ERROR = 500, + BAD_GATEWAY = 502, + SERVICE_UNAVAILABLE = 503, + GATEWAY_TIMEOUT = 504, }