style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-05-10 18:07:50 +00:00
parent 0158cc9342
commit e773b2d611
4 changed files with 70 additions and 66 deletions

View file

@ -2,13 +2,16 @@ import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { Request, Response } from 'express';
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
import { NotFoundException } from "../../src/exceptions/not-found-exception";
import { getClass01 } from "../test_assets/classes/classes.testdata";
import { getAssignment01 } from "../test_assets/assignments/assignments.testdata";
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
import { getAssignment01 } from '../test_assets/assignments/assignments.testdata';
function createRequestObject(classid: string, assignmentid: string): {
function createRequestObject(
classid: string,
assignmentid: string
): {
query: {};
params: { classid: string; id: string }
params: { classid: string; id: string };
} {
return {
params: {
@ -30,7 +33,7 @@ describe('Assignment controllers', () => {
await setupTestApp();
});
beforeEach(async () => {
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
@ -46,27 +49,26 @@ describe('Assignment controllers', () => {
await expect(async () => getAssignmentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return an assignment', async () => {
const assignment = getAssignment01();
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
await getAssignmentHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignment: expect.anything() }));
});
it('should return a list of assignments', async () => {
req = createRequestObject(getClass01().classId as string, 'irrelevant');
await getAllAssignmentsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignments: expect.anything() })); });
it('should return a list of submissions for an assignment', async () => {
it('should return an assignment', async () => {
const assignment = getAssignment01();
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
await getAssignmentHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignment: expect.anything() }));
});
it('should return a list of assignments', async () => {
req = createRequestObject(getClass01().classId as string, 'irrelevant');
await getAllAssignmentsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ assignments: expect.anything() }));
});
it('should return a list of submissions for an assignment', async () => {
const assignment = getAssignment01();
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
await getAssignmentsSubmissionsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
})
})
});
});

View file

@ -1,10 +1,17 @@
import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { createClassHandler, deleteClassHandler, getAllClassesHandler, getClassHandler, getClassStudentsHandler, getTeacherInvitationsHandler } from '../../src/controllers/classes.js';
import {
createClassHandler,
deleteClassHandler,
getAllClassesHandler,
getClassHandler,
getClassStudentsHandler,
getTeacherInvitationsHandler,
} from '../../src/controllers/classes.js';
import { Request, Response } from 'express';
import {NotFoundException} from "../../src/exceptions/not-found-exception";
import {BadRequestException} from "../../src/exceptions/bad-request-exception";
import {getClass01} from "../test_assets/classes/classes.testdata";
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { BadRequestException } from '../../src/exceptions/bad-request-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
describe('Class controllers', () => {
let req: Partial<Request>;
let res: Partial<Response>;
@ -49,8 +56,8 @@ describe('Class controllers', () => {
it('Error class not found', async () => {
req = {
params: { id: 'doesnotexist'},
}
params: { id: 'doesnotexist' },
};
await expect(async () => getClassHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
@ -112,6 +119,5 @@ describe('Class controllers', () => {
await getAllClassesHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
})
});
});

View file

@ -6,12 +6,12 @@ import {
deleteGroupHandler,
getAllGroupsHandler,
getGroupHandler,
getGroupSubmissionsHandler
getGroupSubmissionsHandler,
} from '../../src/controllers/groups.js';
import { NotFoundException } from "../../src/exceptions/not-found-exception";
import { getClass01 } from "../test_assets/classes/classes.testdata";
import { getAssignment01, getAssignment02 } from "../test_assets/assignments/assignments.testdata";
import { getTestGroup01 } from "../test_assets/assignments/groups.testdata";
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass01 } from '../test_assets/classes/classes.testdata';
import { getAssignment01, getAssignment02 } from '../test_assets/assignments/assignments.testdata';
import { getTestGroup01 } from '../test_assets/assignments/groups.testdata';
function createRequestObject(classid: string, assignmentid: string, groupNumber: string) {
return {
@ -35,7 +35,7 @@ describe('Group controllers', () => {
await setupTestApp();
});
beforeEach(async () => {
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
@ -56,7 +56,6 @@ describe('Group controllers', () => {
};
await expect(async () => getGroupHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('should return 404 not found on a non-existing assignment', async () => {
@ -95,16 +94,12 @@ describe('Group controllers', () => {
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ group: expect.anything() }));
});
it('Create and delete', async () => {
const assignment = getAssignment02();
const classId = assignment.within.classId as string;
req = createRequestObject(classId, (assignment.id ?? 1).toString(), '1');
req.body = {
members: [
'Noordkaap',
'DireStraits',
]
members: ['Noordkaap', 'DireStraits'],
};
await createGroupHandler(req as Request, res as Response);

View file

@ -2,24 +2,26 @@ import { setupTestApp } from '../setup-tests.js';
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js';
import { Request, Response } from 'express';
import { NotFoundException } from "../../src/exceptions/not-found-exception";
import { getClass02 } from "../test_assets/classes/classes.testdata";
import { NotFoundException } from '../../src/exceptions/not-found-exception';
import { getClass02 } from '../test_assets/classes/classes.testdata';
function createRequestObject(hruid: string, submissionNumber: string): {
function createRequestObject(
hruid: string,
submissionNumber: string
): {
query: { language: string; version: string };
params: { hruid: string; id: string }
params: { hruid: string; id: string };
} {
return {
params: {
hruid: hruid,
id: submissionNumber,
},
query: {
language: 'en',
version: '1',
},
}
return {
params: {
hruid: hruid,
id: submissionNumber,
},
query: {
language: 'en',
version: '1',
},
};
}
describe('Submission controllers', () => {
@ -33,7 +35,7 @@ describe('Submission controllers', () => {
await setupTestApp();
});
beforeEach(async () => {
beforeEach(async () => {
jsonMock = vi.fn();
statusMock = vi.fn().mockReturnThis();
@ -44,17 +46,16 @@ describe('Submission controllers', () => {
});
it('error submission is not found', async () => {
req = createRequestObject('id01', '1000000');
req = createRequestObject('id01', '1000000');
await expect(async () => getSubmissionHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
});
it('should return a list of submissions for a learning object', async () => {
req = createRequestObject(getClass02().classId as string, 'irrelevant');
it('should return a list of submissions for a learning object', async () => {
req = createRequestObject(getClass02().classId as string, 'irrelevant');
await getAllSubmissionsHandler(req as Request, res as Response);
await getAllSubmissionsHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
});
});