Skip to content

Commit

Permalink
Merge pull request #191 from SELab-2/services
Browse files Browse the repository at this point in the history
Services
  • Loading branch information
BramMeir authored Mar 31, 2024
2 parents 6ab8d28 + f29cffb commit 6ea549b
Show file tree
Hide file tree
Showing 16 changed files with 1,160 additions and 120 deletions.
567 changes: 495 additions & 72 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/node": "^20.11.30",
"@vitejs/plugin-vue": "^5.0.4",
"cypress": "^13.7.1",
"msw": "^2.2.13",
"sass": "^1.72.0",
"typescript": "^5.2.2",
"vite": "^5.1.1",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/composables/services/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function useGroup() {
await getList<Group>(endpoint, groups, Group.fromJSON);
}

async function createGroup(group_data: Group, group_id: string) {
const endpoint = endpoints.groups.byProject.replace('{group_id}', group_id);
async function createGroup(group_data: Group, project_id: string) {
const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id);
await create<Group>(endpoint,
{
score: group_data.score
Expand Down
21 changes: 0 additions & 21 deletions frontend/src/test/unit/course.test.ts

This file was deleted.

115 changes: 115 additions & 0 deletions frontend/src/test/unit/course_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { describe, it, expect } from 'vitest'
import { Course } from '@/types/Course.ts'

import { useCourses } from '@/composables/services/courses.service.ts'

const {
courses,
course,

getCourseByID,
getCourses,
getCoursesByStudent,

createCourse,
cloneCourse,
deleteCourse
} = useCourses();

// "describe" bundles tests about 1 specific thing; here we're testing course
// aka a test suite
describe("course", (): void => {
// "it" is used to specify tests
// you can also import "test" instead of "it", because it's the exact same
// but with "it", it's easy to read => it (referring to the course) returns correct course year
it("returns correct course year", (): void => {
const course: Course = new Course("1", "course", "description", 2003)
// use expect for assertions
// after expect, there are a multitude of possible functions such as:
// toBe, toEqual, toContain
// check https://vitest.dev/api/expect.html for all possibilities
expect(course.getCourseYear()).toBe("2003 - 2004")
// assert can also be used instead, if you like its syntax more
// check out https://vitest.dev/api/assert.html for more info
})

it("gets course data by id", async () => {
await getCourseByID("1")
expect(course.value).not.toBeNull()
expect(course.value?.name).toBe("Math")
expect(course.value?.parent_course).toBeNull()
expect(course.value?.academic_startyear).toBe(2023)
expect(course.value?.description).toBe("Math course")
expect(course.value?.students).toEqual([])
expect(course.value?.teachers).toEqual([])
expect(course.value?.assistants).toEqual([])
expect(course.value?.projects).toEqual([])
})

it("gets courses data", async () => {
await getCourses()
expect(courses.value).not.toBeNull()
expect(courses.value?.[0]?.name).toBe("Math")
expect(courses.value?.[0]?.parent_course).toBeNull()
expect(courses.value?.[0]?.academic_startyear).toBe(2023)
expect(courses.value?.[0]?.description).toBe("Math course")
expect(courses.value?.[0]?.students).toEqual([])
expect(courses.value?.[0]?.teachers).toEqual([])
expect(courses.value?.[0]?.assistants).toEqual([])
expect(courses.value?.[0]?.projects).toEqual([])

expect(courses.value?.[1]?.name).toBe("Sel2")
expect(courses.value?.[1]?.parent_course).toBe("3")
expect(courses.value?.[1]?.academic_startyear).toBe(2023)
expect(courses.value?.[1]?.description).toBe("Software course")
expect(courses.value?.[1]?.students).toEqual([])
expect(courses.value?.[1]?.teachers).toEqual([])
expect(courses.value?.[1]?.assistants).toEqual([])
expect(courses.value?.[1]?.projects).toEqual([])

expect(courses.value?.[2]?.name).toBe("Sel1")
expect(courses.value?.[2]?.parent_course).toBeNull()
expect(courses.value?.[2]?.academic_startyear).toBe(2022)
expect(courses.value?.[2]?.description).toBe("Software course")
expect(courses.value?.[2]?.students).toEqual([])
expect(courses.value?.[2]?.teachers).toEqual([])
expect(courses.value?.[2]?.assistants).toEqual([])
expect(courses.value?.[2]?.projects).toEqual([])

expect(courses.value?.[3]?.name).toBe("Math")
expect(courses.value?.[3]?.parent_course).toBe("1")
expect(courses.value?.[3]?.academic_startyear).toBe(2024)
expect(courses.value?.[3]?.description).toBe("Math course")
expect(courses.value?.[3]?.students).toEqual([])
expect(courses.value?.[3]?.teachers).toEqual([])
expect(courses.value?.[3]?.assistants).toEqual([])
expect(courses.value?.[3]?.projects).toEqual([])

expect(courses.value?.[4]?.name).toBe("Math")
expect(courses.value?.[4]?.parent_course).toBe("12")
expect(courses.value?.[4]?.academic_startyear).toBe(2025)
expect(courses.value?.[4]?.description).toBe("Math course")
expect(courses.value?.[4]?.students).toEqual([])
expect(courses.value?.[4]?.teachers).toEqual([])
expect(courses.value?.[4]?.assistants).toEqual([])
expect(courses.value?.[4]?.projects).toEqual([])

expect(courses.value?.[5]?.name).toBe("Club brugge")
expect(courses.value?.[5]?.parent_course).toBeNull()
expect(courses.value?.[5]?.academic_startyear).toBe(2023)
expect(courses.value?.[5]?.description).toBeNull()
expect(courses.value?.[5]?.students).toEqual([])
expect(courses.value?.[5]?.teachers).toEqual([])
expect(courses.value?.[5]?.assistants).toEqual([])
expect(courses.value?.[5]?.projects).toEqual([])

expect(courses.value?.[6]?.name).toBe("vergeet barbara")
expect(courses.value?.[6]?.parent_course).toBeNull()
expect(courses.value?.[6]?.academic_startyear).toBe(2023)
expect(courses.value?.[6]?.description).toBeNull()
expect(courses.value?.[6]?.students).toEqual([])
expect(courses.value?.[6]?.teachers).toEqual([])
expect(courses.value?.[6]?.assistants).toEqual([])
expect(courses.value?.[6]?.projects).toEqual([])
})
})
31 changes: 31 additions & 0 deletions frontend/src/test/unit/faculty_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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("wetenschappen")
expect(faculty.value).not.toBeNull()
expect(faculty.value?.name).toBe("wetenschappen")
})

it("gets faculties data", async () => {
await getFacultys()
expect(faculties).not.toBeNull()
expect(Array.isArray(faculties.value)).toBe(true)
expect(faculties.value?.length).toBe(2);
expect(faculties.value?.[0]).not.toBeNull()
expect(faculties.value?.[0].name).toBe("wetenschappen")
expect(faculties.value?.[1]).not.toBeNull()
expect(faculties.value?.[1].name).toBe("voetbal")
})
})
56 changes: 56 additions & 0 deletions frontend/src/test/unit/group_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {describe, it, expect, beforeEach} from 'vitest'
import { useGroup } from '@/composables/services/groups.service.ts'

const {
groups,
group,
getGroupByID,
getGroupsByProject,
getGroupsByStudent,

createGroup,
deleteGroup
} = useGroup();

describe("group", (): void => {
it("gets group data by id", async () => {
await getGroupByID("0")
expect(group.value).not.toBeNull()
expect(group.value?.score).toBe(20)
expect(group.value?.id).toBe("0")
expect(group.value?.project).toBeNull()
expect(group.value?.students).toEqual([]);
expect(group.value?.submissions).toEqual([]);
})

it("gets groups data by project", async () => {
await getGroupsByProject("0")
// 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([]);
})

/*
it("create group", async () => {
let gr = new Group("3",10)
await createGroup(gr, "0")
console.log(group.value)
})
*/
})
78 changes: 78 additions & 0 deletions frontend/src/test/unit/project_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {describe, it, expect, beforeEach} from 'vitest'
import { useProject } from '@/composables/services/project.service.ts'

const {
projects,
project,
getProjectByID,
getProjectsByCourse,
getProjectsByCourseAndDeadline,
getProjectsByStudent,

createProject,
deleteProject
} = useProject();

describe("project", (): void => {
it("gets project data by id", async () => {
await getProjectByID("0")
expect(project.value).not.toBeNull()
expect(project.value?.name).toBe("sel2")
expect(project.value?.course).toBeNull()
expect(project.value?.description).toBe("this is a test")
expect(project.value?.visible).toBe(true)
expect(project.value?.archived).toBe(false)
expect(project.value?.locked_groups).toBe(false)
expect(project.value?.start_date).toStrictEqual(new Date("July 21, 2024 01:15:00"))
expect(project.value?.deadline).toStrictEqual(new Date("July 23, 2024 01:15:00"))
expect(project.value?.max_score).toBe(100)
expect(project.value?.score_visible).toBe(true)
expect(project.value?.group_size).toBe(8)
expect(project.value?.course).toBeNull()
expect(project.value?.structure_checks).toEqual([])
expect(project.value?.extra_checks).toEqual([])
expect(project.value?.groups).toEqual([])
expect(project.value?.submissions).toEqual([])
})

it("gets projects data", async () => {
await getProjectsByCourse("1")
expect(projects).not.toBeNull()
expect(Array.isArray(projects.value)).toBe(true)
expect(projects.value?.length).toBe(2);
expect(projects.value).not.toBeNull()
expect(projects.value?.[0]?.name).toBe("sel2")
expect(projects.value?.[0]?.course).toBeNull()
expect(projects.value?.[0]?.description).toBe("this is a test")
expect(projects.value?.[0]?.visible).toBe(true)
expect(projects.value?.[0]?.archived).toBe(false)
expect(projects.value?.[0]?.locked_groups).toBe(false)
expect(projects.value?.[0]?.start_date).toStrictEqual(new Date("July 21, 2024 01:15:00"))
expect(projects.value?.[0]?.deadline).toStrictEqual(new Date("July 23, 2024 01:15:00"))
expect(projects.value?.[0]?.max_score).toBe(100)
expect(projects.value?.[0]?.score_visible).toBe(true)
expect(projects.value?.[0]?.group_size).toBe(8)
expect(projects.value?.[0]?.course).toBeNull()
expect(projects.value?.[0]?.structure_checks).toEqual([])
expect(projects.value?.[0]?.extra_checks).toEqual([])
expect(projects.value?.[0]?.groups).toEqual([])
expect(projects.value?.[0]?.submissions).toEqual([])

expect(projects.value?.[1]?.name).toBe("sel3")
expect(projects.value?.[1]?.course).toBeNull()
expect(projects.value?.[1]?.description).toBe("make a project")
expect(projects.value?.[1]?.visible).toBe(true)
expect(projects.value?.[1]?.archived).toBe(false)
expect(projects.value?.[1]?.locked_groups).toBe(false)
expect(projects.value?.[1]?.start_date).toStrictEqual(new Date("July 21, 2024 01:15:00"))
expect(projects.value?.[1]?.deadline).toStrictEqual(new Date("July 23, 2024 01:15:00"))
expect(projects.value?.[1]?.max_score).toBe(20)
expect(projects.value?.[1]?.score_visible).toBe(false)
expect(projects.value?.[1]?.group_size).toBe(3)
expect(projects.value?.[1]?.course).toBeNull()
expect(projects.value?.[1]?.structure_checks).toEqual([])
expect(projects.value?.[1]?.extra_checks).toEqual([])
expect(projects.value?.[1]?.groups).toEqual([])
expect(projects.value?.[1]?.submissions).toEqual([])
})
})
Loading

0 comments on commit 6ea549b

Please sign in to comment.