Skip to content

Commit cf05aef

Browse files
authored
Test participant store actions 478 (#496)
* initial set of tests. work in progress. * Further working on the store testing. * Ignoring non actions. Included data creation utility function for giggles.
1 parent 8ba373c commit cf05aef

File tree

1 file changed

+301
-0
lines changed

1 file changed

+301
-0
lines changed
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
import { ParticipantStore } from "../src/stores/ParticipantStore"
2+
import { format } from "date-fns"
3+
4+
//Test the participant store actions
5+
describe("Participant Store", () => {
6+
const store = new ParticipantStore()
7+
8+
//Setters
9+
it("sets an is editing flag", () => {
10+
store.setIsEditing(true)
11+
expect(store.isEditing).toBe(true)
12+
})
13+
14+
it("sets a participant from user data", () => {
15+
let startDate = format(new Date("1989-07-13"), "yyyy-MM-dd")
16+
let data = {
17+
id: 1,
18+
first_name: "Buck",
19+
last_name: "Turgison",
20+
last_four_ssn: 1234,
21+
date_of_birth: "10-28-1929",
22+
start_date: startDate,
23+
pp_id: "12345",
24+
sep_id: "12345",
25+
maiden_name: "Strangelove",
26+
race: "white (caucasian)",
27+
gender: "male",
28+
is_insured: true,
29+
insuranceType: "Medical",
30+
insurer: "Strategic Air Command",
31+
}
32+
store.setParticipant(data)
33+
expect(store.participant.id).toBe(1)
34+
expect(store.participant.first_name).toBe("Buck")
35+
expect(store.participant.last_name).toBe("Turgison")
36+
expect(store.participant.last_four_ssn).toBe(1234)
37+
expect(store.participant.date_of_birth).toBe("10-28-1929")
38+
expect(store.participant.start_date).toBe(startDate)
39+
expect(store.participant.pp_id).toBe("12345")
40+
expect(store.participant.sep_id).toBe("12345")
41+
expect(store.participant.maiden_name).toBe("Strangelove")
42+
expect(store.participant.race).toBe("white (caucasian)")
43+
expect(store.participant.gender).toBe("male")
44+
expect(store.participant.is_insured).toBe(true)
45+
expect(store.participant.insuranceType).toBe("Medical")
46+
expect(store.participant.insurer).toBe("Strategic Air Command")
47+
})
48+
49+
it("sets a visit from user data", () => {
50+
let data = {
51+
id: 1,
52+
participant: 11,
53+
program: "4",
54+
service: "2",
55+
notes: "Blah blah notes blah",
56+
urgency: "Time Sensitive",
57+
}
58+
store.setVisit(data)
59+
expect(store.visit.id).toBe(1)
60+
expect(store.visit.participant).toBe(11)
61+
expect(store.visit.program).toBe("4")
62+
expect(store.visit.service).toBe("2")
63+
expect(store.visit.notes).toBe("Blah blah notes blah")
64+
expect(store.visit.urgency).toBe("Time Sensitive")
65+
})
66+
67+
it("sets insurers from user data", () => {
68+
let data = Array(1, 2, 3, 4, 5, 6, 7)
69+
store.setInsurers(data)
70+
expect(store.insurers.length).toBe(7)
71+
})
72+
73+
it("sets insurer from user data and enforces stringness", () => {
74+
store.setInsurer(1)
75+
expect(store.participant.insurer).toBe("1")
76+
})
77+
78+
it("sets ppid & last four SSN from user data", () => {
79+
store.setPPId("ab1234")
80+
expect(store.participant.pp_id).toBe("ab1234")
81+
expect(store.participant.last_four_ssn).toBe("1234")
82+
})
83+
84+
it("sets last four digits of SSN from user data", () => {
85+
store.setLastFourSSN("1234")
86+
expect(store.participant.last_four_ssn).toBe("1234")
87+
})
88+
89+
it("sets visit program from user data", () => {
90+
let data = [
91+
{
92+
id: 1,
93+
name: "test1",
94+
is_closed: false,
95+
is_frozen: false,
96+
has_queue: false,
97+
},
98+
{
99+
id: 2,
100+
name: "test2",
101+
is_closed: false,
102+
is_frozen: false,
103+
has_queue: false,
104+
},
105+
{
106+
id: 3,
107+
name: "test3",
108+
is_closed: false,
109+
is_frozen: false,
110+
has_queue: false,
111+
},
112+
{
113+
id: 4,
114+
name: "test4",
115+
is_closed: true,
116+
is_frozen: true,
117+
has_queue: false,
118+
},
119+
{
120+
id: 5,
121+
name: "test5",
122+
is_closed: true,
123+
is_frozen: true,
124+
has_queue: false,
125+
},
126+
]
127+
store.setPrograms(data)
128+
expect(store.programs.length).toBe(3)
129+
})
130+
131+
it("sets visit program, visit service and services list from user data", () => {
132+
let programID = 3
133+
let data = [
134+
{
135+
id: 1,
136+
name: "test1",
137+
is_closed: false,
138+
is_frozen: false,
139+
has_queue: false,
140+
services: Array(1),
141+
},
142+
{
143+
id: 2,
144+
name: "test2",
145+
is_closed: false,
146+
is_frozen: false,
147+
has_queue: false,
148+
services: Array(1, 2),
149+
},
150+
{
151+
id: 3,
152+
name: "test3",
153+
is_closed: false,
154+
is_frozen: false,
155+
has_queue: false,
156+
services: Array(1, 2, 3),
157+
},
158+
{
159+
id: 4,
160+
name: "test4",
161+
is_closed: true,
162+
is_frozen: true,
163+
has_queue: false,
164+
services: Array(1, 2, 3, 4),
165+
},
166+
{
167+
id: 5,
168+
name: "test5",
169+
is_closed: true,
170+
is_frozen: true,
171+
has_queue: false,
172+
services: Array(1, 2, 3, 4, 5),
173+
},
174+
]
175+
store.setPrograms(data)
176+
store.setVisitProgram(programID)
177+
expect(store.visit.service).toBe("")
178+
expect(store.visit.program).toBe(3)
179+
expect(store.services.length).toBe(3)
180+
})
181+
182+
it("sets the route to the queue table", () => {
183+
expect(store.routeToQueueTable).toBe(false)
184+
store.setRouteToQueue(true)
185+
expect(store.routeToQueueTable).toBe(true)
186+
})
187+
188+
it("sets the participant id from user data", () => {
189+
let id = 1
190+
store.setVisitParticipantId(id)
191+
expect(store.visit.participant).toBe(1)
192+
})
193+
194+
it("sets the visit list", () => {
195+
let data = Array(1, 2, 3, 4, 5)
196+
store.setVisitsList(data)
197+
expect(store.visitList.length).toBe(5)
198+
})
199+
200+
it("sets the site list", () => {
201+
let data = [
202+
{ id: 1, site_name: "test1", site_type: "hq" },
203+
{ id: 2, site_name: "test2", site_type: "hq2" },
204+
{ id: 3, site_name: "test3", site_type: "hq3" },
205+
{ id: 4, site_name: "test4", site_type: "hq4" },
206+
{ id: 5, site_name: "test5", site_type: "hq5" },
207+
]
208+
store.setSites(data)
209+
expect(store.sites.length).toBe(5)
210+
expect(store.sites[3].id).toBe(4)
211+
})
212+
213+
it("sets the current site", () => {
214+
let data = [
215+
{ id: 1, site_name: "test1", site_type: "hq" },
216+
{ id: 2, site_name: "test2", site_type: "hq2" },
217+
{ id: 3, site_name: "test3", site_type: "hq3" },
218+
{ id: 4, site_name: "test4", site_type: "hq4" },
219+
{ id: 5, site_name: "test5", site_type: "hq5" },
220+
]
221+
store.setCurrentSite(data[1])
222+
expect(store.currentSite.id).toBe(2)
223+
})
224+
225+
it("sets the visit data", () => {
226+
let data = {
227+
id: 5,
228+
participant: 5,
229+
URGENCY_LEVEL: { TIME_SENSITIVE: 1 },
230+
program: 5,
231+
service: 1,
232+
notes: "blah five five five",
233+
urgency: "TIME_SENSITIVE",
234+
}
235+
store.setVisitData(data)
236+
expect(store.visitData.id).toBe(5)
237+
expect(store.visitData.urgency).toBe("TIME_SENSITIVE")
238+
})
239+
240+
// //State actions
241+
it("creates a default participant", () => {
242+
store.setDefaultParticipant()
243+
let startDate = format(new Date(), "yyyy-MM-dd")
244+
expect(store.participant.id).toBe(null)
245+
expect(store.participant.first_name).toBe("")
246+
expect(store.participant.last_name).toBe("")
247+
expect(store.participant.last_four_ssn).toBe(0)
248+
expect(store.participant.date_of_birth).toBe("")
249+
expect(store.participant.start_date).toBe(startDate)
250+
expect(store.participant.pp_id).toBe("")
251+
expect(store.participant.sep_id).toBe("")
252+
expect(store.participant.maiden_name).toBe("")
253+
expect(store.participant.race).toBe("")
254+
expect(store.participant.gender).toBe("")
255+
expect(store.participant.is_insured).toBe(false)
256+
expect(store.participant.insuranceType).toBe("")
257+
expect(store.participant.insurer).toBe("")
258+
})
259+
260+
it("creates a default visit", () => {
261+
store.setDefaultVisit()
262+
expect(store.visit.id).toBe(null)
263+
expect(store.visit.participant).toBe(null)
264+
expect(store.visit.program).toBe("")
265+
expect(store.visit.service).toBe("")
266+
expect(store.visit.notes).toBe("")
267+
expect(store.visit.urgency).toBe("")
268+
})
269+
270+
it("creates a participant list", () => {
271+
let data = Array(1, 2, 3, 4, 5)
272+
store.setParticipantsList(data)
273+
expect(store.participants.length).toBe(5)
274+
})
275+
276+
it("creates an empty participant list", () => {
277+
let data = "not an array"
278+
store.setParticipantsList(data)
279+
expect(store.participants.length).toBe(0)
280+
})
281+
282+
it("handles changes to participant data", () => {
283+
store.handleParticipantChange({ name: "is_insured", value: "true" })
284+
expect(store.participant.is_insured).toBe(true)
285+
store.handleParticipantChange({ name: "pp_id", value: "ab1234" })
286+
expect(store.participant.pp_id).toBe("ab1234")
287+
store.handleParticipantChange({ name: "insurer", value: 2 })
288+
expect(store.participant.insurer).toBe("2")
289+
})
290+
291+
it("handles changes to visit data", () => {
292+
store.handleVisitChange({ name: "test", value: 7 })
293+
expect(store.visit.test).toBe(7)
294+
})
295+
296+
//Utility functions
297+
it("creates a start date", () => {
298+
let newDate = format(new Date("07-13-1989"), "yyyy-MM-dd")
299+
expect(newDate).toBe("1989-07-13")
300+
})
301+
})

0 commit comments

Comments
 (0)