Skip to content

Commit

Permalink
Merge pull request #27 from hotungkhanh/kan-72/frontend-api
Browse files Browse the repository at this point in the history
fix: update frontend api + integration tests to match backend
  • Loading branch information
dh-giang-vu authored Sep 30, 2024
2 parents 7fd470f + 458e701 commit 6c7242c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions frontend/src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type TimetableBase = {
}

export type Unit = {
unitID: number,
unitId: number,
name: string,
duration: number,
students: Student[],
Expand All @@ -36,7 +36,7 @@ export type Student = {
};

export type Room = {
id: string,
roomCode: string,
capacity: number,
lab: boolean
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scripts/handleInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function getTimetableProblem(enrolmentExcel: File, roomSpreadsheet:
const unitsList = header.slice(14);
const units: Unit[] = unitsList.map((value, index) => {
return {
unitID: index,
unitId: index,
name: value.toString(),
duration: 0,
students: [],
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function getTimetableProblem(enrolmentExcel: File, roomSpreadsheet:
.filter((record) => record['5'] as boolean)
.map((record) => {
return {
id: record['2'] as string,
roomCode: record['2'] as string,
capacity: record['3'] as number,
lab: record['4'] as boolean
}
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ describe('fetchTimetableSolution', () => {
*/
it('return TimetableSolution', async () => {
const problem: TimetableProblem = {
units: [{ unitID: 0, name: "Unit0", duration: 1200, students: [], wantsLab: true }],
units: [{ unitId: 0, name: "Unit0", duration: 1200, students: [], wantsLab: true }],
daysOfWeek: ["MONDAY"],
startTimes: ["11:00:00"],
rooms: [{ id: "Room A", capacity: 10, lab: true }]
rooms: [{ roomCode: "Room A", capacity: 10, lab: true }]
};

const solution = await fetchTimetableSolution(problem);
expect(solution).not.toBeNull();
expect(solution?.units[0].dayOfWeek).toEqual(problem.daysOfWeek[0]);
expect(solution?.units[0].startTime).toEqual(problem.startTimes[0]);
expect(solution?.units[0].end).toEqual(addSecondsToTimeString(problem.startTimes[0], problem.units[0].duration));
expect(solution?.units[0].room).toEqual(problem.rooms[0]);
expect(solution?.units[0].room).toHaveProperty("roomCode", problem.rooms[0].roomCode);
expect(solution?.daysOfWeek).toEqual(problem.daysOfWeek);
expect(solution?.startTimes).toEqual(problem.startTimes);
expect(solution?.rooms).toEqual(problem.rooms);

});

Expand All @@ -36,10 +35,10 @@ describe('fetchTimetableSolution', () => {
*/
it ('can be called multiple times', async () => {
const problem: TimetableProblem = {
units: [{ unitID: 0, name: "Unit0", duration: 1200, students: [], wantsLab: true }],
units: [{ unitId: 0, name: "Unit0", duration: 1200, students: [], wantsLab: true }],
daysOfWeek: ["MONDAY"],
startTimes: ["11:00:00"],
rooms: [{ id: "Room A", capacity: 10, lab: true }]
rooms: [{ roomCode: "Room A", capacity: 10, lab: true }]
};

const solutions = await Promise.all([fetchTimetableSolution(problem), fetchTimetableSolution(problem), fetchTimetableSolution(problem)]);
Expand Down

0 comments on commit 6c7242c

Please sign in to comment.