From c916a85a11883dfa7f9341860938d30a5b9247fa Mon Sep 17 00:00:00 2001 From: Daniel Searle <84069850+Daniel-Searle@users.noreply.github.com> Date: Tue, 25 Jun 2024 08:04:34 +0100 Subject: [PATCH] feat(CB2-12602): Display re-application date from test-results on IVA30 and MSVA30 (#408) * feat(CB2-12602): added reapplicaiton date to the model * feat(CB2-12602): added reapplicaiton date to the model * feat(CB2-12602): move reapplication date to test type and joi validation * feat(CB2-12602): changed the cancelled schema to be date and not string * feat(CB2-12602): changed the cancelled schema to be date and not string * feat(CB2-12602): added the re-applicaiton date to hgv, trl and psv * feat(CB2-12602): removed the console log from validator unitls * feat(CB2-12602): removed the console log from validator unitls * feat(CB2-12602): reapplication date unit tests --- src/models/ITestResult.ts | 2 +- .../SpecialistTestsCommonSchemaCancelled.ts | 1 + .../SpecialistTestsCommonSchemaSubmitted.ts | 1 + .../TestResultsSchemaHGVCancelled.ts | 1 + .../TestResultsSchemaHGVSubmitted.ts | 1 + .../TestResultsSchemaPSVCancelled.ts | 1 + .../TestResultsSchemaPSVSubmitted.ts | 1 + .../TestResultsSchemaTRLCancelled.ts | 1 + .../TestResultsSchemaTRLSubmitted.ts | 1 + tests/unit/insertTestResult.unitTest.ts | 126 +++++++++++++++++- 10 files changed, 134 insertions(+), 2 deletions(-) diff --git a/src/models/ITestResult.ts b/src/models/ITestResult.ts index 020859027..271470116 100644 --- a/src/models/ITestResult.ts +++ b/src/models/ITestResult.ts @@ -79,7 +79,7 @@ export interface TestType { certificateNumber?: string | null; testExpiryDate?: string | Date; // Sent form FE only for LEC tests. For the rest of the test types it is not sent from FE, and calculated in the BE. deletionFlag?: boolean | null; // Not sent from FE, calculated in the BE. - + reapplicationDate?: string | Date; // Used only for LEC tests. modType?: ModType | null; particulateTrapSerialNumber?: string | null; diff --git a/src/models/validators/SpecialistTestsCommonSchemaCancelled.ts b/src/models/validators/SpecialistTestsCommonSchemaCancelled.ts index 30bbcfd98..781f31a3b 100644 --- a/src/models/validators/SpecialistTestsCommonSchemaCancelled.ts +++ b/src/models/validators/SpecialistTestsCommonSchemaCancelled.ts @@ -44,6 +44,7 @@ export const testTypesCommonSchemaSpecialistTestsCancelled = requiredStandards: Joi.array() .items(requiredStandardsSchema.required()) .optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const testResultsCommonSchemaSpecialistTestsCancelled = diff --git a/src/models/validators/SpecialistTestsCommonSchemaSubmitted.ts b/src/models/validators/SpecialistTestsCommonSchemaSubmitted.ts index 48562ab5d..7a85c91c2 100644 --- a/src/models/validators/SpecialistTestsCommonSchemaSubmitted.ts +++ b/src/models/validators/SpecialistTestsCommonSchemaSubmitted.ts @@ -61,6 +61,7 @@ export const testTypesCommonSchemaSpecialistTestsSubmitted = .items(defectsCommonSchemaSpecialistTestsSubmitted) .required(), requiredStandards: Joi.array().items(requiredStandardsSchema).optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const testResultsCommonSchemaSpecialistTestsSubmitted = diff --git a/src/models/validators/TestResultsSchemaHGVCancelled.ts b/src/models/validators/TestResultsSchemaHGVCancelled.ts index 94c9863ae..5ce35317f 100644 --- a/src/models/validators/TestResultsSchemaHGVCancelled.ts +++ b/src/models/validators/TestResultsSchemaHGVCancelled.ts @@ -41,6 +41,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ requiredStandards: array() .items(requiredStandardsSchema.required()) .optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const hgvCancelled = testResultsCommonSchema.keys({ diff --git a/src/models/validators/TestResultsSchemaHGVSubmitted.ts b/src/models/validators/TestResultsSchemaHGVSubmitted.ts index 230b03e9c..4794c939c 100644 --- a/src/models/validators/TestResultsSchemaHGVSubmitted.ts +++ b/src/models/validators/TestResultsSchemaHGVSubmitted.ts @@ -41,6 +41,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ requiredStandards: array() .items(requiredStandardsSchema.required()) .optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const hgvSubmitted = testResultsCommonSchema.keys({ diff --git a/src/models/validators/TestResultsSchemaPSVCancelled.ts b/src/models/validators/TestResultsSchemaPSVCancelled.ts index c4e890c96..43d7ca749 100644 --- a/src/models/validators/TestResultsSchemaPSVCancelled.ts +++ b/src/models/validators/TestResultsSchemaPSVCancelled.ts @@ -56,6 +56,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ smokeTestKLimitApplied: Joi.string().max(100).allow(null), modificationTypeUsed: Joi.string().max(100).allow(null), particulateTrapFitted: Joi.string().max(100).allow(null), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const psvCancelled = testResultsCommonSchema.keys({ diff --git a/src/models/validators/TestResultsSchemaPSVSubmitted.ts b/src/models/validators/TestResultsSchemaPSVSubmitted.ts index 664cd36f6..c5bdf6ade 100644 --- a/src/models/validators/TestResultsSchemaPSVSubmitted.ts +++ b/src/models/validators/TestResultsSchemaPSVSubmitted.ts @@ -56,6 +56,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ smokeTestKLimitApplied: Joi.string().max(100).allow(null), modificationTypeUsed: Joi.string().max(100).allow(null), particulateTrapFitted: Joi.string().max(100).allow(null), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const psvSubmitted = testResultsCommonSchema.keys({ diff --git a/src/models/validators/TestResultsSchemaTRLCancelled.ts b/src/models/validators/TestResultsSchemaTRLCancelled.ts index c8c05ee9f..24de5a221 100644 --- a/src/models/validators/TestResultsSchemaTRLCancelled.ts +++ b/src/models/validators/TestResultsSchemaTRLCancelled.ts @@ -41,6 +41,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ requiredStandards: array() .items(requiredStandardsSchema.required()) .optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const trlCancelled = testResultsCommonSchema.keys({ diff --git a/src/models/validators/TestResultsSchemaTRLSubmitted.ts b/src/models/validators/TestResultsSchemaTRLSubmitted.ts index a758f648d..b8125ce68 100644 --- a/src/models/validators/TestResultsSchemaTRLSubmitted.ts +++ b/src/models/validators/TestResultsSchemaTRLSubmitted.ts @@ -42,6 +42,7 @@ const testTypesSchema = testTypesCommonSchema.keys({ requiredStandards: array() .items(requiredStandardsSchema.required()) .optional(), + reapplicationDate: Joi.date().optional().allow(null, ''), }); export const trlSubmitted = testResultsCommonSchema.keys({ diff --git a/tests/unit/insertTestResult.unitTest.ts b/tests/unit/insertTestResult.unitTest.ts index 84a7c5835..b88bfa7b9 100644 --- a/tests/unit/insertTestResult.unitTest.ts +++ b/tests/unit/insertTestResult.unitTest.ts @@ -3260,7 +3260,31 @@ describe('insertTestResult', () => { }); }, ); - + it('should create the record successfully when reapplication date is provided', () => { + const testResult = { + ...testResultsPostMock[13], + } as ITestResultPayload; + testResult.testTypes.forEach((x) => { + x.testTypeId = '125'; + x.requiredStandards?.push({ + sectionNumber: '01', + sectionDescription: 'Noise', + rsNumber: 1, + requiredStandard: 'The exhaust must be securely mounted.', + refCalculation: '1.1', + additionalInfo: true, + inspectionTypes: ['basic', 'normal'], + prs: false, + additionalNotes: '' + }) + return x; + }); + testResult.testTypes[0].reapplicationDate = '2024-06-21T13:21:16.417Z'; + + const validationResult = + ValidationUtil.validateInsertTestResultPayload(testResult); + expect(validationResult).toBe(true); + }); // TODO COMMENTED OUT UNTIL FEATURE TEAMS COMPLETE IVA DEFECT WORK // context( // 'when creating an IVA failed test record without IVA defects', @@ -3887,6 +3911,106 @@ describe('insertTestResult', () => { ); }); }); + it('should create the record successfully when reapplication date is provided', () => { + const testResult = cloneDeep(testResultsPostMock[13]); + testResult.testTypes[0].testTypeId = '133'; + testResult.testTypes[0].certificateNumber = '12345'; + testResult.testTypes[0].requiredStandards?.push({ + sectionNumber: '4', + sectionDescription: 'Speedometer', + rsNumber: 1, + requiredStandard: + 'A speedometer; does not indicate speed up to the design speed of the vehicle', + refCalculation: '41.1c', + additionalInfo: true, + inspectionTypes: [], + prs: false, + additionalNotes: '', + }); + testResult.testTypes[0].reapplicationDate = '2024-06-21T13:21:16.417Z'; + MockTestResultsDAO = jest.fn().mockImplementation(() => ({ + createSingle: () => + Promise.resolve({ + Attributes: Array.of(testResult), + }), + createTestNumber: () => + Promise.resolve({ + testNumber: 'W01A00209', + id: 'W01', + certLetter: 'A', + sequenceNumber: '002', + }), + getTestCodesAndClassificationFromTestTypes: () => + Promise.resolve({ + linkedTestCode: null, + defaultTestCode: 'qjt1', + testTypeClassification: 'MSVA With Certificate', + }), + getBySystemNumber: (systemNumber: any) => Promise.resolve([]), + })); + + testResultsService = new TestResultsService(new MockTestResultsDAO()); + + expect.assertions(2); + return testResultsService + .insertTestResult(testResult) + .then((insertedTestResult: any) => { + expect(insertedTestResult[0].testTypes[0].reapplicationDate).toBe('2024-06-21T13:21:16.417Z'); + expect(insertedTestResult[0].testTypes[0].certificateNumber).toBe( + '12345', + ); + }); + }); + it('should create the record successfully with the reapplication date blank', () => { + const testResult = cloneDeep(testResultsPostMock[13]); + testResult.testTypes[0].testTypeId = '133'; + testResult.testTypes[0].certificateNumber = '12345'; + testResult.testTypes[0].requiredStandards?.push({ + sectionNumber: '4', + sectionDescription: 'Speedometer', + rsNumber: 1, + requiredStandard: + 'A speedometer; does not indicate speed up to the design speed of the vehicle', + refCalculation: '41.1c', + additionalInfo: true, + inspectionTypes: [], + prs: false, + additionalNotes: '', + }); + testResult.testTypes[0].reapplicationDate = ''; + MockTestResultsDAO = jest.fn().mockImplementation(() => ({ + createSingle: () => + Promise.resolve({ + Attributes: Array.of(testResult), + }), + createTestNumber: () => + Promise.resolve({ + testNumber: 'W01A00209', + id: 'W01', + certLetter: 'A', + sequenceNumber: '002', + }), + getTestCodesAndClassificationFromTestTypes: () => + Promise.resolve({ + linkedTestCode: null, + defaultTestCode: 'qjt1', + testTypeClassification: 'MSVA With Certificate', + }), + getBySystemNumber: (systemNumber: any) => Promise.resolve([]), + })); + + testResultsService = new TestResultsService(new MockTestResultsDAO()); + + expect.assertions(2); + return testResultsService + .insertTestResult(testResult) + .then((insertedTestResult: any) => { + expect(insertedTestResult[0].testTypes[0].reapplicationDate).toBe(''); + expect(insertedTestResult[0].testTypes[0].certificateNumber).toBe( + '12345', + ); + }); + }); }, ); });