Skip to content

Commit a197849

Browse files
committed
generation completed!
1 parent 66db7ad commit a197849

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {afterAll, beforeEach, describe, expect, jest, test,} from '@jest/globals';
1+
import {afterAll, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
22
import {Json} from '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/db_control';
33
import {NextFunction, Request, Response} from 'express';
44
import request from 'supertest';
@@ -87,20 +87,23 @@ const offering1 = [
8787
{
8888
id: 1,
8989
course_id: 101,
90+
meeting_section: 'LEC01',
9091
day: 'MO',
9192
start: '10:00:00',
9293
end: '11:00:00',
9394
},
9495
{
9596
id: 2,
9697
course_id: 101,
98+
meeting_section: 'LEC02',
9799
day: 'WE',
98100
start: '10:00:00',
99101
end: '11:00:00',
100102
},
101103
{
102104
id: 3,
103105
course_id: 101,
106+
meeting_section: 'LEC03',
104107
day: 'FR',
105108
start: '10:00:00',
106109
end: '11:00:00',
@@ -289,3 +292,104 @@ describe('Simple test case for offering', () => {
289292
expect(response).toEqual(offering1);
290293
});
291294
});
295+
296+
// Test block
297+
describe('Testing timetable generation', () => {
298+
beforeEach(() => {
299+
jest.clearAllMocks();
300+
});
301+
302+
303+
test('Generate for 1 course', async () => {
304+
// Mock authHandler to simulate the user being logged in
305+
(authHandler as jest.MockedFunction<typeof authHandler>)
306+
.mockImplementationOnce(mockAuthHandler(USER5));
307+
const response =
308+
await request(app)
309+
.post('/api/timetables/generate')
310+
.send({courses: [{id: 101}], semester: 'Spring', restrictions: []})
311+
.expect(200);
312+
expect(JSON.parse(response.text).amount)
313+
.toEqual(3); // 3 timetables should be generated.
314+
});
315+
316+
test('Generate for 2 courses, no conflict', async () => {
317+
// Mock authHandler to simulate the user being logged in
318+
(authHandler as jest.MockedFunction<typeof authHandler>)
319+
.mockImplementationOnce(mockAuthHandler(USER5));
320+
const response = await request(app)
321+
.post('/api/timetables/generate')
322+
.send({
323+
courses: [{id: 101}, {id: 103}],
324+
semester: 'Spring',
325+
restrictions: []
326+
})
327+
.expect(200);
328+
expect(JSON.parse(response.text).amount)
329+
.toEqual(6); // 6 timetables should be generated.
330+
});
331+
332+
test('Generate for 2 courses, conflict', async () => {
333+
// Mock authHandler to simulate the user being logged in
334+
(authHandler as jest.MockedFunction<typeof authHandler>)
335+
.mockImplementationOnce(mockAuthHandler(USER5));
336+
const response = await request(app)
337+
.post('/api/timetables/generate')
338+
.send({
339+
courses: [{id: 101}, {id: 102}],
340+
semester: 'Spring',
341+
restrictions: []
342+
})
343+
.expect(200);
344+
expect(JSON.parse(response.text).amount).toEqual(2);
345+
});
346+
347+
test('Generate for 1 course, bad restriction', async () => {
348+
// Mock authHandler to simulate the user being logged in
349+
(authHandler as jest.MockedFunction<typeof authHandler>)
350+
.mockImplementationOnce(mockAuthHandler(USER5));
351+
const response = await request(app)
352+
.post('/api/timetables/generate')
353+
.send({
354+
courses: [{id: 101}],
355+
semester: 'Spring',
356+
restrictions: [{
357+
type: 'Restrict Before',
358+
days: ['MO', 'TU', 'WE', 'TH', 'FR'],
359+
endTime: '21:00:00',
360+
disabled: false
361+
}]
362+
})
363+
.expect(404);
364+
});
365+
366+
test(
367+
'Generate for 1 course w/ restrictions, only wednesday should be allowed',
368+
async () => {
369+
// Mock authHandler to simulate the user being logged in
370+
(authHandler as jest.MockedFunction<typeof authHandler>)
371+
.mockImplementationOnce(mockAuthHandler(USER5));
372+
const response = await request(app)
373+
.post('/api/timetables/generate')
374+
.send({
375+
courses: [{id: 101}],
376+
semester: 'Spring',
377+
restrictions: [{
378+
type: 'Restrict Before',
379+
days: ['MO', 'TU', 'TH', 'FR'],
380+
endTime: '21:00:00',
381+
disabled: false
382+
}]
383+
})
384+
.expect(200);
385+
expect(JSON.parse(response.text).amount).toEqual(1);
386+
expect(JSON.parse(response.text).schedules).toEqual([[{
387+
id: 2,
388+
course_id: 101,
389+
meeting_section: 'LEC02',
390+
day: 'WE',
391+
start: '10:00:00',
392+
end: '11:00:00',
393+
}]]);
394+
});
395+
});

0 commit comments

Comments
 (0)