Skip to content

Commit d9fcf9f

Browse files
committed
Use correct schema
1 parent 5780bc8 commit d9fcf9f

File tree

2 files changed

+213
-69
lines changed

2 files changed

+213
-69
lines changed

src/app/api/partnerDetails/[userId]/route.test.ts

+200-47
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,181 @@ import * as appHandler from "./route";
66
import { expect, test } from "@jest/globals";
77
import { dbMock } from "@/test/dbMock";
88
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+
};
10184

11185
test("returns 401 on invalid session", async () => {
12186
await testApiHandler({
@@ -56,7 +230,7 @@ test("returns 404 on not found", async () => {
56230
});
57231

58232
// Mock record not found
59-
dbMock.partnerDetails.findUnique.mockResolvedValueOnce(null);
233+
dbMock.user.findUnique.mockResolvedValueOnce(null);
60234

61235
const res = await fetch({ method: "GET", body: null });
62236
await expect(res.status).toBe(404);
@@ -77,22 +251,19 @@ test("returns 200 and correct details on success when partner + id matches", asy
77251
expires: "",
78252
});
79253

80-
const exampleDetails = {
81-
numberOfPatients: 10,
82-
organizationType: OrganizationType.NON_PROFIT,
83-
};
84-
85254
// 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+
});
89263

90264
const res = await fetch({ method: "GET", body: null });
91265
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());
96267
},
97268
});
98269
});
@@ -107,22 +278,19 @@ test("returns 200 and correct details on success when staff matches", async () =
107278
expires: "",
108279
});
109280

110-
const exampleDetails = {
111-
numberOfPatients: 10,
112-
organizationType: OrganizationType.NON_PROFIT,
113-
};
114-
115281
// 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+
});
119290

120291
const res = await fetch({ method: "GET", body: null });
121292
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());
126294
},
127295
});
128296
});
@@ -132,17 +300,13 @@ describe("POST /api/partnerDetails/[userId]", () => {
132300
test("returns 401 when there is no valid session", async () => {
133301
authMock.mockReturnValueOnce(null); //no valid session
134302

135-
const formData = new FormData();
136-
formData.append("numberOfPatients", "8");
137-
formData.append("organizationType", "NON_PROFIT");
138-
139303
await testApiHandler({
140304
appHandler,
141305
params: { userId: "1" },
142306
async test({ fetch }) {
143307
const res = await fetch({
144308
method: "POST",
145-
body: formData,
309+
body: getPartnerDetailsFormData(),
146310
});
147311

148312
expect(res.status).toBe(401);
@@ -159,17 +323,13 @@ describe("POST /api/partnerDetails/[userId]", () => {
159323
expires: "",
160324
});
161325

162-
const formData = new FormData();
163-
formData.append("numberOfPatients", "8");
164-
formData.append("organizationType", "NON_PROFIT");
165-
166326
await testApiHandler({
167327
appHandler,
168328
params: { userId: "2" }, //different user
169329
async test({ fetch }) {
170330
const res = await fetch({
171331
method: "POST",
172-
body: formData,
332+
body: getPartnerDetailsFormData(),
173333
});
174334

175335
expect(res.status).toBe(403);
@@ -215,33 +375,26 @@ describe("POST /api/partnerDetails/[userId]", () => {
215375
expires: "",
216376
});
217377

218-
const updatedPartnerDetails = {
219-
numberOfPatients: 5,
220-
organizationType: "NON_PROFIT" as OrganizationType,
221-
};
378+
const updatedPartnerDetails = getValidPartnerDetails();
222379

223380
const updatedUser = {
224381
id: 1,
225382
email: "test_email",
226383
name: "test_name",
227384
passwordHash: "test_hash",
228385
type: UserType.SUPER_ADMIN,
229-
partnerDetails: updatedPartnerDetails
230-
}
386+
partnerDetails: updatedPartnerDetails,
387+
};
231388

232389
dbMock.user.update.mockResolvedValueOnce(updatedUser);
233390

234-
const formData = new FormData();
235-
formData.append("numberOfPatients", "5");
236-
formData.append("organizationType", "NON_PROFIT");
237-
238391
await testApiHandler({
239392
appHandler,
240393
params: { userId: "1" },
241394
async test({ fetch }) {
242395
const res = await fetch({
243396
method: "POST",
244-
body: formData,
397+
body: getPartnerDetailsFormData(),
245398
});
246399

247400
expect(res.status).toBe(200);

0 commit comments

Comments
 (0)