Skip to content

Commit a139d77

Browse files
authored
Yup visit schema validation test script. (#484)
1 parent 0ea1eb3 commit a139d77

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

frontend/src/validation/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ const visitSchema = Yup.object().shape({
106106
.integer(),
107107
})
108108

109-
// eslint-disable-next-line no-unused-vars
110109
const participantSchema = Yup.object().shape({
111110
first_name: Yup.string()
112111
.required()

frontend/test/VisitSchema.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { validateForm, VISIT_SCHEMA } from "../src/validation/index"
2+
3+
let MOCK_SCHEMA = {
4+
id: 1,
5+
participant: 111,
6+
program: 1,
7+
service: 1,
8+
urgency: 1,
9+
notes: "Blah notes and such!",
10+
}
11+
12+
describe("Visit Schema Validation", () => {
13+
it("should not return any errors", async () => {
14+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
15+
expect(validationErrors.length).toEqual(0)
16+
})
17+
18+
it("should not return any errors with null id", async () => {
19+
MOCK_SCHEMA.id = null
20+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
21+
expect(validationErrors.length).toEqual(0)
22+
MOCK_SCHEMA.id = 1
23+
})
24+
25+
it("should return one error without program", async () => {
26+
MOCK_SCHEMA.program = null
27+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
28+
expect(validationErrors.length).toEqual(1)
29+
expect(validationErrors[0].name).toEqual("program")
30+
MOCK_SCHEMA.program = 1
31+
})
32+
33+
it("should return one error when program is a string", async () => {
34+
MOCK_SCHEMA.program = "1"
35+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
36+
expect(validationErrors.length).toEqual(1)
37+
expect(validationErrors[0].name).toEqual("program")
38+
MOCK_SCHEMA.program = 1
39+
})
40+
41+
it("should return one error without service", async () => {
42+
MOCK_SCHEMA.service = null
43+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
44+
expect(validationErrors.length).toEqual(1)
45+
expect(validationErrors[0].name).toEqual("service")
46+
MOCK_SCHEMA.service = 1
47+
})
48+
49+
it("should return one error when service is a string", async () => {
50+
MOCK_SCHEMA.service = "2"
51+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
52+
expect(validationErrors.length).toEqual(1)
53+
expect(validationErrors[0].name).toEqual("service")
54+
MOCK_SCHEMA.service = 1
55+
})
56+
57+
it("should return one error without urgency", async () => {
58+
MOCK_SCHEMA.urgency = null
59+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
60+
expect(validationErrors.length).toEqual(1)
61+
expect(validationErrors[0].name).toEqual("urgency")
62+
MOCK_SCHEMA.urgency = 1
63+
})
64+
65+
it("should return one error when urgency is a string", async () => {
66+
MOCK_SCHEMA.urgency = "4"
67+
const validationErrors = await validateForm(MOCK_SCHEMA, VISIT_SCHEMA)
68+
expect(validationErrors.length).toEqual(1)
69+
expect(validationErrors[0].name).toEqual("urgency")
70+
MOCK_SCHEMA.urgency = 1
71+
})
72+
})

0 commit comments

Comments
 (0)