Skip to content

Commit 4b84cd3

Browse files
thomasyzy7Austin-Xminhhaitran08kevin-lannMasahisaSekita
authored
Ty/scrum 180 backend integration tests (#155)
Co-authored-by: Austin-X <[email protected]> Co-authored-by: minhhaitran08 <[email protected]> Co-authored-by: kevin-lann <[email protected]> Co-authored-by: Masahisa Sekita <[email protected]> Co-authored-by: Dmitriy Prokopchuk <[email protected]> Co-authored-by: Austin-X <[email protected]> Co-authored-by: dawangk <[email protected]> Co-authored-by: kevin-lann <[email protected]> Co-authored-by: MasahisaSekita <[email protected]> Co-authored-by: minhhaitran08 <[email protected]>
1 parent 27b05dc commit 4b84cd3

File tree

11 files changed

+1723
-146
lines changed

11 files changed

+1723
-146
lines changed

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

Lines changed: 407 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import request from "supertest";
1+
import { afterAll, describe, expect, it, jest } from "@jest/globals";
22
import { Request, Response } from "express";
3-
import { jest, describe, it, expect, afterAll } from "@jest/globals";
3+
import request from "supertest";
4+
45
import app, { server } from "../../src/index";
56

67
jest.mock("@ai-sdk/openai", () => ({
@@ -167,16 +168,18 @@ describe("Authentication API", () => {
167168

168169
describe("POST /auth/login", () => {
169170
it("should return 200 and a token for valid credentials", async () => {
170-
const response = await request(app)
171-
.post("/auth/login")
172-
.send({ email: "validUser", password: "validPassword" });
171+
const response = await request(app).post("/auth/login").send({
172+
email: "validUser",
173+
password: "validPassword",
174+
});
173175
expect(response.status).toBe(200);
174176
expect(response.body).toHaveProperty("token");
175177
});
176178
it("should return 401 for invalid credentials", async () => {
177-
const response = await request(app)
178-
.post("/auth/login")
179-
.send({ email: "invalidUser", password: "wrongPassword" });
179+
const response = await request(app).post("/auth/login").send({
180+
email: "invalidUser",
181+
password: "wrongPassword",
182+
});
180183
expect(response.status).toBe(401);
181184
expect(response.body).toHaveProperty("error", "Invalid credentials");
182185
});
@@ -237,7 +240,9 @@ describe("Authentication API", () => {
237240
it("should return 200 and a success message when email is provided", async () => {
238241
const response = await request(app)
239242
.post("/auth/request-password-reset")
240-
.send({ email: "[email protected]" });
243+
.send({
244+
245+
});
241246
expect(response.status).toBe(200);
242247
expect(response.body).toHaveProperty(
243248
"message",
@@ -256,9 +261,10 @@ describe("Authentication API", () => {
256261

257262
describe("POST /auth/reset-password", () => {
258263
it("should return 200 and a success message when password and token are provided", async () => {
259-
const response = await request(app)
260-
.post("/auth/reset-password")
261-
.send({ password: "newPassword123", token: "validToken" });
264+
const response = await request(app).post("/auth/reset-password").send({
265+
password: "newPassword123",
266+
token: "validToken",
267+
});
262268
expect(response.status).toBe(200);
263269
expect(response.body).toHaveProperty(
264270
"message",
@@ -267,9 +273,9 @@ describe("Authentication API", () => {
267273
});
268274

269275
it("should return 400 if password or token is missing", async () => {
270-
const response = await request(app)
271-
.post("/auth/reset-password")
272-
.send({ password: "newPassword123" });
276+
const response = await request(app).post("/auth/reset-password").send({
277+
password: "newPassword123",
278+
});
273279
expect(response.status).toBe(400);
274280
expect(response.body).toHaveProperty(
275281
"error",
@@ -280,9 +286,9 @@ describe("Authentication API", () => {
280286

281287
describe("DELETE /auth/accountDelete", () => {
282288
it("should return 200 and a success message when userId is provided", async () => {
283-
const response = await request(app)
284-
.delete("/auth/accountDelete")
285-
.send({ userId: "12345" });
289+
const response = await request(app).delete("/auth/accountDelete").send({
290+
userId: "12345",
291+
});
286292
expect(response.status).toBe(200);
287293
expect(response.body).toHaveProperty(
288294
"message",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { describe, expect, it, jest, test } from "@jest/globals";
2+
3+
import { supabase } from "../../src/db/setupDb";
4+
import getOfferings from "../../src/services/getOfferings";
5+
6+
jest.mock("../../src/db/setupDb", () => ({
7+
supabase: {
8+
schema: jest.fn(),
9+
},
10+
}));
11+
12+
type SupabaseQueryResult = Promise<{ data: any; error: any }>;
13+
14+
describe("getOfferings", () => {
15+
it("returns offering data for a valid course and semester", async () => {
16+
const mockData = [
17+
{
18+
id: 1,
19+
course_id: 123,
20+
meeting_section: "L01",
21+
offering: "Fall 2025",
22+
day: "Mon",
23+
start: "10:00",
24+
end: "11:00",
25+
location: "Room 101",
26+
current: 30,
27+
max: 40,
28+
is_waitlisted: false,
29+
delivery_mode: "In-Person",
30+
instructor: "Dr. Smith",
31+
notes: "",
32+
code: "ABC123",
33+
},
34+
];
35+
36+
// Build the method chain mock
37+
const eqMock2 = jest.fn<() => SupabaseQueryResult>().mockResolvedValue({
38+
data: mockData,
39+
error: null,
40+
});
41+
const eqMock1 = jest.fn(() => ({ eq: eqMock2 }));
42+
const selectMock = jest.fn(() => ({ eq: eqMock1 }));
43+
const fromMock = jest.fn(() => ({ select: selectMock }));
44+
const schemaMock = jest.fn(() => ({ from: fromMock }));
45+
46+
// Replace supabase.schema with our chain
47+
(supabase.schema as jest.Mock).mockImplementation(schemaMock);
48+
49+
// Act
50+
const result = await getOfferings(123, "Fall 2025");
51+
52+
// Assert
53+
expect(schemaMock).toHaveBeenCalledWith("course");
54+
expect(fromMock).toHaveBeenCalledWith("offerings");
55+
expect(selectMock).toHaveBeenCalled();
56+
expect(eqMock1).toHaveBeenCalledWith("course_id", 123);
57+
expect(eqMock2).toHaveBeenCalledWith("offering", "Fall 2025");
58+
expect(result).toEqual(mockData);
59+
});
60+
});

0 commit comments

Comments
 (0)