diff --git a/src/certificate/commands/MakeAndModelCommand.ts b/src/certificate/commands/MakeAndModelCommand.ts index ddc12f30..a24f4684 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.error('Vehicle is not valid for TRN.'); } return undefined; diff --git a/src/test-result/TestResultService.ts b/src/test-result/TestResultService.ts index 6f9bfd4a..643b916c 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/tests/resources/queue-event-fail.json b/tests/resources/queue-event-fail.json index 9f46b4ae..2c56b87b 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 fa285768..33251424 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,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); @@ -7315,7 +7314,7 @@ describe("cert-gen", () => { "inspectionTypes": [ "normal", "basic" - ], + ], "prs": false, "refCalculation": "1.1", "requiredStandard": "The exhaust must be securely mounted",