Skip to content

Commit

Permalink
feat(cb2-13178): use enum to validate test station type
Browse files Browse the repository at this point in the history
  • Loading branch information
LGin-BJSS committed Aug 13, 2024
1 parent e039726 commit d4d1e87
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 8 deletions.
195 changes: 189 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.549.0",
"@aws-sdk/lib-dynamodb": "^3.549.0",
"@dvsa/cvs-type-definitions": "^7.4.0",
"@smithy/smithy-client": "^2.5.0",
"aws-lambda": "^1.0.7",
"aws-xray-sdk": "^3.6.0",
Expand Down
3 changes: 2 additions & 1 deletion src/functions/putTestStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Joi from "joi";
import { TestStationService } from "../services/TestStationService";
import { TestStationDAO } from "../models/TestStationDAO";
import { ITestStation } from "../models/ITestStation";
import { TestStationTypes} from "@dvsa/cvs-type-definitions/types/v1/enums/testStationType.enum"

export const putTestStation = async (testStation: ITestStation) => {
await validateTestStation(testStation);
Expand Down Expand Up @@ -35,7 +36,7 @@ async function validateTestStation(testStation: any) {
testStationLatitude: Joi.number().allow(null),
testStationType: Joi.any()
.required()
.valid("atf", "tass", "gvts", "potf", "hq", "other"),
.valid(... Object.values(TestStationTypes)),
testStationEmails: Joi.array().items(Joi.string()).required(),
});
await schema.validateAsync(testStation);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/putTestStationFunction.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("putTestStation Handler", () => {
} catch (e) {
expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toEqual(
'"testStationType" must be one of [atf, tass, gvts, potf, hq, other]'
'"testStationType" must be one of [atf, gvts, hq, potf, vef]'
);
}
});
Expand Down

0 comments on commit d4d1e87

Please sign in to comment.