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

feat(CB2-12602): Display re-application date from test-results on IVA30 and MSVA30 #408

Merged
merged 9 commits into from
Jun 25, 2024
2 changes: 1 addition & 1 deletion src/models/ITestResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const testTypesCommonSchemaSpecialistTestsCancelled =
requiredStandards: Joi.array()
.items(requiredStandardsSchema.required())
.optional(),
reapplicationDate: Joi.date().optional().allow(null, ''),
});

export const testResultsCommonSchemaSpecialistTestsCancelled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaHGVCancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaHGVSubmitted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaPSVCancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaPSVSubmitted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaTRLCancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/models/validators/TestResultsSchemaTRLSubmitted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
126 changes: 125 additions & 1 deletion tests/unit/insertTestResult.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
);
});
});
},
);
});
Expand Down
Loading