Skip to content

Commit

Permalink
chore: add test for faculty
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed Mar 29, 2024
1 parent 5dbbdb3 commit 0103450
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
20 changes: 20 additions & 0 deletions frontend/src/test/unit/faculty_service.tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {describe, it, expect, beforeEach} from 'vitest'
import { useFaculty } from '@/composables/services/faculties.service.ts'

const {
faculties,
faculty,
getFacultyByID,
getFacultys,

createFaculty,
deleteFaculty
} = useFaculty();

describe("faculty", (): void => {
it("gets faculty data by id", async () => {
await getFacultyByID("0")
expect(faculty.value).not.toBeNull()
expect(faculty.value?.name).toBe("wetenschappen")
})
})
23 changes: 19 additions & 4 deletions frontend/src/test/unit/group_service.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {describe, it, expect, beforeEach} from 'vitest'

import { useGroup } from '@/composables/services/groups.service.ts'
import { getgroups } from 'process';
import { Group } from '@/types/Group';

const {
groups,
Expand All @@ -28,7 +25,25 @@ describe("group", (): void => {

it("gets groups data by project", async () => {
await getGroupsByProject("0")
console.log(groups.value)
// console.log(groups.value)
// Ensure group data is not null
expect(groups.value).not.toBeNull();
expect(Array.isArray(groups.value)).toBe(true);
expect(groups.value?.length).toBe(2);

expect(groups.value?.[0]).not.toBeNull()
expect(groups.value?.[0]?.score).toBe(20)
expect(groups.value?.[0]?.id).toBe("0")
expect(groups.value?.[0]?.project).toBeNull()
expect(groups.value?.[0]?.students).toEqual([]);
expect(groups.value?.[0]?.submissions).toEqual([]);

expect(groups.value?.[1]).not.toBeNull()
expect(groups.value?.[1]?.score).toBe(18)
expect(groups.value?.[1]?.id).toBe("1")
expect(groups.value?.[1]?.project).toBeNull()
expect(groups.value?.[1]?.students).toEqual([]);
expect(groups.value?.[1]?.submissions).toEqual([]);
})

/*
Expand Down
23 changes: 22 additions & 1 deletion frontend/src/test/unit/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const projects = [
}
]

const faculties = [
{
name: "wetenschappen"
}
]

export const restHandlers = [
http.get(baseUrl + endpoints.groups.retrieve.replace('{id}', ':id'),
({ params }) => {
Expand All @@ -43,9 +49,24 @@ export const restHandlers = [
),
http.get(baseUrl + endpoints.groups.byProject.replace('{project_id}', ':id'),
({ params }) => {
return HttpResponse.json(groups.find(x => x.project == params.id))
return HttpResponse.json(groups.filter(x => x.project == params.id))
}
),
http.get(baseUrl + endpoints.faculties.retrieve.replace('{name}', ':id'),
({ params }) => {
return HttpResponse.json(faculties.find(x => x.name == params.name))
}
)

/*
http.post(baseUrl + endpoints.groups.byProject.replace('{project_id}', ':id'),
({ params }) => {
const newGroup = params.body; // Assuming the request body contains the new group data
groups.push(newGroup);
return HttpResponse.json(newGroup);
}
)
*/
]

const server = setupServer(...restHandlers)
Expand Down

0 comments on commit 0103450

Please sign in to comment.