Skip to content

Commit 8bce802

Browse files
dawangkgithub-actions[bot]
authored andcommitted
Auto-formatted the code using Prettier
1 parent 2450e8e commit 8bce802

File tree

3 files changed

+21
-79
lines changed

3 files changed

+21
-79
lines changed

course-matrix/backend/__tests__/integration-tests/timetableIntegration.test.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import { server } from "../../src/index";
1919
const USER1 = "testuser01-ab9e6877-f603-4c6a-9832-864e520e4d01";
2020
const USER2 = "testuser02-1d3f02df-f926-4c1f-9f41-58ca50816a33";
2121
const USER3 = "testuser03-f84fd0da-d775-4424-ad88-d9675282453c";
22-
const USER4 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
23-
22+
const USER4 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
2423

2524
//Handle AI import from index.ts
2625
jest.mock("@ai-sdk/openai", () => ({
@@ -111,27 +110,18 @@ jest.mock("../../src/db/setupDb", () => ({
111110
eq: jest.fn().mockImplementation((key, value) => {
112111
//Each test case is codded by the user_id in session
113112
//DB response 1: Query user timetable return non null value
114-
if (
115-
key === "user_id" &&
116-
value === USER1
117-
) {
113+
if (key === "user_id" && value === USER1) {
118114
// Return mock data when user_id matches
119115
return { data: mockTimetables1, error: null };
120116
}
121117
//DB response 2: Query user timetable return null value
122-
if (
123-
key === "user_id" &&
124-
value === USER2
125-
) {
118+
if (key === "user_id" && value === USER2) {
126119
// Return null for this user_id
127120
return { data: null, error: null };
128121
}
129122

130123
//DB response 3: Combine .eq and .maybeSingle to signify that the return value could be single: Return non null value
131-
if (
132-
key === "user_id" &&
133-
value === USER3
134-
) {
124+
if (key === "user_id" && value === USER3) {
135125
return {
136126
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
137127
maybeSingle: jest.fn().mockImplementation(() => {
@@ -140,10 +130,7 @@ jest.mock("../../src/db/setupDb", () => ({
140130
};
141131
}
142132
//DB response 4: Combine .eq and .maybeSingle to signify that the return value could be single: Return null value
143-
if (
144-
key === "user_id" &&
145-
value === USER4
146-
) {
133+
if (key === "user_id" && value === USER4) {
147134
return {
148135
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
149136
neq: jest.fn().mockImplementation(() => ({
@@ -160,10 +147,7 @@ jest.mock("../../src/db/setupDb", () => ({
160147
// Mock db response to .insert query command
161148
insert: jest.fn().mockImplementation((data: Json) => {
162149
//DB response 5: Create timetable successfully, new timetable data is responded
163-
if (
164-
data &&
165-
data[0].user_id === USER3
166-
) {
150+
if (data && data[0].user_id === USER3) {
167151
return {
168152
select: jest.fn().mockImplementation(() => {
169153
// Return the input data when select is called
@@ -206,4 +190,3 @@ jest.mock("../../src/db/setupDb", () => ({
206190
}),
207191
},
208192
}));
209-

course-matrix/backend/__tests__/unit-tests/restrictionsController.test.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ jest.mock("../../src/db/setupDb", () => ({
142142
};
143143
}
144144
//DB response 4: Combine .eq and .maybeSingle to signify that the return value could be single: Return null value
145-
if (
146-
key === "user_id" &&
147-
value === USER1
148-
) {
145+
if (key === "user_id" && value === USER1) {
149146
return {
150147
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
151148
maybeSingle: jest.fn().mockImplementation(() => {
@@ -154,10 +151,7 @@ jest.mock("../../src/db/setupDb", () => ({
154151
};
155152
}
156153

157-
if (
158-
key === "user_id" &&
159-
value === USER2
160-
) {
154+
if (key === "user_id" && value === USER2) {
161155
return {
162156
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
163157
maybeSingle: jest.fn().mockImplementation(() => {
@@ -191,10 +185,7 @@ jest.mock("../../src/db/setupDb", () => ({
191185
}),
192186
};
193187
}
194-
if (
195-
key === "user_id" &&
196-
value === USER1
197-
) {
188+
if (key === "user_id" && value === USER1) {
198189
return {
199190
eq: jest.fn().mockImplementation((key, value) => {
200191
if (key === "calendar_id" && value === "1") {
@@ -203,10 +194,7 @@ jest.mock("../../src/db/setupDb", () => ({
203194
}),
204195
};
205196
}
206-
if (
207-
key === "user_id" &&
208-
value === USER2
209-
) {
197+
if (key === "user_id" && value === USER2) {
210198
return {
211199
eq: jest.fn().mockImplementation((key, value) => {
212200
if (key === "calendar_id" && value === "1") {
@@ -224,11 +212,7 @@ jest.mock("../../src/db/setupDb", () => ({
224212
}),
225213
insert: jest.fn().mockImplementation((data: Json) => {
226214
//DB response 5: Create timetable successfully, new timetable data is responded
227-
if (
228-
data &&
229-
data[0].user_id ===
230-
USER1
231-
) {
215+
if (data && data[0].user_id === USER1) {
232216
return {
233217
select: jest.fn().mockImplementation(() => {
234218
// Return the input data when select is called
@@ -263,10 +247,7 @@ jest.mock("../../src/db/setupDb", () => ({
263247
//DB response 9: Delete timetable successfully
264248
return {
265249
eq: jest.fn().mockImplementation((key, value) => {
266-
if (
267-
key === "user_id" &&
268-
value === USER2
269-
) {
250+
if (key === "user_id" && value === USER2) {
270251
return {
271252
eq: jest.fn().mockReturnThis(),
272253
data: null,
@@ -305,9 +286,7 @@ describe("GET /api/timetables/restrictions/:id", () => {
305286
// Initialize the authenticated session
306287
(
307288
authHandler as jest.MockedFunction<typeof authHandler>
308-
).mockImplementationOnce(
309-
mockAuthHandler(USER1),
310-
);
289+
).mockImplementationOnce(mockAuthHandler(USER1));
311290

312291
const response = await request(app).get("/api/timetables/restrictions/1");
313292

course-matrix/backend/__tests__/unit-tests/timetablesController.test.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { server } from "../../src/index";
1818
const USER1 = "testuser01-ab9e6877-f603-4c6a-9832-864e520e4d01";
1919
const USER2 = "testuser02-1d3f02df-f926-4c1f-9f41-58ca50816a33";
2020
const USER3 = "testuser03-f84fd0da-d775-4424-ad88-d9675282453c";
21-
const USER4 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
22-
21+
const USER4 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
2322

2423
//Handle AI import from index.ts
2524
jest.mock("@ai-sdk/openai", () => ({
@@ -110,27 +109,18 @@ jest.mock("../../src/db/setupDb", () => ({
110109
eq: jest.fn().mockImplementation((key, value) => {
111110
//Each test case is codded by the user_id in session
112111
//DB response 1: Query user timetable return non null value
113-
if (
114-
key === "user_id" &&
115-
value === USER1
116-
) {
112+
if (key === "user_id" && value === USER1) {
117113
// Return mock data when user_id matches
118114
return { data: mockTimetables1, error: null };
119115
}
120116
//DB response 2: Query user timetable return null value
121-
if (
122-
key === "user_id" &&
123-
value === USER2
124-
) {
117+
if (key === "user_id" && value === USER2) {
125118
// Return null for this user_id
126119
return { data: null, error: null };
127120
}
128121

129122
//DB response 3: Combine .eq and .maybeSingle to signify that the return value could be single: Return non null value
130-
if (
131-
key === "user_id" &&
132-
value === USER3
133-
) {
123+
if (key === "user_id" && value === USER3) {
134124
return {
135125
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
136126
maybeSingle: jest.fn().mockImplementation(() => {
@@ -139,10 +129,7 @@ jest.mock("../../src/db/setupDb", () => ({
139129
};
140130
}
141131
//DB response 4: Combine .eq and .maybeSingle to signify that the return value could be single: Return null value
142-
if (
143-
key === "user_id" &&
144-
value === USER4
145-
) {
132+
if (key === "user_id" && value === USER4) {
146133
return {
147134
eq: jest.fn().mockReturnThis(), // Allow further chaining of eq if required
148135
neq: jest.fn().mockImplementation(() => ({
@@ -159,10 +146,7 @@ jest.mock("../../src/db/setupDb", () => ({
159146
// Mock db response to .insert query command
160147
insert: jest.fn().mockImplementation((data: Json) => {
161148
//DB response 5: Create timetable successfully, new timetable data is responded
162-
if (
163-
data &&
164-
data[0].user_id === USER3
165-
) {
149+
if (data && data[0].user_id === USER3) {
166150
return {
167151
select: jest.fn().mockImplementation(() => {
168152
// Return the input data when select is called
@@ -216,9 +200,7 @@ describe("GET /api/timetables", () => {
216200
// Initialize the authenticated session
217201
(
218202
authHandler as jest.MockedFunction<typeof authHandler>
219-
).mockImplementationOnce(
220-
mockAuthHandler(USER1),
221-
);
203+
).mockImplementationOnce(mockAuthHandler(USER1));
222204

223205
const response = await request(app).get("/api/timetables");
224206

@@ -231,9 +213,7 @@ describe("GET /api/timetables", () => {
231213
// Initialize the authenticated session
232214
(
233215
authHandler as jest.MockedFunction<typeof authHandler>
234-
).mockImplementationOnce(
235-
mockAuthHandler(USER2),
236-
);
216+
).mockImplementationOnce(mockAuthHandler(USER2));
237217

238218
const response = await request(app).get("/api/timetables");
239219
// Verify the response status and error message

0 commit comments

Comments
 (0)