Skip to content

Commit

Permalink
Services fix, tests (#297)
Browse files Browse the repository at this point in the history
* test: create course

* fix: send id to backend when creating faculty

* test: create faculty

* test: create group

* test: cleanup create tests

* test: assistant type

* test: services and types folder

* test: start with create project

* test: cleanup setup file

* test: cleanup request handlers

* test: reset services + fix mistakes in teacher/assistant service

* chore: fix linting

* test: create project

* chore: linting autofix

* chore: bring back multipart/from-data

* Better academic year selector, filtering and sorting (#292)

* feat: academic year selector, better pagination and filtering composables

* chore: added course pagination

* Run submission checks (#268)

* chore: celery #206

* chore: Support partial update for project

* chore: support patch for project 2

* refactor!: rework checks and submissions

* chore: allow models passed to tasks

* feat: added -k to test.sh

* fix: re-add translations

* chore: display faculty in course edit

* fix: courses to create projects filtered on selected calendar date

* fix: make teacher command

* fix: linting

* test: admin delete

* test: fix service mistake, assistant delete

---------

Co-authored-by: Ewout Verlinde <ewoutverlinde@hotmail.com>
Co-authored-by: Vincent Vallaeys <vincent@vallaeys.com>
Co-authored-by: Bram Meir <bram.meir@ugent.be>
  • Loading branch information
4 people committed Apr 12, 2024
1 parent 0b75a21 commit 415911d
Show file tree
Hide file tree
Showing 29 changed files with 1,196 additions and 648 deletions.
1 change: 1 addition & 0 deletions frontend/src/composables/services/admins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function useAdmin(): AdminState {
return {
admins,
admin,

getAdminByID,
getAdmins,

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useAssistant(): AssistantState {

async function getAssistantByCourse(courseId: string): Promise<void> {
const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId);
await get<Assistant>(endpoint, assistant, Assistant.fromJSON);
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON);
}

async function getAssistants(): Promise<void> {
Expand Down Expand Up @@ -71,7 +71,7 @@ export function useAssistant(): AssistantState {
}

async function deleteAssistant(id: string): Promise<void> {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
const endpoint = endpoints.assistants.retrieve.replace('{id}', id);
await deleteId<Assistant>(endpoint, assistant, Assistant.fromJSON);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export function useCourses(): CoursesState {
await create<Course>(
endpoint,
{
id: courseData.id,
name: courseData.name,
description: courseData.description,
academic_startyear: courseData.academic_startyear,
faculty: courseData.faculty?.id,
},
course,
Course.fromJSON,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/faculties.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useFaculty(): FacultyState {

async function createFaculty(facultyData: Faculty): Promise<void> {
const endpoint = endpoints.faculties.index;
await create<Faculty>(endpoint, { name: facultyData.name }, faculty, Faculty.fromJSON);
await create<Faculty>(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON);
}

async function deleteFaculty(id: string): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/composables/services/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function useGroup(): GroupState {
endpoint,
{
score: groupData.score,
project: groupData.project?.id,
},
group,
Group.fromJSON,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/teachers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useTeacher(): TeacherState {

async function getTeacherByCourse(courseId: string): Promise<void> {
const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId);
await get<Teacher>(endpoint, teacher, Teacher.fromJSON);
await getList<Teacher>(endpoint, teachers, Teacher.fromJSON);
}

async function getTeachers(): Promise<void> {
Expand Down
24 changes: 0 additions & 24 deletions frontend/src/test/unit/faculty_service.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ import { User } from '@/types/users/User.ts';
const {
admins,
admin,

getAdminByID,
getAdmins,

createAdmin,
deleteAdmin,
} = useAdmin();

function resetService(): void {
admin.value = null;
admins.value = null;
}

describe('admin', (): void => {
it('gets assistant data by id', async () => {
resetService();

await getAdminByID('300201547011');
expect(admin.value).not.toBeNull();
expect(admin.value?.username).toBe('tverslyp');
Expand All @@ -28,6 +37,8 @@ describe('admin', (): void => {
});

it('gets admins data', async () => {
resetService();

await getAdmins();
expect(admins).not.toBeNull();
expect(Array.isArray(admins.value)).toBe(true);
Expand Down Expand Up @@ -55,22 +66,24 @@ describe('admin', (): void => {
});

it('create admin', async () => {
resetService();

const exampleAdmin = new User(
'101', // id
'sample_admin', // username
'', // id
'', // username
'sample.admin@UGent.be', // email
'Sample', // first_name
'Admin', // last_name
2024, // last_enrolled
'admin_first_name', // first_name
'admin_last_name', // last_name
-1, // last_enrolled
true, // is_staff
['user'], // roles
[], // roles
[], // faculties
new Date('April 2, 2023 01:15:00'), // create_time
new Date('April 2, 2024 01:15:00'), // last_login
new Date(), // create_time
null, // last_login
);

await getAdmins();
expect(admins).not.toBeNull();
expect(admins.value).not.toBeNull();
expect(Array.isArray(admins.value)).toBe(true);
const prevLength = admins.value?.length ?? 0;

Expand All @@ -81,9 +94,31 @@ describe('admin', (): void => {
expect(Array.isArray(admins.value)).toBe(true);
expect(admins.value?.length).toBe(prevLength + 1);

expect(admins.value?.[prevLength]?.first_name).toBe('Sample');
expect(admins.value?.[prevLength]?.last_name).toBe('Admin');
// Only check for fields that are sent to the backend
expect(admins.value?.[prevLength]?.first_name).toBe('admin_first_name');
expect(admins.value?.[prevLength]?.last_name).toBe('admin_last_name');
expect(admins.value?.[prevLength]?.email).toBe('sample.admin@UGent.be');
expect(admins.value?.[prevLength]?.is_staff).toBe(true);
});

it('delete admin', async () => {
resetService();

await getAdmins();
expect(admins.value).not.toBeNull();
expect(Array.isArray(admins.value)).toBe(true);
const prevLength = admins.value?.length ?? 0;

let adminId = '0';
if (admins.value?.[0]?.id !== undefined && admins.value?.[0].id !== null) {
adminId = admins.value?.[0]?.id;
}

await deleteAdmin(adminId);
await getAdmins();

expect(admins).not.toBeNull();
expect(Array.isArray(admins.value)).toBe(true);
expect(admins.value?.length).toBe(prevLength - 1);
expect(admins.value?.[0]?.id).not.toBe(adminId);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ const {
getAssistants,

createAssistant,
deleteAssistant,

assistantJoinCourse,
assistantLeaveCourse,
} = useAssistant();

function resetService(): void {
assistant.value = null;
assistants.value = null;
}

describe('assistant', (): void => {
it('gets assistant data by id', async () => {
resetService();

await getAssistantByID('235');
expect(assistant.value).not.toBeNull();
expect(assistant.value?.username).toBe('bsimpson');
Expand All @@ -31,6 +42,8 @@ describe('assistant', (): void => {
});

it('gets assistants data', async () => {
resetService();

await getAssistants();
expect(assistants).not.toBeNull();
expect(Array.isArray(assistants.value)).toBe(true);
Expand Down Expand Up @@ -60,6 +73,8 @@ describe('assistant', (): void => {
});

it('gets assistants data by course', async () => {
resetService();

await getAssistantByCourse('1');
expect(assistants).not.toBeNull();
expect(Array.isArray(assistants.value)).toBe(true);
Expand Down Expand Up @@ -89,19 +104,21 @@ describe('assistant', (): void => {
});

it('create assistant', async () => {
resetService();

const exampleAssistant = new Assistant(
'102',
'sample_assistant',
'sample.assistant@UGent.be',
'Sample',
'Assistant',
2023,
true,
[],
[],
[],
new Date('April 2, 2023 01:15:00'),
new Date('April 2, 2024 01:15:00'),
'', // id
'', // username
'sample.assistant@UGent.be', // email
'assistant_first_name', // first_name
'assistant_last_name', // last name
2023, // last enrolled
true, // is_staff
[], // roles
[], // faculties
[], // courses
new Date(), // create_time
null, // last_login
);

await getAssistants();
Expand All @@ -116,9 +133,31 @@ describe('assistant', (): void => {
expect(Array.isArray(assistants.value)).toBe(true);
expect(assistants.value?.length).toBe(prevLength + 1);

expect(assistants.value?.[prevLength]?.first_name).toBe('Sample');
expect(assistants.value?.[prevLength]?.last_name).toBe('Assistant');
// Only check for fields that are sent to the backend
expect(assistants.value?.[prevLength]?.first_name).toBe('assistant_first_name');
expect(assistants.value?.[prevLength]?.last_name).toBe('assistant_last_name');
expect(assistants.value?.[prevLength]?.email).toBe('sample.assistant@UGent.be');
expect(assistants.value?.[prevLength]?.roles).toContain('assistant');
});

it('delete assistant', async () => {
resetService();

await getAssistants();
expect(assistants.value).not.toBeNull();
expect(Array.isArray(assistants.value)).toBe(true);
const prevLength = assistants.value?.length ?? 0;

let assistantId = '0';
if (assistants.value?.[0]?.id !== undefined && assistants.value?.[0].id !== null) {
assistantId = assistants.value?.[0]?.id;
}

await deleteAssistant(assistantId);
await getAssistants();

expect(assistants).not.toBeNull();
expect(Array.isArray(assistants.value)).toBe(true);
expect(assistants.value?.length).toBe(prevLength - 1);
expect(assistants.value?.[0]?.id).not.toBe(assistantId);
});
});
Loading

0 comments on commit 415911d

Please sign in to comment.