Skip to content

Commit

Permalink
fix: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francisvaut committed Apr 5, 2024
1 parent e2ba6fd commit cc99330
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 5.0.3 on 2024-04-05 16:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0009_merge_0008_add_extra_checks_0008_course_faculty"),
]

operations = [
migrations.RenameModel(
old_name="errortemplate",
new_name="ErrorTemplates",
),
migrations.RenameField(
model_name="extracheck",
old_name="docker_image_id",
new_name="docker_image",
),
migrations.AlterField(
model_name="dockerimage",
name="custom",
field=models.BooleanField(default=True),
),
]
64 changes: 64 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/src/composables/services/faculties.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { get, getList, create, deleteId } from '@/composables/services/helpers.t
interface FacultyState {
faculties: Ref<Faculty[] | null>;
faculty: Ref<Faculty | null>;
getFacultyByID: (name: string) => Promise<void>;
getFacultyByID: (id: string) => Promise<void>;
getFaculties: () => Promise<void>;
createFaculty: (facultyData: Faculty) => Promise<void>;
deleteFaculty: (id: string) => Promise<void>;
Expand All @@ -16,8 +16,8 @@ export function useFaculty(): FacultyState {
const faculties = ref<Faculty[] | null>(null);
const faculty = ref<Faculty | null>(null);

async function getFacultyByID(name: string): Promise<void> {
const endpoint = endpoints.faculties.retrieve.replace('{name}', name);
async function getFacultyByID(id: string): Promise<void> {
const endpoint = endpoints.faculties.retrieve.replace('{id}', id);
await get<Faculty>(endpoint, faculty, Faculty.fromJSON);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const endpoints = {
},
faculties: {
index: '/api/faculties/',
retrieve: '/api/faculties/{name}',
retrieve: '/api/faculties/{id}',
},
groups: {
retrieve: '/api/groups/{id}/',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/faculty_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {

describe('faculty', (): void => {
it('gets faculty data by id', async () => {
await getFacultyByID('wetenschappen');
await getFacultyByID('sciences');
expect(faculty.value).not.toBeNull();
expect(faculty.value?.name).toBe('wetenschappen');
});
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/test/unit/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const courses = [
students: ['1', '2', '3', '000201247011'],
projects: ['0', '1'],
parent_course: null,
faculty: null,
name: 'Math',
academic_startyear: 2023,
description: 'Math course',
Expand All @@ -79,6 +80,7 @@ const courses = [
students: [],
projects: [],
parent_course: '3',
faculty: null,
name: 'Sel2',
academic_startyear: 2023,
description: 'Software course',
Expand All @@ -90,6 +92,7 @@ const courses = [
students: [],
projects: [],
parent_course: null,
faculty: null,
name: 'Sel1',
academic_startyear: 2022,
description: 'Software course',
Expand All @@ -101,6 +104,7 @@ const courses = [
students: [],
projects: [],
parent_course: '1',
faculty: null,
name: 'Math',
academic_startyear: 2024,
description: 'Math course',
Expand All @@ -112,6 +116,7 @@ const courses = [
students: [],
projects: [],
parent_course: '12',
faculty: null,
name: 'Math',
academic_startyear: 2025,
description: 'Math course',
Expand All @@ -123,6 +128,7 @@ const courses = [
students: [],
projects: [],
parent_course: null,
faculty: null,
name: 'Club brugge',
academic_startyear: 2023,
description: null,
Expand All @@ -134,13 +140,14 @@ const courses = [
students: [],
projects: [],
parent_course: null,
faculty: null,
name: 'vergeet barbara',
academic_startyear: 2023,
description: null,
},
];

const faculties = [{ name: 'wetenschappen' }, { name: 'voetbal' }];
const faculties = [{ id: 'sciences', name: 'wetenschappen' }, { id:'football', name: 'voetbal' }];

const students = [
{
Expand All @@ -157,6 +164,7 @@ const students = [
roles: ['student'],
courses: ['1', '2', '3'],
groups: ['0'],
faculties: [],
},
{
id: '2',
Expand All @@ -172,6 +180,7 @@ const students = [
roles: ['student'],
courses: [],
groups: [],
faculties: [],
},
{
id: '000201247011',
Expand All @@ -187,6 +196,7 @@ const students = [
roles: ['student'],
courses: [],
groups: [],
faculties: [],
},
{
id: '3',
Expand All @@ -202,6 +212,7 @@ const students = [
roles: ['student'],
courses: [],
groups: [],
faculties: [],
},
];

Expand Down Expand Up @@ -450,8 +461,8 @@ export const restHandlers = [
http.get(baseUrl + endpoints.submissions.byGroup.replace('{groupId}', ':id'), ({ params }) => {
return HttpResponse.json(submissions.filter((x) => x.group === params.id));
}),
http.get(baseUrl + endpoints.faculties.retrieve.replace('{name}', ':name'), ({ params }) => {
return HttpResponse.json(faculties.find((x) => x.name === params.name));
http.get(baseUrl + endpoints.faculties.retrieve.replace('{id}', ':id'), ({ params }) => {
return HttpResponse.json(faculties.find((x) => x.id === params.id));
}),
http.get(baseUrl + endpoints.faculties.index, () => {
return HttpResponse.json(faculties);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/Faculty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Faculty {
* @param faculty
*/
static fromJSON(faculty: Faculty): Faculty {
console.log(JSON.stringify(faculty))
return new Faculty(faculty.id, faculty.name);
}
}

0 comments on commit cc99330

Please sign in to comment.