Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francisvaut authored and EwoutV committed Apr 16, 2024
1 parent 89546d5 commit 748f69d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 52 deletions.
2 changes: 2 additions & 0 deletions frontend/src/test/unit/services/course_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ describe('course', (): void => {
const exampleCourse = new Course(
'course_id', // id
'course_name', // name
'course_excerpt', // excerpt
'course_description', // description
2024, // acedemic_startyear,
null, // parent_course
Expand All @@ -179,6 +180,7 @@ describe('course', (): void => {
expect(courses.value?.[prevLength]?.id).toBe('course_id');
expect(courses.value?.[prevLength]?.name).toBe('course_name');
expect(courses.value?.[prevLength]?.description).toBe('course_description');
expect(courses.value?.[prevLength]?.excerpt).toBe('course_excerpt');
expect(courses.value?.[prevLength]?.academic_startyear).toBe(2024);
});
});
56 changes: 5 additions & 51 deletions frontend/src/test/unit/services/project_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest';
import { useProject } from '@/composables/services/project.service.ts';
import { useCourses } from '@/composables/services/course.service';
import { Project } from '@/types/Project';
import { type Course } from '@/types/Course';
import { Course } from '@/types/Course';

const {
projects,
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('project', (): void => {
await getProjectByID('0');
expect(project.value).not.toBeNull();
expect(project.value?.name).toBe('sel2');
expect(project.value?.course).toBeNull();
expect(project.value?.course).toBeInstanceOf(Course);
expect(project.value?.description).toBe('this is a test');
expect(project.value?.visible).toBe(true);
expect(project.value?.archived).toBe(false);
Expand All @@ -41,14 +41,13 @@ describe('project', (): void => {
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?.structureChecks).toEqual([]);
expect(project.value?.extra_checks).toEqual([]);
expect(project.value?.groups).toEqual([]);
expect(project.value?.submissions).toEqual([]);
});

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

await getProjectsByCourse('1');
Expand All @@ -57,7 +56,7 @@ describe('project', (): void => {
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].course).toBeInstanceOf(Course);
expect(projects.value?.[0]?.description).toBe('this is a test');
expect(projects.value?.[0]?.visible).toBe(true);
expect(projects.value?.[0]?.archived).toBe(false);
Expand All @@ -67,14 +66,13 @@ describe('project', (): void => {
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]?.structureChecks).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].course).toBeInstanceOf(Course);
expect(projects.value?.[1]?.description).toBe('make a project');
expect(projects.value?.[1]?.visible).toBe(true);
expect(projects.value?.[1]?.archived).toBe(false);
Expand All @@ -84,50 +82,6 @@ describe('project', (): void => {
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]?.structureChecks).toEqual([]);
expect(projects.value?.[1]?.extra_checks).toEqual([]);
expect(projects.value?.[1]?.groups).toEqual([]);
expect(projects.value?.[1]?.submissions).toEqual([]);
});

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

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]?.structureChecks).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]?.structureChecks).toEqual([]);
expect(projects.value?.[1]?.extra_checks).toEqual([]);
expect(projects.value?.[1]?.groups).toEqual([]);
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/test/unit/services/setup/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const projects = [
score_visible: true,
group_size: 8,
submissions: ['1', '2'],
groups: ['0', '1'],z
groups: ['0', '1'],
},
{
id: 1,
Expand All @@ -51,6 +51,7 @@ export const projects = [
export const courses = [
{
id: '1',
excerpt: 'excerpt1',
teachers: ['123', '124'],
assistants: ['235', '236'],
students: ['1', '2', '3', '000201247011'],
Expand All @@ -63,6 +64,7 @@ export const courses = [
},
{
id: '2',
excerpt: 'excerpt2',
teachers: [],
assistants: [],
students: [],
Expand All @@ -75,6 +77,7 @@ export const courses = [
},
{
id: '3',
excerpt: 'excerpt3',
teachers: [],
assistants: [],
students: [],
Expand All @@ -87,6 +90,7 @@ export const courses = [
},
{
id: '12',
excerpt: 'excerpt12',
teachers: [],
assistants: [],
students: [],
Expand All @@ -99,6 +103,7 @@ export const courses = [
},
{
id: '13',
excerpt: 'excerpt13',
teachers: [],
assistants: [],
students: [],
Expand All @@ -111,6 +116,7 @@ export const courses = [
},
{
id: '14',
excerpt: 'excerpt14',
teachers: [],
assistants: [],
students: [],
Expand All @@ -123,6 +129,7 @@ export const courses = [
},
{
id: '15',
excerpt: 'excerpt15',
teachers: [],
assistants: [],
students: [],
Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/unit/services/setup/get_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
structureChecks,
submissions,
} from './data';
import { json } from 'stream/consumers';

const baseUrl = 'http://localhost';

Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/unit/types/course.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('course type', () => {
expect(course).toBeInstanceOf(Course);
expect(course.id).toBe(courseData.id);
expect(course.name).toBe(courseData.name);
expect(course.excerpt).toBe(courseData.excerpt);
expect(course.description).toBe(courseData.description);
expect(course.academic_startyear).toBe(courseData.academic_startyear);
expect(course.parent_course).toBe(courseData.parent_course);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/unit/types/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function createCourse(courseData: any): Course {
return new Course(
courseData.id,
courseData.name,
courseData.excerpt,
courseData.description,
courseData.academic_startyear,
courseData.parent_course,
Expand Down

0 comments on commit 748f69d

Please sign in to comment.