Skip to content

Commit

Permalink
feat(cb2-13369): Amend centralDocs object validation to be optional (#…
Browse files Browse the repository at this point in the history
…413)

* feat(cb2-13369): updated logic for central docs to be optional

* feat(cb2-13369): corrected unit test

* feat(cb2-13369): updated tests following changes to test type id list

* feat(cb2-13369): linting

* feat(cb2-13369): added more tests for better coverage of scenarios

* feat(cb2-13369): removed fail logic as per ticket change

* feat(cb2-13369): removed unused enum

* feat(cb2-13369): removed test status submitted check as per po request
  • Loading branch information
cb-cs authored Aug 8, 2024
1 parent 6f2c245 commit 7faef54
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 175 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"joi": "^17.12.1",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
"@dvsa/cvs-microservice-common": "1.2.0",
"@dvsa/cvs-microservice-common": "1.2.1",
"moment": "^2.29.4",
"moment-timezone": "^0.5.40",
"node-yaml": "^4.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/assets/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export enum MESSAGES {
ID_ALREADY_EXISTS = 'Test Result id already exists',
CONDITIONAL_REQUEST_FAILED = 'The conditional request failed',
REASON_FOR_ABANDONING_NOT_PRESENT = 'Reason for Abandoning not present on all abandoned tests',
CENTRAL_DOCS_NOT_AVAILABLE_FOR_TEST_TYPE = 'Central documents can not be issued for test type',
}

export enum VEHICLE_TYPE {
Expand Down
33 changes: 13 additions & 20 deletions src/utils/validationUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,31 +581,24 @@ export class ValidationUtil {
*/
public static validateCentralDocs(testTypes: TestType[]): void {
testTypes.forEach((testType) => {
if (
TestTypeHelper.validateTestTypeIdInList(
CENTRAL_DOCS_TEST,
testType.testTypeId,
) &&
!testType?.centralDocs
) {
throw new models.HTTPError(
400,
`Central docs required for test type ${testType.testTypeId}`,
);
// if centralDocs is not present, then no object to validate immediately return true
if (!testType.centralDocs) {
return true;
}
if (
!TestTypeHelper.validateTestTypeIdInList(
CENTRAL_DOCS_TEST,
testType.testTypeId,
) &&
testType?.centralDocs
) {

// if centralDocs is present, does the test type id exist in the list of central docs test types
const validTestTypeId = TestTypeHelper.validateTestTypeIdInList(
CENTRAL_DOCS_TEST,
testType.testTypeId,
);

// if the test type is not in the list of central docs test types, throw an error
if (!validTestTypeId) {
throw new models.HTTPError(
400,
`Central documents can not be issued for test type ${testType.testTypeId}`,
`${enums.MESSAGES.CENTRAL_DOCS_NOT_AVAILABLE_FOR_TEST_TYPE} ${testType.testTypeId}`,
);
}
return true;
});
}
}
16 changes: 0 additions & 16 deletions tests/integration/postTestResults.intTest.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import supertest from 'supertest';
import { CENTRAL_DOCS_TEST } from '@dvsa/cvs-microservice-common/classes/testTypes/Constants';
import { ITestResultPayload } from '../../src/models';
import testResultsPostMock from '../resources/test-results-post.json';

const url = 'http://localhost:3006/';
const request = supertest(url);

describe('postTestResults', () => {
context('when submitting a test result with central docs', () => {
it('should return 400 when central docs are required but missing', async () => {
const testResult =
testResultsPostMock[15] as unknown as ITestResultPayload;

testResult.testTypes[0].testTypeId = CENTRAL_DOCS_TEST.IDS[3];
delete testResult.testTypes[0].centralDocs;

const res = await request.post('test-results').send(testResult);

expect(res.status).toBe(400);
expect(res.body).toBe('Central docs required for test type 47');
});
});

context('when submitting an invalid test result', () => {
it('should return 400 for missing required fields', async () => {
const testResult =
Expand Down
165 changes: 70 additions & 95 deletions tests/resources/test-results-post.json
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,6 @@
"certificateNumber": "12512ds",
"testTypeName": "Annual test",
"additionalNotesRecorded": "VEHICLE FRONT REGISTRATION PLATE MISSING",
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"customDefects": [
{
"referenceNumber": "abcd",
Expand Down Expand Up @@ -720,11 +715,6 @@
"code": "m",
"description": "modification or change of engine"
},
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"emissionStandard": "0.03 g/kWh Euro IV PM",
"fuelType": "gas-cng",
"smokeTestKLimitApplied": "123",
Expand Down Expand Up @@ -818,11 +808,6 @@
"reasonForAbandoning": null,
"additionalCommentsForAbandon": null,
"additionalNotesRecorded": "Test notes",
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"customDefects": [
{
"referenceNumber": "abcd",
Expand Down Expand Up @@ -896,11 +881,6 @@
"defectNotes": null
}
],
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"defects": []
}
]
Expand Down Expand Up @@ -967,11 +947,6 @@
"defectNotes": null
}
],
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"defects": []
}
]
Expand Down Expand Up @@ -1037,11 +1012,6 @@
"defectNotes": null
}
],
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
},
"defects": []
}
],
Expand Down Expand Up @@ -1085,12 +1055,7 @@
}
],
"defects": [],
"requiredStandards": [],
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
}
"requiredStandards": []
}
],
"testStationName": "Abshire-Kub",
Expand Down Expand Up @@ -1191,78 +1156,88 @@
"bodyType": { "code": "test code", "description": "test description" }
},
{
"vin": "YV3S2G5265A101407",
"vrm": "PO54ACV",
"countryOfRegistration": "gbz",
"euVehicleCategory": "m2",
"odometerReading": 4000,
"odometerReadingUnits": "kilometres",
"preparerName": "",
"preparerId": "",
"make": "DARWIN/EAST LANCS",
"model": "VYKING MYLLENIUM",
"bodyType": {
"code": "d",
"description": "double decker"
},
"contingencyTestNumber": "1534432",
"testStartTimestamp": "2024-07-18T10:00:00.000",
"testEndTimestamp": "2024-07-18T12:00:00.000",
"testerStaffId": "1",
"systemNumber": "1218",
"testResultId": "195",
"testStartTimestamp": "2019-01-14T10:36:33.987Z",
"testEndTimestamp": "2019-01-14T10:36:33.987Z",
"testStatus": "submitted",
"numberOfWheelsDriven": 3,
"testTypes": [
{
"testResult": "pass",
"testTypeName": "COIF with annual test",
"reasonForAbandoning": null,
"additionalCommentsForAbandon": null,
"certificateNumber": "",
"secondaryCertificateNumber": "34523453452345",
"testTypeStartTimestamp": "2024-07-18T10:00:00.000",
"testTypeEndTimestamp": "2024-07-18T12:00:00.000",
"prohibitionIssued": false,
"seatbeltInstallationCheckDate": true,
"numberOfSeatbeltsFitted": 4,
"lastSeatbeltInstallationCheckDate": "2024-07-18T00:00:00.000",
"additionalNotesRecorded": "",
"defects": [],
"testTypeId": "142",
"name": "With annual test",
"customDefects": [],
"additionalCommentsForAbandon": "none",
"testTypeEndTimestamp": "2019-01-14T10:36:33.987Z",
"secondaryCertificateNumber": "1234",
"reasonForAbandoning": "none",
"testTypeId": "95",
"testTypeStartTimestamp": "2019-01-14T10:36:33.987Z",
"certificateNumber": "W01A00209",
"testTypeName": "First test",
"additionalNotesRecorded": "VEHICLE FRONT REGISTRATION PLATE MISSING",
"customDefects": [
{
"referenceNumber": "abcd",
"defectName": "Some custom defect",
"defectNotes": "some defect noe"
}
],
"defects": [
{
"prohibitionIssued": false,
"deficiencyCategory": "major",
"deficiencyText": "missing.",
"prs": false,
"additionalInformation": {
"location": {
"axleNumber": null,
"horizontal": null,
"vertical": null,
"longitudinal": "front",
"rowNumber": null,
"lateral": null,
"seatNumber": null
},
"notes": "None"
},
"itemNumber": 1,
"deficiencyRef": "1.1.a",
"stdForProhibition": false,
"deficiencySubId": null,
"imDescription": "Registration Plate",
"deficiencyId": "a",
"itemDescription": "A registration plate:",
"imNumber": 1
}
],
"name": "First test",
"testResult": "pass",
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
}
}
],
"testStationName": "Swansea Test HQ",
"testStationPNumber": "14-7160003",
"testStationType": "hq",
"testerStaffId": "8bd2avcf-c31e-4669-acb7-54bc3878e1b0",
"testerName": "CVS Dev",
"testerEmailAddress": "CVS.Dev@dvsagov.onmicrosoft.com",
"reasonForCreation": "TEST DATA",
"testResultId": "4ea8a6a9-b670-4960-9dfc-6a2242791c68",
"vehicleType": "psv",
"testStatus": "submitted",
"reasonForCancellation": "",
"systemNumber": "3128310",
"vehicleClass": {
"code": "l",
"description": "large psv(ie: greater than 23 seats)"
"description": "motorbikes over 200cc or with a sidecar",
"code": "2"
},
"vin": "P012301230123",
"testStationName": "Rowe, Wunsch and Wisoky",
"noOfAxles": 2,
"numberOfWheelsDriven": 2,
"regnDate": "2004-08-23",
"firstUseDate": null,
"createdByName": "Dobbie1",
"createdById": "3341037-bb122-4c54-9gfa-a2413asdfdsaf45",
"lastUpdatedAt": "2024-07-18T14:03:23.155Z",
"lastUpdatedByName": "SA_Daniel Searle1",
"lastUpdatedById": "3341037-bb122-4c54-9gfa-a2413asdfdsaf45",
"numberOfSeats": 70,
"vehicleType": "trl",
"countryOfRegistration": "united kingdom",
"preparerId": "ak4434",
"preparerName": "Durrell Vehicles Limited",
"vehicleConfiguration": "rigid",
"typeOfTest": "contingency",
"source": "vtm",
"vehicleSize": "large"
"testStationType": "gvts",
"reasonForCancellation": "none",
"testerName": "Dorel",
"testStationPNumber": "87-1369569",
"testerEmailAddress": "dorel.popescu@dvsagov.uk",
"euVehicleCategory": "o1",
"trailerId": "abcd",
"firstUseDate": "2018-11-11"
}
]
7 changes: 1 addition & 6 deletions tests/resources/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1939,12 +1939,7 @@
"testTypeEndTimestamp": "2023-01-14T10:36:33.987Z",
"testTypeId": "95",
"testTypeName": "First test",
"testTypeStartTimestamp": "2023-01-14T10:36:33.987Z",
"centralDocs": {
"issueRequired": false,
"notes": "notes",
"reasonsForIssue": ["issue reason"]
}
"testTypeStartTimestamp": "2023-01-14T10:36:33.987Z"
}
],
"trailerId": "C234567",
Expand Down
Loading

0 comments on commit 7faef54

Please sign in to comment.