From 5817fc9e919b6e65f6cce035d7c7c686163569be Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Mon, 14 Oct 2024 11:04:04 +0100 Subject: [PATCH 1/7] feat(CB2-14255): Remove error throwing to continue when retriving trn data --- src/trailer/TrailerRepository.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trailer/TrailerRepository.ts b/src/trailer/TrailerRepository.ts index b7c06e0..805939b 100644 --- a/src/trailer/TrailerRepository.ts +++ b/src/trailer/TrailerRepository.ts @@ -20,7 +20,10 @@ export class TrailerRepository { * @param make The make of the trailer * @returns A payload containing the TRN of the trailer and a boolean. */ - public async getTrailerRegistrationObject(vin: string, make: string): Promise { + public async getTrailerRegistrationObject( + vin: string, + make: string + ): Promise { const config: IInvokeConfig = this.config.getInvokeConfig(); const invokeParams: InvocationRequest = { FunctionName: config.functions.trailerRegistration.name, @@ -56,7 +59,6 @@ export class TrailerRepository { return { Trn: trailerRegistration.trn, IsTrailer: true }; } catch (err) { console.error(`Error on fetching vinOrChassisWithMake ${vin + make}`, err); - throw err; } } } From 07cd7a125ac850d85e085ccf66b14e31245b587a Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Mon, 14 Oct 2024 12:53:23 +0100 Subject: [PATCH 2/7] feat(CB2-14255): validation on make --- src/certificate/commands/MakeAndModelCommand.ts | 2 ++ src/test-result/TestResultService.ts | 2 +- src/trailer/TrailerRepository.ts | 6 ++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/certificate/commands/MakeAndModelCommand.ts b/src/certificate/commands/MakeAndModelCommand.ts index ddc12f3..64b6b87 100644 --- a/src/certificate/commands/MakeAndModelCommand.ts +++ b/src/certificate/commands/MakeAndModelCommand.ts @@ -61,6 +61,8 @@ export class MakeAndModelCommand extends BasePayloadCommand { const isValidForTrn = this.testResultService.isValidForTrn(vehicleType, makeAndModel); if (isValidForTrn) { return await this.trailerRepository.getTrailerRegistrationObject(testResult.vin, makeAndModel.Make); + } else { + console.log('Vehicle is not valid for Trn.'); } return undefined; diff --git a/src/test-result/TestResultService.ts b/src/test-result/TestResultService.ts index 6f9bfd4..643b916 100644 --- a/src/test-result/TestResultService.ts +++ b/src/test-result/TestResultService.ts @@ -70,7 +70,7 @@ export class TestResultService { * @returns returns if the condition is satisfied else false */ public isValidForTrn(vehicleType: string, makeAndModel: IMakeAndModel): boolean { - return makeAndModel && vehicleType === VEHICLE_TYPES.TRL; + return makeAndModel && !!makeAndModel.Make && vehicleType === VEHICLE_TYPES.TRL; } /** diff --git a/src/trailer/TrailerRepository.ts b/src/trailer/TrailerRepository.ts index 805939b..b7c06e0 100644 --- a/src/trailer/TrailerRepository.ts +++ b/src/trailer/TrailerRepository.ts @@ -20,10 +20,7 @@ export class TrailerRepository { * @param make The make of the trailer * @returns A payload containing the TRN of the trailer and a boolean. */ - public async getTrailerRegistrationObject( - vin: string, - make: string - ): Promise { + public async getTrailerRegistrationObject(vin: string, make: string): Promise { const config: IInvokeConfig = this.config.getInvokeConfig(); const invokeParams: InvocationRequest = { FunctionName: config.functions.trailerRegistration.name, @@ -59,6 +56,7 @@ export class TrailerRepository { return { Trn: trailerRegistration.trn, IsTrailer: true }; } catch (err) { console.error(`Error on fetching vinOrChassisWithMake ${vin + make}`, err); + throw err; } } } From 7a68bb5801de7716ff66af485e91d4361f1aa891 Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Mon, 14 Oct 2024 13:04:38 +0100 Subject: [PATCH 3/7] feat(CB2-14255): validation on make --- tests/resources/queue-event-fail.json | 2 +- tests/unit/certGen.unitTest.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/resources/queue-event-fail.json b/tests/resources/queue-event-fail.json index 9f46b4a..2c56b87 100644 --- a/tests/resources/queue-event-fail.json +++ b/tests/resources/queue-event-fail.json @@ -23,7 +23,7 @@ { "messageId": "g48c54a0-7027-4e37-b7e8-c8d231511c680", "receiptHandle": "AQEBJcBvTRZ1W2LSaUJ0g0ELXlqA8WCL4zJxO63wu0YOVhx44xxxPhsnc+/Q9+1vOPYO+3HupEjXzGRSvfPY5rEEJkgCJe4/RQ+q2kU5LsmJEr1qE/CTdIYe5X/75XeMQ523KKpdNsD9tRhyvEpPpSu50byGbz7J0JyR6lu1E6Q4YuB4QNm+ev1obPMLdEt8RhgvIi/NfEfQf0L1r3TPi3wLho1R61PllPm27He8/1CjCnMyWBzgX+DCjJ7vyRXObMZ/MbhMBKbYpeTcejsKpYX//PPr1yvldp1YPC0wPKp+iqmWxoDDeHXbo8xYRFXDA8rnY5RfkwxxffH7o534vYn8FCZEtqybQuo7pumu6Ah9PsC05tP38syU71ltasljGIA35BgCdSO+9r5rTaBnbO9++Q==", - "body": "{\"testerStaffId\":\"1\",\"testStartTimestamp\":\"2019-02-26T14:50:44.279Z\",\"odometerReadingUnits\":\"kilometres\",\"testEndTimestamp\":\"2019-02-26T15:02:10.761Z\",\"testStatus\":\"submitted\",\"testTypes\":{\"testNumber\":\"W01A00310\",\"prohibitionIssued\":false,\"testCode\":\"ffv2\",\"lastUpdatedAt\":\"2019-02-26T15:29:39.537Z\",\"testAnniversaryDate\":\"2019-12-26T15:29:40.032Z\",\"numberOfSeatbeltsFitted\":2,\"testTypeEndTimestamp\":\"2019-02-26T15:02:37.392Z\",\"lastSeatbeltInstallationCheckDate\":\"2019-02-26\",\"createdAt\":\"2019-02-26T15:29:39.537Z\",\"testExpiryDate\":\"2020-02-25T15:29:40.032Z\",\"testTypeId\":\"1\",\"testTypeStartTimestamp\":\"2019-02-26T14:51:54.180Z\",\"certificateNumber\":\"321\",\"seatbeltInstallationCheckDate\":true,\"testTypeName\":\"Annual test\",\"defects\":[{\"deficiencyCategory\":\"dangerous\",\"deficiencyText\":\"not working correctly and obviously affects steering control.\",\"prs\":false,\"additionalInformation\":{\"notes\":\"Asdasd\",\"location\":{\"axleNumber\":7,\"horizontal\":\"inner\",\"lateral\":\"offside\"}},\"deficiencyRef\":\"54.1.a.ii\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":\"ii\",\"deficiencyId\":\"a\",\"imDescription\":\"Steering\",\"itemDescription\":\"Power steering:\",\"imNumber\":54},{\"deficiencyCategory\":\"minor\",\"deficiencyText\":\"reservoir is below minimum level.\",\"prs\":false,\"additionalInformation\":{\"location\":{\"axleNumber\":7,\"horizontal\":\"outer\",\"lateral\":\"nearside\"}},\"deficiencyRef\":\"54.1.d.i\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":\"i\",\"deficiencyId\":\"d\",\"imDescription\":\"Steering\",\"itemDescription\":\"Power steering:\",\"imNumber\":54},{\"deficiencyCategory\":\"advisory\",\"deficiencyText\":\"null\",\"prs\":false,\"additionalInformation\":{\"notes\":\"Dasdasdccc\",\"location\":{}},\"deficiencyRef\":\"5.1\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":null,\"deficiencyId\":null,\"imDescription\":\"Exhaust Emissions\",\"itemDescription\":\"Compression Ignition Engines Statutory Smoke Meter Test:\",\"imNumber\":5}],\"name\":\"Annual test\",\"testResult\":\"fail\"},\"vehicleClass\":{\"code\":\"t\",\"description\":\"trailer\"},\"testResultId\":\"1\",\"vehicleSize\":\"small\",\"vin\":\"T12876765\",\"testStationName\":\"Abshire-Kub\",\"vehicleId\":\"C456789\",\"countryOfRegistration\":\"gb\",\"vehicleType\":\"trl\",\"preparerId\":\"AK4434\",\"preparerName\":\"Durrell Vehicles Limited\",\"odometerReading\":12312,\"vehicleConfiguration\":\"rigid\",\"testStationType\":\"gvts\",\"testerName\":\"CVS Dev1\",\"vrm\":\"C456789\",\"testStationPNumber\":\"09-4129632\",\"numberOfSeats\":50,\"testerEmailAddress\":\"cvs.dev1@dvsagov.onmicrosoft.com\",\"euVehicleCategory\":\"m1\",\"order\":{\"current\":2,\"total\":2}}", + "body": "{\"testerStaffId\":\"1\",\"testStartTimestamp\":\"2019-02-26T14:50:44.279Z\",\"odometerReadingUnits\":\"kilometres\",\"testEndTimestamp\":\"2019-02-26T15:02:10.761Z\",\"testStatus\":\"submitted\",\"testTypes\":{\"testNumber\":\"W01A00310\",\"prohibitionIssued\":false,\"testCode\":\"ffv2\",\"lastUpdatedAt\":\"2019-02-26T15:29:39.537Z\",\"testAnniversaryDate\":\"2019-12-26T15:29:40.032Z\",\"numberOfSeatbeltsFitted\":2,\"testTypeEndTimestamp\":\"2019-02-26T15:02:37.392Z\",\"lastSeatbeltInstallationCheckDate\":\"2019-02-26\",\"createdAt\":\"2019-02-26T15:29:39.537Z\",\"testExpiryDate\":\"2020-02-25T15:29:40.032Z\",\"testTypeId\":\"1\",\"testTypeStartTimestamp\":\"2019-02-26T14:51:54.180Z\",\"certificateNumber\":\"321\",\"seatbeltInstallationCheckDate\":true,\"testTypeName\":\"Annual test\",\"defects\":[{\"deficiencyCategory\":\"dangerous\",\"deficiencyText\":\"not working correctly and obviously affects steering control.\",\"prs\":false,\"additionalInformation\":{\"notes\":\"Asdasd\",\"location\":{\"axleNumber\":7,\"horizontal\":\"inner\",\"lateral\":\"offside\"}},\"deficiencyRef\":\"54.1.a.ii\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":\"ii\",\"deficiencyId\":\"a\",\"imDescription\":\"Steering\",\"itemDescription\":\"Power steering:\",\"imNumber\":54},{\"deficiencyCategory\":\"minor\",\"deficiencyText\":\"reservoir is below minimum level.\",\"prs\":false,\"additionalInformation\":{\"location\":{\"axleNumber\":7,\"horizontal\":\"outer\",\"lateral\":\"nearside\"}},\"deficiencyRef\":\"54.1.d.i\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":\"i\",\"deficiencyId\":\"d\",\"imDescription\":\"Steering\",\"itemDescription\":\"Power steering:\",\"imNumber\":54},{\"deficiencyCategory\":\"advisory\",\"deficiencyText\":\"null\",\"prs\":false,\"additionalInformation\":{\"notes\":\"Dasdasdccc\",\"location\":{}},\"deficiencyRef\":\"5.1\",\"itemNumber\":1,\"stdForProhibition\":false,\"deficiencySubId\":null,\"deficiencyId\":null,\"imDescription\":\"Exhaust Emissions\",\"itemDescription\":\"Compression Ignition Engines Statutory Smoke Meter Test:\",\"imNumber\":5}],\"name\":\"Annual test\",\"testResult\":\"fail\"},\"vehicleClass\":{\"code\":\"t\",\"description\":\"trailer\"},\"testResultId\":\"1\",\"vehicleSize\":\"small\",\"vin\":\"T12876765\",\"testStationName\":\"Abshire-Kub\",\"vehicleId\":\"C456789\",\"countryOfRegistration\":\"gb\",\"vehicleType\":\"trl\",\"preparerId\":\"AK4434\",\"preparerName\":\"Durrell Vehicles Limited\",\"odometerReading\":12312,\"vehicleConfiguration\":\"rigid\",\"testStationType\":\"gvts\",\"testerName\":\"CVS Dev1\",\"vrm\":\"C456789\", \"make\": \"STANLEY\",\"testStationPNumber\":\"09-4129632\",\"numberOfSeats\":50,\"testerEmailAddress\":\"cvs.dev1@dvsagov.onmicrosoft.com\",\"euVehicleCategory\":\"m1\",\"order\":{\"current\":2,\"total\":2}}", "messageAttributes": {}, "md5OfBody": "9586727cbc9f3312542387099b60982c", "eventSource": "aws:sqs", diff --git a/tests/unit/certGen.unitTest.ts b/tests/unit/certGen.unitTest.ts index fa28576..6077ec7 100644 --- a/tests/unit/certGen.unitTest.ts +++ b/tests/unit/certGen.unitTest.ts @@ -6194,7 +6194,7 @@ describe("cert-gen", () => { }); context("and lambda-to-lambda calls were unsuccessful", () => { - it("should return a VTG5A payload without bodyMake, bodyModel and odometer history", async () => { + it("should return a VTG5A payload without bodyModel and odometer history", async () => { const expectedResult: any = { Watermark: "NOT VALID", DATA: { @@ -6212,6 +6212,7 @@ describe("cert-gen", () => { CountryOfRegistrationCode: "gb", VehicleEuClassification: "M1", RawVIN: "T12876765", + Make: "STANLEY", ExpiryDate: "25.02.2020", EarliestDateOfTheNextTest: "01.11.2019", SeatBeltTested: "Yes", @@ -6229,7 +6230,6 @@ describe("cert-gen", () => { // @ts-ignore delete techRecordResponseRwtMock.techRecord_model; // @ts-ignore - delete techRecordResponseRwtMock.techRecord_make; callGetTechRecordSpy.mockResolvedValue(techRecordResponseRwtMock as any); // Make the functions return undefined @@ -6555,7 +6555,7 @@ describe("cert-gen", () => { }); context("and lambda-to-lambda calls were unsuccessful", () => { - it("should return a PRS payload without bodyMake, bodyModel and odometer history", async () => { + it("should return a PRS payload without, bodyModel and odometer history", async () => { const expectedResult: any = { Watermark: "NOT VALID", DATA: { @@ -6578,6 +6578,7 @@ describe("cert-gen", () => { SeatBeltTested: "Yes", SeatBeltPreviousCheckDate: "26.02.2019", SeatBeltNumber: 2, + Make: "STANLEY", }, FAIL_DATA: { TestNumber: "W01A00310", @@ -6600,6 +6601,7 @@ describe("cert-gen", () => { SeatBeltPreviousCheckDate: "26.02.2019", SeatBeltNumber: 2, PRSDefects: ["1.1.a A registration plate: missing. Front."], + Make: "STANLEY" }, Signature: { ImageType: "png", @@ -6611,8 +6613,6 @@ describe("cert-gen", () => { const techRecordResponseRwtMock = cloneDeep(techRecordsRwt); // @ts-ignore - delete techRecordResponseRwtMock.techRecord_make; - // @ts-ignore delete techRecordResponseRwtMock.techRecord_model; callGetTechRecordSpy.mockResolvedValue(techRecordResponseRwtMock as any); @@ -6830,6 +6830,7 @@ describe("cert-gen", () => { SeatBeltTested: "Yes", SeatBeltPreviousCheckDate: "26.02.2019", SeatBeltNumber: 2, + "Make": "STANLEY", DangerousDefects: [ "54.1.a.ii Power steering: not working correctly and obviously affects steering control. Axles: 7. Inner Offside. Asdasd", ], @@ -6850,7 +6851,7 @@ describe("cert-gen", () => { const techRecordResponseRwtMock = cloneDeep(techRecordsRwt); // @ts-ignore - delete techRecordResponseRwtMock.techRecord_make; + // delete techRecordResponseRwtMock.techRecord_make; // @ts-ignore delete techRecordResponseRwtMock.techRecord_model; callGetTechRecordSpy.mockResolvedValue(techRecordResponseRwtMock as any); @@ -7315,7 +7316,7 @@ describe("cert-gen", () => { "inspectionTypes": [ "normal", "basic" - ], + ], "prs": false, "refCalculation": "1.1", "requiredStandard": "The exhaust must be securely mounted", From f95302eada6dafb92314d9eff63f5d14592eb678 Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Mon, 14 Oct 2024 13:05:34 +0100 Subject: [PATCH 4/7] feat(CB2-14255): change log to error message --- src/certificate/commands/MakeAndModelCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/certificate/commands/MakeAndModelCommand.ts b/src/certificate/commands/MakeAndModelCommand.ts index 64b6b87..99005d8 100644 --- a/src/certificate/commands/MakeAndModelCommand.ts +++ b/src/certificate/commands/MakeAndModelCommand.ts @@ -62,7 +62,7 @@ export class MakeAndModelCommand extends BasePayloadCommand { if (isValidForTrn) { return await this.trailerRepository.getTrailerRegistrationObject(testResult.vin, makeAndModel.Make); } else { - console.log('Vehicle is not valid for Trn.'); + console.error('Vehicle is not valid for Trn.'); } return undefined; From 91e789fa3edaed889fa6d8f341c3c5073a6b66de Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Tue, 15 Oct 2024 09:01:25 +0100 Subject: [PATCH 5/7] feat(CB2-14255): test log --- src/test-result/TestResultService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test-result/TestResultService.ts b/src/test-result/TestResultService.ts index 643b916..9dd72c8 100644 --- a/src/test-result/TestResultService.ts +++ b/src/test-result/TestResultService.ts @@ -70,6 +70,7 @@ export class TestResultService { * @returns returns if the condition is satisfied else false */ public isValidForTrn(vehicleType: string, makeAndModel: IMakeAndModel): boolean { + console.log('TEST LOG'); return makeAndModel && !!makeAndModel.Make && vehicleType === VEHICLE_TYPES.TRL; } From 691afe26901bd8e7b353dc54d0991681cee880a1 Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Tue, 15 Oct 2024 09:20:36 +0100 Subject: [PATCH 6/7] feat(CB2-14255): test log removal --- src/test-result/TestResultService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test-result/TestResultService.ts b/src/test-result/TestResultService.ts index 9dd72c8..643b916 100644 --- a/src/test-result/TestResultService.ts +++ b/src/test-result/TestResultService.ts @@ -70,7 +70,6 @@ export class TestResultService { * @returns returns if the condition is satisfied else false */ public isValidForTrn(vehicleType: string, makeAndModel: IMakeAndModel): boolean { - console.log('TEST LOG'); return makeAndModel && !!makeAndModel.Make && vehicleType === VEHICLE_TYPES.TRL; } From 600b4d84319aa4a52cd4ed3a9b50c03ed6f4acad Mon Sep 17 00:00:00 2001 From: Daniel Searle Date: Tue, 15 Oct 2024 10:34:43 +0100 Subject: [PATCH 7/7] feat(CB2-14255): removed commented out code and capitalised TRN --- src/certificate/commands/MakeAndModelCommand.ts | 2 +- tests/unit/certGen.unitTest.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/certificate/commands/MakeAndModelCommand.ts b/src/certificate/commands/MakeAndModelCommand.ts index 99005d8..a24f468 100644 --- a/src/certificate/commands/MakeAndModelCommand.ts +++ b/src/certificate/commands/MakeAndModelCommand.ts @@ -62,7 +62,7 @@ export class MakeAndModelCommand extends BasePayloadCommand { if (isValidForTrn) { return await this.trailerRepository.getTrailerRegistrationObject(testResult.vin, makeAndModel.Make); } else { - console.error('Vehicle is not valid for Trn.'); + console.error('Vehicle is not valid for TRN.'); } return undefined; diff --git a/tests/unit/certGen.unitTest.ts b/tests/unit/certGen.unitTest.ts index 6077ec7..3325142 100644 --- a/tests/unit/certGen.unitTest.ts +++ b/tests/unit/certGen.unitTest.ts @@ -6851,8 +6851,6 @@ describe("cert-gen", () => { const techRecordResponseRwtMock = cloneDeep(techRecordsRwt); // @ts-ignore - // delete techRecordResponseRwtMock.techRecord_make; - // @ts-ignore delete techRecordResponseRwtMock.techRecord_model; callGetTechRecordSpy.mockResolvedValue(techRecordResponseRwtMock as any);