Skip to content

Commit 54648b8

Browse files
committed
Update db response for timetable integration test
1 parent 866de6e commit 54648b8

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import { supabase } from "../../src/db/setupDb";
1515
import { Json } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/db_control";
1616
import app from "../../src/index";
1717
import { server } from "../../src/index";
18+
import getOfferings from "../../src/services/getOfferings";
1819

1920
const USER1 = "testuser01-ab9e6877-f603-4c6a-9832-864e520e4d01";
2021
const USER2 = "testuser02-1d3f02df-f926-4c1f-9f41-58ca50816a33";
2122
const USER3 = "testuser03-f84fd0da-d775-4424-ad88-d9675282453c";
2223
const USER4 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
24+
//USER5 is saved for courseOffering query do not use for anyother test
25+
const USER5 = "testuser04-f84fd0da-d775-4424-ad88-d9675282453c";
2326

2427
//Handle AI import from index.ts
2528
jest.mock("@ai-sdk/openai", () => ({
@@ -79,6 +82,58 @@ const mockTimetables1 = [
7982
},
8083
];
8184

85+
//Mock list of offering
86+
const offering1 = [
87+
{
88+
id:1,
89+
course_id:101,
90+
day:"MO",
91+
start:"10:00:00",
92+
end:"11:00:00",
93+
},
94+
{
95+
id:2,
96+
course_id:101,
97+
day:"WE",
98+
start:"10:00:00",
99+
end:"11:00:00",
100+
},
101+
{
102+
id:3,
103+
course_id:101,
104+
day:"FR",
105+
start:"10:00:00",
106+
end:"11:00:00",
107+
}
108+
]
109+
110+
const offering2 = [
111+
{
112+
id:1,
113+
course_id:102,
114+
day:"MO",
115+
start:"10:00:00",
116+
end:"12:00:00",
117+
}
118+
]
119+
120+
const offering3 = [
121+
{
122+
id:1,
123+
course_id:103,
124+
day:"TU",
125+
start:"15:00:00",
126+
end:"17:00:00",
127+
},
128+
{
129+
id:2,
130+
course_id:103,
131+
day:"WE",
132+
start:"15:00:00",
133+
end:"17:00:00",
134+
},
135+
]
136+
82137
// Spy on the getTimetables method
83138
jest
84139
.spyOn(timetablesController, "getTimetables")
@@ -143,6 +198,30 @@ jest.mock("../../src/db/setupDb", () => ({
143198
}),
144199
};
145200
}
201+
//DB response with offering1 if courseID = 101 in request
202+
if(key === "course_id" && value === 101){
203+
return{
204+
eq:jest.fn().mockImplementation(() => {
205+
return{data: offering1, error: null}
206+
})
207+
}
208+
}
209+
//DB response with offering1 if courseID = 102 in request
210+
if(key === "course_id" && value === 102){
211+
return{
212+
eq:jest.fn().mockImplementation(() => {
213+
return{data: offering2, error: null}
214+
})
215+
}
216+
}
217+
//DB response with offering1 if courseID = 103 in request
218+
if(key === "course_id" && value === 103){
219+
return{
220+
eq:jest.fn().mockImplementation(() => {
221+
return{data: offering1, error: null}
222+
})
223+
}
224+
}
146225
}),
147226
// Mock db response to .insert query command
148227
insert: jest.fn().mockImplementation((data: Json) => {
@@ -190,3 +269,15 @@ jest.mock("../../src/db/setupDb", () => ({
190269
}),
191270
},
192271
}));
272+
273+
//Test block
274+
describe("Simple test case for offering", () => {
275+
beforeEach(() => {
276+
jest.clearAllMocks();
277+
});
278+
279+
test("should return offering1", async() => {
280+
const response = await getOfferings(101, "Spring")
281+
expect(response).toEqual(offering1)
282+
})
283+
})

0 commit comments

Comments
 (0)