Skip to content

Commit 8f2672f

Browse files
kevin-lannthomasyzy7Austin-Xminhhaitran08MasahisaSekita
authored
Release/1.3 [main] (#88)
Co-authored-by: dawangk <[email protected]> Co-authored-by: Austin-X <[email protected]> Co-authored-by: minhhaitran08 <[email protected]> Co-authored-by: Masahisa Sekita <[email protected]> Co-authored-by: dawangk <[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: Dmitriy Prokopchuk <[email protected]>
1 parent 2699f2a commit 8f2672f

File tree

111 files changed

+9418
-696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+9418
-696
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ The `DATABASE_URL` variable should contain your Supabase project url and the `DA
6161

6262
```
6363
VITE_SERVER_URL="http://localhost:8081"
64+
VITE_PUBLIC_ASSISTANT_BASE_URL=[Insert vite public assistant bas URL]
65+
VITE_ASSISTANT_UI_KEY=[Insert vite assistant UI key]
6466
```
6567

6668
### Running the Application
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { analyzeQuery } from "../src/utils/analyzeQuery";
2+
import { describe, test, expect, jest } from "@jest/globals";
3+
import {
4+
NAMESPACE_KEYWORDS,
5+
ASSISTANT_TERMS,
6+
DEPARTMENT_CODES,
7+
} from "../src/constants/promptKeywords";
8+
9+
// Mock the constants if needed
10+
jest.mock("../src/constants/promptKeywords", () => ({
11+
NAMESPACE_KEYWORDS: {
12+
courses_v3: ["course", "class", "description"],
13+
offerings: ["offering", "schedule", "timetable"],
14+
prerequisites: ["prerequisite", "prereq"],
15+
corequisites: ["corequisite", "coreq"],
16+
departments: ["department", "faculty"],
17+
programs: ["program", "major", "minor"],
18+
},
19+
ASSISTANT_TERMS: ["you", "your", "morpheus", "assistant"],
20+
DEPARTMENT_CODES: ["cs", "math", "eng"],
21+
GENERAL_ACADEMIC_TERMS: ["academic", "study", "education"],
22+
}));
23+
24+
describe("analyzeQuery", () => {
25+
test("should return no search required for assistant-related queries", () => {
26+
const result = analyzeQuery("Can you help me with something?");
27+
expect(result).toEqual({
28+
requiresSearch: false,
29+
relevantNamespaces: [],
30+
});
31+
});
32+
33+
test("should detect course-related keywords and return appropriate namespaces", () => {
34+
const result = analyzeQuery("Tell me about this course");
35+
expect(result.requiresSearch).toBe(true);
36+
expect(result.relevantNamespaces).toContain("courses_v3");
37+
});
38+
39+
test("should detect course codes and include relevant namespaces", () => {
40+
const result = analyzeQuery("What is CSC108 about?");
41+
expect(result.requiresSearch).toBe(true);
42+
expect(result.relevantNamespaces).toContain("courses_v3");
43+
expect(result.relevantNamespaces).toContain("offerings");
44+
expect(result.relevantNamespaces).toContain("prerequisites");
45+
});
46+
47+
test("should detect department codes and include relevant namespaces", () => {
48+
const result = analyzeQuery("What math courses are available?");
49+
expect(result.requiresSearch).toBe(true);
50+
expect(result.relevantNamespaces).toContain("departments");
51+
expect(result.relevantNamespaces).toContain("courses_v3");
52+
});
53+
54+
test("should detect offering-related keywords", () => {
55+
const result = analyzeQuery("What is the schedule for winter semester?");
56+
expect(result.requiresSearch).toBe(true);
57+
expect(result.relevantNamespaces).toContain("offerings");
58+
});
59+
60+
test("should detect prerequisite-related keywords", () => {
61+
const result = analyzeQuery("What are the prerequisites for this class?");
62+
expect(result.requiresSearch).toBe(true);
63+
expect(result.relevantNamespaces).toContain("prerequisites");
64+
});
65+
66+
test("should detect corequisite-related keywords", () => {
67+
const result = analyzeQuery("Are there any corequisites for this course?");
68+
expect(result.requiresSearch).toBe(true);
69+
expect(result.relevantNamespaces).toContain("corequisites");
70+
});
71+
72+
test("should return all namespaces when search is required but no specific namespaces identified", () => {
73+
// Assuming GENERAL_ACADEMIC_TERMS includes 'academic'
74+
const result = analyzeQuery("I need academic information");
75+
expect(result.requiresSearch).toBe(true);
76+
expect(result.relevantNamespaces).toEqual([
77+
"courses_v3",
78+
"offerings",
79+
"prerequisites",
80+
"corequisites",
81+
"departments",
82+
"programs",
83+
]);
84+
});
85+
86+
test("should be case insensitive", () => {
87+
const result = analyzeQuery("TELL ME ABOUT THIS COURSE");
88+
expect(result.requiresSearch).toBe(true);
89+
expect(result.relevantNamespaces).toContain("courses_v3");
90+
});
91+
92+
test("should detect multiple namespaces in a single query", () => {
93+
const result = analyzeQuery(
94+
"What are the prerequisites and schedule for CSC108?",
95+
);
96+
expect(result.requiresSearch).toBe(true);
97+
expect(result.relevantNamespaces).toContain("prerequisites");
98+
expect(result.relevantNamespaces).toContain("offerings");
99+
expect(result.relevantNamespaces).toContain("courses_v3");
100+
});
101+
102+
test("should correctly identify course codes with different formats", () => {
103+
const formats = [
104+
"CSC108", // Standard format
105+
"CSC108H", // With suffix
106+
"CSCA08", // Four letters
107+
"MAT224", // Different department
108+
"ECO100Y", // Another format
109+
];
110+
111+
formats.forEach((code) => {
112+
const result = analyzeQuery(`Tell me about ${code}`);
113+
expect(result.requiresSearch).toBe(true);
114+
expect(result.relevantNamespaces).toContain("courses_v3");
115+
expect(result.relevantNamespaces).toContain("offerings");
116+
expect(result.relevantNamespaces).toContain("prerequisites");
117+
});
118+
});
119+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import request from "supertest";
2+
import { describe, expect, it, test } from "@jest/globals";
3+
import app from "../src/index";
4+
5+
describe("Authentication API", () => {
6+
// The unit tests below are currently commented out because they require a database connection.
7+
// They will be uncommented out once all the necessary mocks are in place.
8+
9+
// describe('POST /auth/login', () => {
10+
// it('should return 200 and a token for valid credentials', async () => {
11+
// const response = await request(app)
12+
// .post('/auth/login')
13+
// .send({ username: 'validUser', password: 'validPassword' });
14+
// expect(response.status).toBe(200);
15+
// expect(response.body).toHaveProperty('token');
16+
// });
17+
// it('should return 401 for invalid credentials', async () => {
18+
// const response = await request(app)
19+
// .post('/auth/login')
20+
// .send({ username: 'invalidUser', password: 'wrongPassword' });
21+
// expect(response.status).toBe(401);
22+
// expect(response.body).toHaveProperty('error', 'Invalid credentials');
23+
// });
24+
// it('should return 400 if username or password is missing', async () => {
25+
// const response = await request(app)
26+
// .post('/auth/login')
27+
// .send({ username: 'validUser' });
28+
// expect(response.status).toBe(400);
29+
// expect(response.body).toHaveProperty('error', 'Username and password are required');
30+
// });
31+
// });
32+
// describe('POST /auth/register', () => {
33+
// it('should return 201 and create a new user for valid input', async () => {
34+
// const response = await request(app)
35+
// .post('/auth/register')
36+
// .send({ username: 'newUser', password: 'newPassword' });
37+
// expect(response.status).toBe(201);
38+
// expect(response.body).toHaveProperty('message', 'User registered successfully');
39+
// });
40+
// it('should return 400 if username is already taken', async () => {
41+
// await request(app)
42+
// .post('/auth/register')
43+
// .send({ username: 'existingUser', password: 'password123' });
44+
// const response = await request(app)
45+
// .post('/auth/register')
46+
// .send({ username: 'existingUser', password: 'password123' });
47+
// expect(response.status).toBe(400);
48+
// expect(response.body).toHaveProperty('error', 'Username is already taken');
49+
// });
50+
// it('should return 400 if username or password is missing', async () => {
51+
// const response = await request(app)
52+
// .post('/auth/register')
53+
// .send({ username: '' });
54+
// expect(response.status).toBe(400);
55+
// expect(response.body).toHaveProperty('error', 'Username and password are required');
56+
// });
57+
// });
58+
// describe('GET /auth/profile', () => {
59+
// it('should return 200 and user profile for valid token', async () => {
60+
// const loginResponse = await request(app)
61+
// .post('/auth/login')
62+
// .send({ username: 'validUser', password: 'validPassword' });
63+
// const token = loginResponse.body.token;
64+
// const response = await request(app)
65+
// .get('/auth/profile')
66+
// .set('Authorization', `Bearer ${token}`);
67+
// expect(response.status).toBe(200);
68+
// expect(response.body).toHaveProperty('username', 'validUser');
69+
// });
70+
// it('should return 401 if token is missing or invalid', async () => {
71+
// const response = await request(app)
72+
// .get('/auth/profile')
73+
// .set('Authorization', 'Bearer invalidToken');
74+
// expect(response.status).toBe(401);
75+
// expect(response.body).toHaveProperty('error', 'Unauthorized');
76+
// });
77+
// });
78+
it("template test", () => {
79+
expect(2 + 3).toEqual(5);
80+
});
81+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { describe, expect, it, test } from "@jest/globals";
2+
3+
import { createOffering, canInsert } from "../src/utils/generatorHelpers";
4+
import { Offering } from "../src/types/generatorTypes";
5+
6+
describe("canInsert function", () => {
7+
const offering1: Offering = createOffering({
8+
id: 1,
9+
course_id: 101,
10+
day: "MO",
11+
start: "09:00:00",
12+
end: "10:00:00",
13+
});
14+
const offering2: Offering = createOffering({
15+
id: 2,
16+
course_id: 102,
17+
day: "MO",
18+
start: "10:00:00",
19+
end: "11:00:00",
20+
});
21+
const offering3: Offering = createOffering({
22+
id: 3,
23+
course_id: 103,
24+
day: "MO",
25+
start: "11:00:00",
26+
end: "12:00:00",
27+
});
28+
29+
it("should return true if there is no overlap with existing offerings", async () => {
30+
const toInsert: Offering = createOffering({
31+
id: 4,
32+
course_id: 104,
33+
day: "MO",
34+
start: "12:00:00",
35+
end: "13:00:00",
36+
});
37+
const curList: Offering[] = [offering1, offering2, offering3];
38+
39+
const result = await canInsert(toInsert, curList);
40+
41+
expect(result).toBe(true); // No overlap, should return true
42+
});
43+
44+
it("should return false if there is an overlap with an existing offering", async () => {
45+
const toInsert: Offering = createOffering({
46+
id: 4,
47+
course_id: 104,
48+
day: "MO",
49+
start: "09:30:00",
50+
end: "10:30:00",
51+
});
52+
const curList: Offering[] = [offering1, offering2, offering3];
53+
54+
const result = await canInsert(toInsert, curList);
55+
56+
expect(result).toBe(false); // There is an overlap with offering1, should return false
57+
});
58+
59+
it("should return true if the new offering starts after the last one ends", async () => {
60+
const toInsert: Offering = createOffering({
61+
id: 4,
62+
course_id: 104,
63+
day: "MO",
64+
start: "13:00:00",
65+
end: "14:00:00",
66+
});
67+
const curList: Offering[] = [offering1, offering2, offering3];
68+
69+
const result = await canInsert(toInsert, curList);
70+
71+
expect(result).toBe(true); // No overlap, should return true
72+
});
73+
74+
it("should return true if the new offering ends before the first one starts", async () => {
75+
const toInsert: Offering = createOffering({
76+
id: 4,
77+
course_id: 104,
78+
day: "MO",
79+
start: "07:00:00",
80+
end: "08:00:00",
81+
});
82+
const curList: Offering[] = [offering1, offering2, offering3];
83+
84+
const result = await canInsert(toInsert, curList);
85+
86+
expect(result).toBe(true); // No overlap, should return true
87+
});
88+
89+
it("should return false if the new offering is completely inside an existing one", async () => {
90+
const toInsert: Offering = createOffering({
91+
id: 4,
92+
course_id: 104,
93+
day: "MO",
94+
start: "09:30:00",
95+
end: "09:45:00",
96+
});
97+
const curList: Offering[] = [offering1, offering2, offering3];
98+
99+
const result = await canInsert(toInsert, curList);
100+
101+
expect(result).toBe(false); // Overlaps with offering1, should return false
102+
});
103+
104+
it("should return true if the day is different (no overlap)", async () => {
105+
const toInsert: Offering = createOffering({
106+
id: 4,
107+
course_id: 104,
108+
day: "TU",
109+
start: "09:00:00",
110+
end: "10:00:00",
111+
});
112+
const curList: Offering[] = [offering1, offering2, offering3];
113+
114+
const result = await canInsert(toInsert, curList);
115+
116+
expect(result).toBe(true); // Different day, no overlap
117+
});
118+
});

0 commit comments

Comments
 (0)