@@ -6,7 +6,181 @@ import * as appHandler from "./route";
6
6
import { expect , test } from "@jest/globals" ;
7
7
import { dbMock } from "@/test/dbMock" ;
8
8
import { authMock } from "@/test/authMock" ;
9
- import { OrganizationType , UserType } from "@prisma/client" ;
9
+ import { UserType } from "@prisma/client" ;
10
+
11
+ const getValidPartnerDetails = ( ) => {
12
+ const testContact = {
13
+ firstName : "test_firstName" ,
14
+ lastName : "test_lastName" ,
15
+ orgTitle : "test_orgTitle" ,
16
+ primaryTelephone : "test_primaryTelephone" ,
17
+ secondaryTelephone : "test_secondaryTelephone" ,
18
+ } ;
19
+
20
+ const partnerDetails = {
21
+ // General
22
+ siteName : "test_siteName" ,
23
+ address : "test_address" ,
24
+ department : "test_department" ,
25
+ gpsCoordinates : "test_gpsCoordinates" ,
26
+ website : "test_website" ,
27
+ socialMedia : "test_socialMedia" ,
28
+
29
+ // Contact
30
+ regionalContact : testContact ,
31
+ medicalContact : testContact ,
32
+ adminDirectorContact : testContact ,
33
+ pharmacyContact : testContact ,
34
+ contactWhatsAppName : "test_contactWhatsAppName" ,
35
+ contactWhatsAppNumber : "test_contactWhatsAppNumber" ,
36
+
37
+ // Introduction
38
+ organizationHistory : "test_organizationHistory" ,
39
+ supportRequested : "mobile_clinic_support" ,
40
+ yearOrganizationEstablished : 2025 ,
41
+ registeredWithMssp : true ,
42
+ proofOfRegistationWithMssp : "https://www.google.com/" , // this is a URL to the file upload
43
+ programUpdatesSinceLastReport : "test_programUpdatesSinceLastReport" ,
44
+
45
+ // Facility
46
+ facilityType : [
47
+ "birthing_center" ,
48
+ "clinic" ,
49
+ "hospital" ,
50
+ "elderly_care" ,
51
+ "rehabilitation_center" ,
52
+ "dispensary" ,
53
+ "orphanage" ,
54
+ "primary_care" ,
55
+ "health_center" ,
56
+ "community_health_education" ,
57
+ "nutrition_feeding" ,
58
+ "secondary_tertiary_healthcare" ,
59
+ ] ,
60
+ organizationType : [ "non_profit" , "for_profit" , "faith_based" ] ,
61
+ governmentRun : true ,
62
+ emergencyMedicalRecordsSystemPresent : true ,
63
+ emergencyMedicalRecordsSystemName : "test" ,
64
+ numberOfInpatientBeds : 10 ,
65
+ numberOfPatientsServedAnnually : 10 ,
66
+ communityMobileOutreachOffered : true ,
67
+ communityMobileOutreachDescription : "test" ,
68
+
69
+ // Infrastructure and Services
70
+ facilityDescription : "test" ,
71
+ cleanWaterAccessible : true ,
72
+ cleanWaterDescription : "test" ,
73
+ closestSourceOfCleanWater : "test" ,
74
+ sanitationFacilitiesPresent : true ,
75
+ sanitationFacilitiesLockableFromInside : true ,
76
+ electricityAvailable : true ,
77
+ accessibleByDisablePatients : true ,
78
+ medicationDisposalProcessDefined : true ,
79
+ medicationDisposalProcessDescription : "test" ,
80
+ pickupVehiclePresent : true ,
81
+ pickupVehicleType : "test" ,
82
+ pickupLocations : [ "les_cayes" , "port_au_prince" ] ,
83
+
84
+ // Programs and Services Provided
85
+ medicalServicesProvided : [
86
+ "cancer" ,
87
+ "dentistry" ,
88
+ "dermatology" ,
89
+ "hematology" ,
90
+ "immunizations" ,
91
+ "parasitic_infections" ,
92
+ "acute_respiratory_infections" ,
93
+ "vector_borne_diseases" ,
94
+ "chronic_diseases" ,
95
+ "diarrheal_diseases" ,
96
+ "vaccine_preventable_diseases" ,
97
+ "infectious_diseases" ,
98
+ "neurology" ,
99
+ "malnutrition" ,
100
+ "ophthalmology" ,
101
+ "ears_nose_throat" ,
102
+ "orthopedics_and_rehabilitation" ,
103
+ "pediatrics" ,
104
+ "radiology" ,
105
+ "wound_care" ,
106
+ "maternal_care" ,
107
+ "lab_tests" ,
108
+ "trauma_and_surgery" ,
109
+ "urology" ,
110
+ ] ,
111
+ otherMedicalServicesProvided : "test" ,
112
+
113
+ // Finances
114
+ patientsWhoCannotPay : "test" ,
115
+ percentageOfPatientsNeedingFinancialAid : 10 ,
116
+ percentageOfPatientsReceivingFreeTreatment : 10 ,
117
+ annualSpendingOnMedicationsAndMedicalSupplies : "5001_to_10000" ,
118
+ numberOfPrescriptionsPrescribedAnnuallyTracked : true ,
119
+ numberOfTreatmentsPrescribedAnnually : 10 ,
120
+ anyMenServedLastYear : true ,
121
+ menServedLastYear : 10 ,
122
+ anyWomenServedLastYear : true ,
123
+ womenServedLastYear : 10 ,
124
+ anyBoysServedLastYear : true ,
125
+ boysServedLastYear : 10 ,
126
+ anyGirlsServedLastYear : true ,
127
+ girlsServedLastYear : 10 ,
128
+ anyBabyBoysServedLastYear : true ,
129
+ babyBoysServedLastYear : 10 ,
130
+ anyBabyGirlsServedLastYear : true ,
131
+ babyGirlsServedLastYear : 10 ,
132
+ totalPatientsServedLastYear : 10 ,
133
+
134
+ // Staff
135
+ numberOfDoctors : 10 ,
136
+ numberOfNurses : 10 ,
137
+ numberOfMidwives : 10 ,
138
+ numberOfAuxilaries : 10 ,
139
+ numberOfStatisticians : 10 ,
140
+ numberOfPharmacists : 10 ,
141
+ numberOfCHW : 10 ,
142
+ numberOfAdministrative : 10 ,
143
+ numberOfHealthOfficers : 10 ,
144
+ totalNumberOfStaff : 10 ,
145
+ other : "test" ,
146
+
147
+ // Medical Supplies
148
+ mostNeededMedicalSupplies : [
149
+ "anesthetics" ,
150
+ "antipyretics_nsaids" ,
151
+ "antiallergics" ,
152
+ "anti_infectives" ,
153
+ "antineoplastics" ,
154
+ "cardiovascular" ,
155
+ "dermatological" ,
156
+ "diagnostics" ,
157
+ "diuretics" ,
158
+ "gastrointestinal" ,
159
+ "ophthalmological" ,
160
+ "respiratory" ,
161
+ "replacements" ,
162
+ "vitamins_minerals" ,
163
+ "bandages" ,
164
+ "braces" ,
165
+ "hospital_consumables" ,
166
+ "dental" ,
167
+ "diagnostic" ,
168
+ "personal_care" ,
169
+ "Prosthetics" ,
170
+ "respiratory " ,
171
+ "surgical " ,
172
+ "syringes_needles" ,
173
+ ] ,
174
+ otherSpecialityItemsNeeded : "test" ,
175
+ } ;
176
+ return partnerDetails ;
177
+ } ;
178
+
179
+ const getPartnerDetailsFormData = ( ) => {
180
+ const formData = new FormData ( ) ;
181
+ formData . append ( "partnerDetails" , JSON . stringify ( getValidPartnerDetails ( ) ) ) ;
182
+ return formData ;
183
+ } ;
10
184
11
185
test ( "returns 401 on invalid session" , async ( ) => {
12
186
await testApiHandler ( {
@@ -56,7 +230,7 @@ test("returns 404 on not found", async () => {
56
230
} ) ;
57
231
58
232
// Mock record not found
59
- dbMock . partnerDetails . findUnique . mockResolvedValueOnce ( null ) ;
233
+ dbMock . user . findUnique . mockResolvedValueOnce ( null ) ;
60
234
61
235
const res = await fetch ( { method : "GET" , body : null } ) ;
62
236
await expect ( res . status ) . toBe ( 404 ) ;
@@ -77,22 +251,19 @@ test("returns 200 and correct details on success when partner + id matches", asy
77
251
expires : "" ,
78
252
} ) ;
79
253
80
- const exampleDetails = {
81
- numberOfPatients : 10 ,
82
- organizationType : OrganizationType . NON_PROFIT ,
83
- } ;
84
-
85
254
// Mock return for partner details
86
- dbMock . partnerDetails . findUnique . mockResolvedValueOnce (
87
- exampleDetails as any
88
- ) ;
255
+ dbMock . user . findUnique . mockResolvedValueOnce ( {
256
+ partnerDetails : getValidPartnerDetails ( ) ,
257
+ type : "PARTNER" ,
258
+ id : 0 ,
259
+ email : "test_email@test.com" ,
260
+ name : "tester" ,
261
+ passwordHash : "test_hash" ,
262
+ } ) ;
89
263
90
264
const res = await fetch ( { method : "GET" , body : null } ) ;
91
265
await expect ( res . status ) . toBe ( 200 ) ;
92
- await expect ( res . json ( ) ) . resolves . toStrictEqual ( {
93
- numberOfPatients : 10 ,
94
- organizationType : OrganizationType . NON_PROFIT ,
95
- } ) ;
266
+ await expect ( res . json ( ) ) . resolves . toStrictEqual ( getValidPartnerDetails ( ) ) ;
96
267
} ,
97
268
} ) ;
98
269
} ) ;
@@ -107,22 +278,19 @@ test("returns 200 and correct details on success when staff matches", async () =
107
278
expires : "" ,
108
279
} ) ;
109
280
110
- const exampleDetails = {
111
- numberOfPatients : 10 ,
112
- organizationType : OrganizationType . NON_PROFIT ,
113
- } ;
114
-
115
281
// Mock return for partner details
116
- dbMock . partnerDetails . findUnique . mockResolvedValueOnce (
117
- exampleDetails as any
118
- ) ;
282
+ dbMock . user . findUnique . mockResolvedValueOnce ( {
283
+ partnerDetails : getValidPartnerDetails ( ) ,
284
+ type : "PARTNER" ,
285
+ id : 0 ,
286
+ email : "test_email@test.com" ,
287
+ name : "tester" ,
288
+ passwordHash : "test_hash" ,
289
+ } ) ;
119
290
120
291
const res = await fetch ( { method : "GET" , body : null } ) ;
121
292
await expect ( res . status ) . toBe ( 200 ) ;
122
- await expect ( res . json ( ) ) . resolves . toStrictEqual ( {
123
- numberOfPatients : 10 ,
124
- organizationType : OrganizationType . NON_PROFIT ,
125
- } ) ;
293
+ await expect ( res . json ( ) ) . resolves . toStrictEqual ( getValidPartnerDetails ( ) ) ;
126
294
} ,
127
295
} ) ;
128
296
} ) ;
@@ -132,17 +300,13 @@ describe("POST /api/partnerDetails/[userId]", () => {
132
300
test ( "returns 401 when there is no valid session" , async ( ) => {
133
301
authMock . mockReturnValueOnce ( null ) ; //no valid session
134
302
135
- const formData = new FormData ( ) ;
136
- formData . append ( "numberOfPatients" , "8" ) ;
137
- formData . append ( "organizationType" , "NON_PROFIT" ) ;
138
-
139
303
await testApiHandler ( {
140
304
appHandler,
141
305
params : { userId : "1" } ,
142
306
async test ( { fetch } ) {
143
307
const res = await fetch ( {
144
308
method : "POST" ,
145
- body : formData ,
309
+ body : getPartnerDetailsFormData ( ) ,
146
310
} ) ;
147
311
148
312
expect ( res . status ) . toBe ( 401 ) ;
@@ -159,17 +323,13 @@ describe("POST /api/partnerDetails/[userId]", () => {
159
323
expires : "" ,
160
324
} ) ;
161
325
162
- const formData = new FormData ( ) ;
163
- formData . append ( "numberOfPatients" , "8" ) ;
164
- formData . append ( "organizationType" , "NON_PROFIT" ) ;
165
-
166
326
await testApiHandler ( {
167
327
appHandler,
168
328
params : { userId : "2" } , //different user
169
329
async test ( { fetch } ) {
170
330
const res = await fetch ( {
171
331
method : "POST" ,
172
- body : formData ,
332
+ body : getPartnerDetailsFormData ( ) ,
173
333
} ) ;
174
334
175
335
expect ( res . status ) . toBe ( 403 ) ;
@@ -215,33 +375,26 @@ describe("POST /api/partnerDetails/[userId]", () => {
215
375
expires : "" ,
216
376
} ) ;
217
377
218
- const updatedPartnerDetails = {
219
- numberOfPatients : 5 ,
220
- organizationType : "NON_PROFIT" as OrganizationType ,
221
- } ;
378
+ const updatedPartnerDetails = getValidPartnerDetails ( ) ;
222
379
223
380
const updatedUser = {
224
381
id : 1 ,
225
382
email : "test_email" ,
226
383
name : "test_name" ,
227
384
passwordHash : "test_hash" ,
228
385
type : UserType . SUPER_ADMIN ,
229
- partnerDetails : updatedPartnerDetails
230
- }
386
+ partnerDetails : updatedPartnerDetails ,
387
+ } ;
231
388
232
389
dbMock . user . update . mockResolvedValueOnce ( updatedUser ) ;
233
390
234
- const formData = new FormData ( ) ;
235
- formData . append ( "numberOfPatients" , "5" ) ;
236
- formData . append ( "organizationType" , "NON_PROFIT" ) ;
237
-
238
391
await testApiHandler ( {
239
392
appHandler,
240
393
params : { userId : "1" } ,
241
394
async test ( { fetch } ) {
242
395
const res = await fetch ( {
243
396
method : "POST" ,
244
- body : formData ,
397
+ body : getPartnerDetailsFormData ( ) ,
245
398
} ) ;
246
399
247
400
expect ( res . status ) . toBe ( 200 ) ;
0 commit comments