Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
27e31fa
Update team.md
thomasyzy7 Jan 23, 2025
daad2a4
Merge pull request #3 from UTSC-CSCC01-Software-Engineering-I/develop
Austin-X Jan 25, 2025
761a7eb
This commit tests if the main branch actually blocks force-pushes
Austin-X Jan 29, 2025
70578b8
Revert "This commit tests if the main branch actually blocks force-pu…
Austin-X Jan 29, 2025
a21f3e3
Release/0.1 - Main (#14)
thomasyzy7 Feb 1, 2025
ff98df3
[Hotfix]: Add missing section in README.md for "Tech Stack and Softwa…
Austin-X Feb 1, 2025
5024884
Release/1.0 - Main (#30)
thomasyzy7 Feb 15, 2025
813595b
Added Sprint0 Rubric + Grades + Deductions (#39)
prokopchukdim Feb 20, 2025
6def085
Added Sprint 1 Rubric / Grades (#49)
prokopchukdim Mar 2, 2025
2699f2a
Release/1.2 - Main (#60)
thomasyzy7 Mar 8, 2025
8f2672f
Release/1.3 [main] (#88)
kevin-lann Mar 22, 2025
f797fb3
Hotfix/1.0.4 [main] (#94)
kevin-lann Mar 22, 2025
5974f34
Sprint 2 rubric (#113)
prokopchukdim Mar 24, 2025
21f2214
Release/1.4 - Main (#126)
thomasyzy7 Mar 27, 2025
ab79531
Release/1.5 (#138)
thomasyzy7 Mar 30, 2025
63ed492
Kl/hotfix 1.0.5 - restriction form bug (#141)
kevin-lann Mar 30, 2025
00ea3fb
Hotfix/1.0.6 - main (#144)
thomasyzy7 Mar 31, 2025
543f8ca
refactored the test files in backend
thomasyzy7 Apr 3, 2025
39ef622
Auto-formatted the code using Prettier
Apr 3, 2025
004d238
refactored testing files
thomasyzy7 Apr 3, 2025
2450e8e
Merge branch 'ty/scrum-180-backend-integration-tests' of https://gith…
thomasyzy7 Apr 3, 2025
8bce802
Auto-formatted the code using Prettier
Apr 3, 2025
4483b62
getOfferings unit test
thomasyzy7 Apr 4, 2025
866de6e
Auto-formatted the code using Prettier
Apr 4, 2025
118dd4d
timetableGeneration progress
thomasyzy7 Apr 4, 2025
8ff7678
Merge branch 'ty/scrum-180-backend-integration-tests' of https://gith…
thomasyzy7 Apr 4, 2025
54648b8
Update db response for timetable integration test
minhhaitran08 Apr 4, 2025
5167eb8
Auto-formatted the code using Prettier
minhhaitran08 Apr 4, 2025
66db7ad
Merge branch 'ty/scrum-180-backend-integration-tests' of https://gith…
thomasyzy7 Apr 4, 2025
e4110d0
Auto-formatted the code using Prettier
Apr 4, 2025
a197849
generation completed!
thomasyzy7 Apr 4, 2025
f0a9b1a
Merge branch 'ty/scrum-180-backend-integration-tests' of https://gith…
thomasyzy7 Apr 4, 2025
3a18b7d
Auto-formatted the code using Prettier
Apr 4, 2025
1ce6663
Merge branch 'develop' of https://github.com/UTSC-CSCC01-Software-Eng…
thomasyzy7 Apr 4, 2025
ea61e26
Auto-formatted the code using Prettier
Apr 4, 2025
4f672c8
Update jest.config.ts
thomasyzy7 Apr 4, 2025
a2dee88
deleted bad merges
thomasyzy7 Apr 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

42 changes: 24 additions & 18 deletions course-matrix/backend/__tests__/unit-tests/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import request from "supertest";
import { afterAll, describe, expect, it, jest } from "@jest/globals";
import { Request, Response } from "express";
import { jest, describe, it, expect, afterAll } from "@jest/globals";
import request from "supertest";

import app, { server } from "../../src/index";

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

describe("POST /auth/login", () => {
it("should return 200 and a token for valid credentials", async () => {
const response = await request(app)
.post("/auth/login")
.send({ email: "validUser", password: "validPassword" });
const response = await request(app).post("/auth/login").send({
email: "validUser",
password: "validPassword",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("token");
});
it("should return 401 for invalid credentials", async () => {
const response = await request(app)
.post("/auth/login")
.send({ email: "invalidUser", password: "wrongPassword" });
const response = await request(app).post("/auth/login").send({
email: "invalidUser",
password: "wrongPassword",
});
expect(response.status).toBe(401);
expect(response.body).toHaveProperty("error", "Invalid credentials");
});
Expand Down Expand Up @@ -237,7 +240,9 @@ describe("Authentication API", () => {
it("should return 200 and a success message when email is provided", async () => {
const response = await request(app)
.post("/auth/request-password-reset")
.send({ email: "[email protected]" });
.send({
email: "[email protected]",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty(
"message",
Expand All @@ -256,9 +261,10 @@ describe("Authentication API", () => {

describe("POST /auth/reset-password", () => {
it("should return 200 and a success message when password and token are provided", async () => {
const response = await request(app)
.post("/auth/reset-password")
.send({ password: "newPassword123", token: "validToken" });
const response = await request(app).post("/auth/reset-password").send({
password: "newPassword123",
token: "validToken",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty(
"message",
Expand All @@ -267,9 +273,9 @@ describe("Authentication API", () => {
});

it("should return 400 if password or token is missing", async () => {
const response = await request(app)
.post("/auth/reset-password")
.send({ password: "newPassword123" });
const response = await request(app).post("/auth/reset-password").send({
password: "newPassword123",
});
expect(response.status).toBe(400);
expect(response.body).toHaveProperty(
"error",
Expand All @@ -280,9 +286,9 @@ describe("Authentication API", () => {

describe("DELETE /auth/accountDelete", () => {
it("should return 200 and a success message when userId is provided", async () => {
const response = await request(app)
.delete("/auth/accountDelete")
.send({ userId: "12345" });
const response = await request(app).delete("/auth/accountDelete").send({
userId: "12345",
});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty(
"message",
Expand Down
60 changes: 60 additions & 0 deletions course-matrix/backend/__tests__/unit-tests/getOfferings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, expect, it, jest, test } from "@jest/globals";

import { supabase } from "../../src/db/setupDb";
import getOfferings from "../../src/services/getOfferings";

jest.mock("../../src/db/setupDb", () => ({
supabase: {
schema: jest.fn(),
},
}));

type SupabaseQueryResult = Promise<{ data: any; error: any }>;

describe("getOfferings", () => {
it("returns offering data for a valid course and semester", async () => {
const mockData = [
{
id: 1,
course_id: 123,
meeting_section: "L01",
offering: "Fall 2025",
day: "Mon",
start: "10:00",
end: "11:00",
location: "Room 101",
current: 30,
max: 40,
is_waitlisted: false,
delivery_mode: "In-Person",
instructor: "Dr. Smith",
notes: "",
code: "ABC123",
},
];

// Build the method chain mock
const eqMock2 = jest.fn<() => SupabaseQueryResult>().mockResolvedValue({
data: mockData,
error: null,
});
const eqMock1 = jest.fn(() => ({ eq: eqMock2 }));
const selectMock = jest.fn(() => ({ eq: eqMock1 }));
const fromMock = jest.fn(() => ({ select: selectMock }));
const schemaMock = jest.fn(() => ({ from: fromMock }));

// Replace supabase.schema with our chain
(supabase.schema as jest.Mock).mockImplementation(schemaMock);

// Act
const result = await getOfferings(123, "Fall 2025");

// Assert
expect(schemaMock).toHaveBeenCalledWith("course");
expect(fromMock).toHaveBeenCalledWith("offerings");
expect(selectMock).toHaveBeenCalled();
expect(eqMock1).toHaveBeenCalledWith("course_id", 123);
expect(eqMock2).toHaveBeenCalledWith("offering", "Fall 2025");
expect(result).toEqual(mockData);
});
});
Loading