Skip to content

Commit

Permalink
Merge pull request #214 from SELab-2/services
Browse files Browse the repository at this point in the history
Services
  • Loading branch information
francisvaut authored Mar 31, 2024
2 parents 19b69cd + f5b2b55 commit a18c167
Show file tree
Hide file tree
Showing 19 changed files with 5,496 additions and 4,718 deletions.
9,172 changes: 4,554 additions & 4,618 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 @@ -17,6 +17,7 @@
"axios": "^1.6.8",
"js-cookie": "^3.0.5",
"moment": "^2.30.1",
"msw": "^2.2.13",
"pinia": "^2.1.7",
"primeflex": "^3.3.1",
"primeicons": "^6.0.1",
Expand Down
1 change: 0 additions & 1 deletion frontend/src/composables/services/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export async function getListMerged<T>(endpoints: string[], ref: Ref<T[]|null>,
const allData: T[] = [];

for (const endpoint of endpoints){
console.log(endpoint)
await client.get(endpoint).then(response => {
const responseData: T[] = response.data.map((data: T) => fromJson(data));
allData.push(...responseData); // Merge into the allData array
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/composables/services/submissionStatus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {endpoints} from '@/config/endpoints.ts';
import { get} from '@/composables/services/helpers.ts';
import { SubmissionStatus } from '@/types/SubmisionStatus';

export function useSubmission() {
export function useSubmission_status() {
const submissionStatus = ref<SubmissionStatus|null>(null);

async function getSubmissionStatus(project_id: string) {
async function getSubmissionStatusByProject(project_id: string) {
const endpoint = endpoints.submissions.status.replace('{project_id}', project_id);
await get<SubmissionStatus>(endpoint, submissionStatus, SubmissionStatus.fromJSON);
}

return {
submissionStatus,
getSubmissionStatus
getSubmissionStatusByProject
};
}
55 changes: 55 additions & 0 deletions frontend/src/test/unit/admin_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {describe, it, expect, beforeEach} from 'vitest'
import { useAdmin } from '@/composables/services/admins.service.ts'

const {
admins,
admin,
getAdminByID,
getAdmins,

createAdmin,
deleteAdmin
} = useAdmin();

describe("admin", (): void => {
it("gets assistant data by id", async () => {
await getAdminByID("300201547011")
expect(admin.value).not.toBeNull()
expect(admin.value?.username).toBe("tverslyp")
expect(admin.value?.is_staff).toBe(true)
expect(admin.value?.email).toBe("Tybo.Verslype@UGent.be")
expect(admin.value?.first_name).toBe("Tybo")
expect(admin.value?.last_name).toBe("Verslype")
expect(admin.value?.last_enrolled).toBe(2023)
expect(admin.value?.last_login).toEqual(new Date("July 23, 2024 01:15:00"))
expect(admin.value?.create_time).toEqual(new Date("July 21, 2024 01:15:00"))
expect(admin.value?.faculties).toEqual([])
})

it("gets admins data", async () => {
await getAdmins()
expect(admins).not.toBeNull()
expect(Array.isArray(admins.value)).toBe(true)
expect(admins.value?.length).toBe(2);

expect(admins.value?.[0]?.username).toBe("tverslyp")
expect(admins.value?.[0]?.is_staff).toBe(true)
expect(admins.value?.[0]?.email).toBe("Tybo.Verslype@UGent.be")
expect(admins.value?.[0]?.first_name).toBe("Tybo")
expect(admins.value?.[0]?.last_name).toBe("Verslype")
expect(admins.value?.[0]?.last_enrolled).toBe(2023)
expect(admins.value?.[0]?.last_login).toEqual(new Date("July 23, 2024 01:15:00"))
expect(admins.value?.[0]?.create_time).toEqual(new Date("July 21, 2024 01:15:00"))
expect(admins.value?.[0]?.faculties).toEqual([])

expect(admins.value?.[1]?.username).toBe("simmig")
expect(admins.value?.[1]?.is_staff).toBe(true)
expect(admins.value?.[1]?.email).toBe("Simon.Mignolet@UGent.be")
expect(admins.value?.[1]?.first_name).toBe("Simon")
expect(admins.value?.[1]?.last_name).toBe("Mignolet")
expect(admins.value?.[1]?.last_enrolled).toBe(2023)
expect(admins.value?.[0]?.last_login).toEqual(new Date("July 23, 2024 01:15:00"))
expect(admins.value?.[0]?.create_time).toEqual(new Date("July 21, 2024 01:15:00"))
expect(admins.value?.[1]?.faculties).toEqual([])
})
})
93 changes: 93 additions & 0 deletions frontend/src/test/unit/assistant_service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 assistants 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([])
})

it("gets assistants data by course", async () => {
await getAssistantByCourse("1")
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([])
})
})
34 changes: 34 additions & 0 deletions frontend/src/test/unit/course_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,38 @@ describe("course", (): void => {
expect(courses.value?.[6]?.assistants).toEqual([])
expect(courses.value?.[6]?.projects).toEqual([])
})

it("gets courses data by student", async () => {
await getCoursesByStudent("1")
expect(courses).not.toBeNull()
expect(Array.isArray(courses.value)).toBe(true)
expect(courses.value?.length).toBe(3);

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([])
})
})
14 changes: 14 additions & 0 deletions frontend/src/test/unit/group_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ describe("group", (): void => {
expect(groups.value?.[1]?.submissions).toEqual([]);
})

it("gets groups data by student", async () => {
await getGroupsByStudent("1")
expect(groups.value).not.toBeNull();
expect(Array.isArray(groups.value)).toBe(true)
expect(groups.value?.length).toBe(1)

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([])
})

/*
it("create group", async () => {
let gr = new Group("3",10)
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/test/unit/project_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,45 @@ describe("project", (): void => {
expect(projects.value?.[1]?.groups).toEqual([])
expect(projects.value?.[1]?.submissions).toEqual([])
})

it("gets projects data", async () => {
await getProjectsByStudent("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 a18c167

Please sign in to comment.