Skip to content

Commit

Permalink
chore: add assistant service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed Mar 31, 2024
1 parent 65a7bfa commit 65b9a98
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 5 deletions.
64 changes: 64 additions & 0 deletions frontend/src/test/unit/assistant_service.test.ts
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
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("[email protected]")
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("[email protected]")
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([])
})
})
45 changes: 41 additions & 4 deletions frontend/src/test/unit/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,50 @@ 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,
email: "[email protected]",
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: "[email protected]",
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: "[email protected]",
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 }) => {
Expand All @@ -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))
Expand Down Expand Up @@ -273,6 +305,11 @@ export const restHandlers = [
({}) => {
return HttpResponse.json(teachers)
}
),
http.get(baseUrl + endpoints.assistants.index,
({}) => {
return HttpResponse.json(assistants)
}
)

/*
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/types/Assistant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Course } from "./Course";
import { Faculty } from "./Faculty";
import {Role, User} from '@/types/User.ts';

Expand All @@ -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);
}
Expand Down

0 comments on commit 65b9a98

Please sign in to comment.