diff --git a/frontend/src/test/unit/assistant_service.test.ts b/frontend/src/test/unit/assistant_service.test.ts new file mode 100644 index 00000000..c42e5b76 --- /dev/null +++ b/frontend/src/test/unit/assistant_service.test.ts @@ -0,0 +1,64 @@ +import {describe, it, expect, beforeEach} from 'vitest' +import { useAssistant } from '@/composables/services/assistant.service.ts' + +const { + assistants, + assistant, + response, + + getAssistantByID, + getAssistantByCourse, + getAssistants, + + createAssistant, + deleteAssistant, + + assistantJoinCourse, + assistantLeaveCourse +} = useAssistant(); + +describe("assistant", (): void => { + it("gets assistant data by id", async () => { + await getAssistantByID("235") + expect(assistant.value).not.toBeNull() + expect(assistant.value?.username).toBe("bsimpson") + expect(assistant.value?.is_staff).toBe(false) + expect(assistant.value?.email).toBe("Bart.Simpson@gmail.be") + expect(assistant.value?.first_name).toBe("Bart") + expect(assistant.value?.last_name).toBe("Simpson") + expect(assistant.value?.last_enrolled).toBe(2023) + // expect(assistant.value?.last_login).toBeNull() + // expect(assistant.value?.create_time).toEqual(new Date("July 21, 2024 01:15:00")) + expect(assistant.value?.courses).toEqual([]) + expect(assistant.value?.faculties).toEqual([]) + }) + + it("gets teacher data", async () => { + await getAssistants() + expect(assistants).not.toBeNull() + expect(Array.isArray(assistants.value)).toBe(true) + expect(assistants.value?.length).toBe(2); + + expect(assistants.value?.[0]?.username).toBe("bsimpson") + expect(assistants.value?.[0]?.is_staff).toBe(false) + expect(assistants.value?.[0]?.email).toBe("Bart.Simpson@gmail.be") + expect(assistants.value?.[0]?.first_name).toBe("Bart") + expect(assistants.value?.[0]?.last_name).toBe("Simpson") + expect(assistants.value?.[0]?.last_enrolled).toBe(2023) + // expect(assistants.value?.[0]?.last_login).toBeNull() + // expect(assistants.value?.[0]?.create_time).toEqual(new Date("July 21, 2024 01:15:00")) + expect(assistants.value?.[0]?.courses).toEqual([]) + expect(assistants.value?.[0]?.faculties).toEqual([]) + + expect(assistants.value?.[1]?.username).toBe("kclijster") + expect(assistants.value?.[1]?.is_staff).toBe(false) + expect(assistants.value?.[1]?.email).toBe("Kim.Clijsters@gmail.be") + expect(assistants.value?.[1]?.first_name).toBe("Kim") + expect(assistants.value?.[1]?.last_name).toBe("Clijsters") + expect(assistants.value?.[1]?.last_enrolled).toBe(2023) + // expect(assistants.value?.[0]?.last_login).toBeNull() + // expect(assistants.value?.[0]?.create_time).toEqual(new Date("July 21, 2024 01:15:00")) + expect(assistants.value?.[1]?.courses).toEqual([]) + expect(assistants.value?.[1]?.faculties).toEqual([]) + }) +}) \ No newline at end of file diff --git a/frontend/src/test/unit/setup.ts b/frontend/src/test/unit/setup.ts index 7437fdfa..3c3ce267 100644 --- a/frontend/src/test/unit/setup.ts +++ b/frontend/src/test/unit/setup.ts @@ -196,12 +196,10 @@ const teachers = [ first_name: "Tom", last_name: "Boonen", last_enrolled: 2023, - create_time: new Date("July 21, 2024 01:15:00") + create_time: new Date("July 21, 2024 01:15:00") }, { id: "124", - courses: [], - faculties: [], last_login: null, username: "psagan", is_staff: false, @@ -209,10 +207,39 @@ const teachers = [ first_name: "Peter", last_name: "Sagan", last_enrolled: 2023, - create_time: new Date("July 21, 2024 01:15:00") + create_time: new Date("July 21, 2024 01:15:00") } ] +const assistants = [ + { + id: "235", + courses: [], + faculties: [], + last_login: null, + username: "bsimpson", + is_staff: false, + email: "Bart.Simpson@gmail.be", + first_name: "Bart", + last_name: "Simpson", + last_enrolled: 2023, + create_time: new Date("July 21, 2024 01:15:00") + }, + { + id: "236", + courses: [], + faculties: [], + last_login: null, + username: "kclijster", + is_staff: false, + email: "Kim.Clijsters@gmail.be", + first_name: "Kim", + last_name: "Clijsters", + last_enrolled: 2023, + create_time: new Date("July 21, 2024 01:15:00") + } +] + export const restHandlers = [ http.get(baseUrl + endpoints.groups.retrieve.replace('{id}', ':id'), ({ params }) => { @@ -224,6 +251,11 @@ export const restHandlers = [ return HttpResponse.json(teachers.find(x => x.id == params.id)) } ), + http.get(baseUrl + endpoints.assistants.retrieve.replace('{id}', ':id'), + ({ params }) => { + return HttpResponse.json(assistants.find(x => x.id == params.id)) + } + ), http.get(baseUrl + endpoints.students.retrieve.replace('{id}', ':id'), ({ params }) => { return HttpResponse.json(students.find(x => x.id == params.id)) @@ -273,6 +305,11 @@ export const restHandlers = [ ({}) => { return HttpResponse.json(teachers) } + ), + http.get(baseUrl + endpoints.assistants.index, + ({}) => { + return HttpResponse.json(assistants) + } ) /* diff --git a/frontend/src/types/Assistant.ts b/frontend/src/types/Assistant.ts index 786c58ee..9008ff75 100644 --- a/frontend/src/types/Assistant.ts +++ b/frontend/src/types/Assistant.ts @@ -1,3 +1,4 @@ +import { Course } from "./Course"; import { Faculty } from "./Faculty"; import {Role, User} from '@/types/User.ts'; @@ -11,7 +12,8 @@ export class Assistant extends User { public last_enrolled: number, public is_staff: boolean, public roles: Role[] = [], - public faculties: Faculty[] = [] + public faculties: Faculty[] = [], + public courses: Course[] = [] ) { super(id, username, email, first_name, last_name, last_enrolled, is_staff, roles); }