Skip to content

Commit

Permalink
chore: linting autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
francisvaut committed May 21, 2024
1 parent 043cac8 commit b129289
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 deletions.
8 changes: 4 additions & 4 deletions frontend/src/test/unit/services/group_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('group', (): void => {
expect(group.value).not.toBeNull();
expect(group.value?.id).toBe('0');
expect(group.value?.score).toBe(20);
assertType(group.value?.project as Project);
assertType(group.value?.project!);
expect(group.value?.students).toBeNull();
expect(group.value?.submissions).toBeNull();
});
Expand All @@ -46,13 +46,13 @@ describe('group', (): void => {

expect(groups.value?.[0].id).toBe('0');
expect(groups.value?.[0].score).toBe(20);
assertType(groups.value?.[0].project as Project)
assertType(groups.value?.[0].project!);
expect(groups.value?.[0].students).toBeNull;
expect(groups.value?.[0].submissions).toBeNull();

expect(groups.value?.[1].id).toBe('1');
expect(groups.value?.[1].score).toBe(18);
assertType(groups.value?.[1].project as Project)
assertType(groups.value?.[1].project!);
expect(groups.value?.[1].students).toBeNull;
expect(groups.value?.[1].submissions).toBeNull();
});
Expand All @@ -67,7 +67,7 @@ describe('group', (): void => {

expect(groups.value?.[0].id).toBe('0');
expect(groups.value?.[0].score).toBe(20);
assertType(groups.value?.[0].project as Project)
assertType(groups.value?.[0].project!);
expect(groups.value?.[0].students).toBeNull;
expect(groups.value?.[0].submissions).toBeNull();
});
Expand Down
44 changes: 22 additions & 22 deletions frontend/src/test/unit/services/project_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { describe, it, expect, assertType } from 'vitest';
import { useProject } from '@/composables/services/project.service.ts';
import { useCourses } from '@/composables/services/course.service';
import { Project } from '@/types/Project';
import { Course } from '@/types/Course';
import { type Course } from '@/types/Course';
import { SubmissionStatus } from '@/types/SubmisionStatus';
import { Group } from '@/types/Group';
import { type Group } from '@/types/Group';

const {
projects,
Expand Down Expand Up @@ -42,13 +42,13 @@ describe('project', (): void => {
expect(project.value?.max_score).toBe(100);
expect(project.value?.score_visible).toBe(true);
expect(project.value?.group_size).toBe(5);
assertType(project.value?.course as Course);
assertType(project.value?.status as SubmissionStatus);
assertType(project.value?.structure_file as File);
assertType(project.value?.course!);
assertType(project.value?.status!);
assertType(project.value?.structure_file!);
expect(project.value?.structureChecks).toBe(null);
expect(project.value?.extra_checks).toBe(null);
assertType(Array.isArray(project.value?.groups));
assertType((project.value?.groups?.[0] ?? null) as Group);
assertType((project.value?.groups?.[0] ?? null)!);
expect(project.value?.submissions).toBe(null);
});

Expand All @@ -70,13 +70,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(5);
assertType(projects.value?.[0]?.course as Course);
assertType(projects.value?.[0]?.status as SubmissionStatus);
assertType(projects.value?.[0]?.structure_file as File);
assertType(projects.value?.[0]?.course!);
assertType(projects.value?.[0]?.status!);
assertType(projects.value?.[0]?.structure_file!);
expect(projects.value?.[0]?.structureChecks).toBe(null);
expect(projects.value?.[0]?.extra_checks).toBe(null);
assertType(Array.isArray(projects.value?.[0]?.groups));
assertType((projects.value?.[0]?.groups?.[0] ?? null) as Group);
assertType((projects.value?.[0]?.groups?.[0] ?? null)!);
expect(projects.value?.[0]?.submissions).toBe(null);

expect(projects.value?.[1]?.name).toBe('project1');
Expand All @@ -89,13 +89,13 @@ describe('project', (): void => {
expect(projects.value?.[1]?.max_score).toBe(50);
expect(projects.value?.[1]?.score_visible).toBe(false);
expect(projects.value?.[1]?.group_size).toBe(8);
assertType(projects.value?.[1]?.course as Course);
assertType(projects.value?.[1]?.status as SubmissionStatus);
assertType(projects.value?.[1]?.structure_file as File);
assertType(projects.value?.[1]?.course!);
assertType(projects.value?.[1]?.status!);
assertType(projects.value?.[1]?.structure_file!);
expect(projects.value?.[1]?.structureChecks).toBe(null);
expect(projects.value?.[1]?.extra_checks).toBe(null);
assertType(Array.isArray(projects.value?.[1]?.groups));
assertType((projects.value?.[0]?.groups?.[1] ?? null) as Group);
assertType((projects.value?.[0]?.groups?.[1] ?? null)!);
expect(projects.value?.[1]?.submissions).toBe(null);
});

Expand All @@ -118,13 +118,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(5);
assertType(projects.value?.[0]?.course as Course);
assertType(projects.value?.[0]?.status as SubmissionStatus);
assertType(projects.value?.[0]?.structure_file as File);
assertType(projects.value?.[0]?.course!);
assertType(projects.value?.[0]?.status!);
assertType(projects.value?.[0]?.structure_file!);
expect(projects.value?.[0]?.structureChecks).toBe(null);
expect(projects.value?.[0]?.extra_checks).toBe(null);
assertType(Array.isArray(projects.value?.[0]?.groups));
assertType((projects.value?.[0]?.groups?.[0] ?? null) as Group);
assertType((projects.value?.[0]?.groups?.[0] ?? null)!);
expect(projects.value?.[0]?.submissions).toBe(null);

expect(projects.value?.[1]?.name).toBe('project1');
Expand All @@ -137,13 +137,13 @@ describe('project', (): void => {
expect(projects.value?.[1]?.max_score).toBe(50);
expect(projects.value?.[1]?.score_visible).toBe(false);
expect(projects.value?.[1]?.group_size).toBe(8);
assertType(projects.value?.[1]?.course as Course);
assertType(projects.value?.[1]?.status as SubmissionStatus);
assertType(projects.value?.[1]?.structure_file as File);
assertType(projects.value?.[1]?.course!);
assertType(projects.value?.[1]?.status!);
assertType(projects.value?.[1]?.structure_file!);
expect(projects.value?.[1]?.structureChecks).toBe(null);
expect(projects.value?.[1]?.extra_checks).toBe(null);
assertType(Array.isArray(projects.value?.[1]?.groups));
assertType((projects.value?.[0]?.groups?.[1] ?? null) as Group);
assertType((projects.value?.[0]?.groups?.[1] ?? null)!);
expect(projects.value?.[1]?.submissions).toBe(null);
});

Expand Down
11 changes: 5 additions & 6 deletions frontend/src/test/unit/services/setup/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export const courses = [
{
id: '1',
Expand Down Expand Up @@ -135,14 +134,14 @@ const groups = [
score: 20,
project: {},
students: ['1', '2', '3', '000201247011'],
submissions: [submissions[0]]
submissions: [submissions[0]],
},
{
id: '1',
score: 18,
project: {},
students: ['1', '2', '3', '000201247011'],
submissions: [submissions[1]]
submissions: [submissions[1]],
},
];

Expand Down Expand Up @@ -209,10 +208,10 @@ export const projects = [
},
];

groups[0].project = projects[2]
groups[1].project = projects[2]
groups[0].project = projects[2];
groups[1].project = projects[2];

export { groups }
export { groups };

export const faculties = [
{ id: 'sciences', name: 'wetenschappen' },
Expand Down
36 changes: 25 additions & 11 deletions frontend/src/test/unit/services/setup/get_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export const getHandlers = [
return HttpResponse.json(groups.find((x) => x.id === params.id));
}),
http.get(baseUrl + endpoints.submissions.retrieve.replace('{id}', ':id'), ({ params }) => {
const submission = submissions.find((x) => x.id === params.id)
const submission = submissions.find((x) => x.id === params.id);
// Convert to a ResponseSubmission object
const response_submission = {
id: submission?.id,
submission_number: submission?.submission_number,
submission_time: submission?.submission_time,
zip: submission?.zip,
results: [], // We can leave this empty since the conversion to a valid results array is not the purpose of these tests
is_valid: submission?.is_valid
}
is_valid: submission?.is_valid,
};
return HttpResponse.json(response_submission);
}),
http.get(baseUrl + endpoints.structureChecks.retrieve.replace('{id}', ':id'), ({ params }) => {
Expand Down Expand Up @@ -62,8 +62,15 @@ export const getHandlers = [
const submittedSubmissions = project !== null && project !== undefined ? project.submissions : [];

// Convert to a ResponseSubmission object
const projectSubmissions = submissions.filter((x) => submittedSubmissions.map(y => y.id).includes(x.id))
const responseSubmissions = projectSubmissions.map(x => ({ id: x?.id, submission_number: x?.submission_number,submission_time: x?.submission_time,zip: x?.zip,results: [], is_valid: x?.is_valid }) )
const projectSubmissions = submissions.filter((x) => submittedSubmissions.map((y) => y.id).includes(x.id));
const responseSubmissions = projectSubmissions.map((x) => ({
id: x?.id,
submission_number: x?.submission_number,
submission_time: x?.submission_time,
zip: x?.zip,
results: [],
is_valid: x?.is_valid,
}));
return HttpResponse.json(responseSubmissions);
}),
http.get(baseUrl + endpoints.teachers.byCourse.replace('{courseId}', ':id'), ({ params }) => {
Expand Down Expand Up @@ -99,9 +106,9 @@ export const getHandlers = [
http.get(baseUrl + endpoints.submissions.status.replace('{projectId}', ':id'), ({ params }) => {
const project = projects.find((x) => x.id === params.id);
const groups = project !== null && project !== undefined ? project.groups : [];
const groupIds = groups.map(group => group.id);
const groupIds = groups.map((group) => group.id);
const submissions = project !== null && project !== undefined ? project.submissions : [];
const submissionIds = submissions.map(submission => submission.id);
const submissionIds = submissions.map((submission) => submission.id);

return HttpResponse.json({
groups_submitted: new Set(submissions.filter((x) => submissionIds.includes(x.id)).map((x) => x.group)).size,
Expand All @@ -122,11 +129,18 @@ export const getHandlers = [
);
}),
http.get(baseUrl + endpoints.submissions.byGroup.replace('{groupId}', ':id'), ({ params }) => {
const group = groups.find((x) => x.id = params.id)
const groupSubmissions = submissions.filter(x => group?.submissions.includes(x))
const group = groups.find((x) => (x.id = params.id));
const groupSubmissions = submissions.filter((x) => group?.submissions.includes(x));

// Convert to a ResponseSubmission object
const responseSubmissions = groupSubmissions.map(x => ({ id: x?.id, submission_number: x?.submission_number,submission_time: x?.submission_time,zip: x?.zip,results: [], is_valid: x?.is_valid }) )
const responseSubmissions = groupSubmissions.map((x) => ({
id: x?.id,
submission_number: x?.submission_number,
submission_time: x?.submission_time,
zip: x?.zip,
results: [],
is_valid: x?.is_valid,
}));
return HttpResponse.json(responseSubmissions);
}),
http.get(baseUrl + endpoints.faculties.retrieve.replace('{id}', ':id'), ({ params }) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/services/setup/post_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const postHandlers = [
const requestBody = new TextDecoder().decode(buffer);
const newGroup = JSON.parse(requestBody);
groups.push(newGroup);
console.log(JSON.stringify(newGroup))
console.log(JSON.stringify(newGroup));
return HttpResponse.json(groups);
}),
http.post(baseUrl + endpoints.projects.byCourse.replace('{courseId}', ':id'), async ({ request }) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/test/unit/services/submission_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('submissions', (): void => {
expect(submissions.value?.[0]?.id).toEqual('1');
expect(submissions.value?.[0]?.submission_number).toEqual(1);
expect(submissions.value?.[0]?.submission_time).toStrictEqual(new Date('July 21, 2024 01:15:00'));
expect(submissions.value?.[0]?.is_valid).toEqual(true);
expect(submissions.value?.[0]?.is_valid).toEqual(true);

expect(submissions.value?.[1]?.id).toEqual('2');
expect(submissions.value?.[1]?.submission_number).toEqual(2);
expect(submissions.value?.[1]?.submission_time).toStrictEqual(new Date('July 21, 2024 01:15:00'));
expect(submissions.value?.[1]?.is_valid).toEqual(true);
expect(submissions.value?.[1]?.is_valid).toEqual(true);
});
});
1 change: 0 additions & 1 deletion frontend/src/test/unit/types/submission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Submission } from '@/types/submission/Submission.ts';
import { submissionData } from './data';
import { createSubmission } from './helper';


describe('submission type', () => {
it('create instance of submission with correct properties', () => {
const submission = createSubmission(submissionData);
Expand Down

0 comments on commit b129289

Please sign in to comment.