style: fix linting issues met Prettier
This commit is contained in:
parent
0158cc9342
commit
e773b2d611
4 changed files with 70 additions and 66 deletions
|
@ -2,13 +2,16 @@ import { setupTestApp } from '../setup-tests.js';
|
||||||
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
|
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
|
||||||
import { NotFoundException } from "../../src/exceptions/not-found-exception";
|
import { NotFoundException } from '../../src/exceptions/not-found-exception';
|
||||||
import { getClass01 } from "../test_assets/classes/classes.testdata";
|
import { getClass01 } from '../test_assets/classes/classes.testdata';
|
||||||
import { getAssignment01 } from "../test_assets/assignments/assignments.testdata";
|
import { getAssignment01 } from '../test_assets/assignments/assignments.testdata';
|
||||||
|
|
||||||
function createRequestObject(classid: string, assignmentid: string): {
|
function createRequestObject(
|
||||||
|
classid: string,
|
||||||
|
assignmentid: string
|
||||||
|
): {
|
||||||
query: {};
|
query: {};
|
||||||
params: { classid: string; id: string }
|
params: { classid: string; id: string };
|
||||||
} {
|
} {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
|
@ -30,7 +33,7 @@ describe('Assignment controllers', () => {
|
||||||
await setupTestApp();
|
await setupTestApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jsonMock = vi.fn();
|
jsonMock = vi.fn();
|
||||||
statusMock = vi.fn().mockReturnThis();
|
statusMock = vi.fn().mockReturnThis();
|
||||||
|
|
||||||
|
@ -46,27 +49,26 @@ describe('Assignment controllers', () => {
|
||||||
await expect(async () => getAssignmentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
await expect(async () => getAssignmentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 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();
|
const assignment = getAssignment01();
|
||||||
req = createRequestObject(assignment.within.classId as string, (assignment.id ?? 1).toString());
|
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);
|
await getAssignmentsSubmissionsHandler(req as Request, res as Response);
|
||||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import { setupTestApp } from '../setup-tests.js';
|
import { setupTestApp } from '../setup-tests.js';
|
||||||
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
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 { Request, Response } from 'express';
|
||||||
import {NotFoundException} from "../../src/exceptions/not-found-exception";
|
import { NotFoundException } from '../../src/exceptions/not-found-exception';
|
||||||
import {BadRequestException} from "../../src/exceptions/bad-request-exception";
|
import { BadRequestException } from '../../src/exceptions/bad-request-exception';
|
||||||
import {getClass01} from "../test_assets/classes/classes.testdata";
|
import { getClass01 } from '../test_assets/classes/classes.testdata';
|
||||||
describe('Class controllers', () => {
|
describe('Class controllers', () => {
|
||||||
let req: Partial<Request>;
|
let req: Partial<Request>;
|
||||||
let res: Partial<Response>;
|
let res: Partial<Response>;
|
||||||
|
@ -49,8 +56,8 @@ describe('Class controllers', () => {
|
||||||
|
|
||||||
it('Error class not found', async () => {
|
it('Error class not found', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { id: 'doesnotexist'},
|
params: { id: 'doesnotexist' },
|
||||||
}
|
};
|
||||||
|
|
||||||
await expect(async () => getClassHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
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);
|
await getAllClassesHandler(req as Request, res as Response);
|
||||||
|
|
||||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
|
||||||
})
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,12 +6,12 @@ import {
|
||||||
deleteGroupHandler,
|
deleteGroupHandler,
|
||||||
getAllGroupsHandler,
|
getAllGroupsHandler,
|
||||||
getGroupHandler,
|
getGroupHandler,
|
||||||
getGroupSubmissionsHandler
|
getGroupSubmissionsHandler,
|
||||||
} from '../../src/controllers/groups.js';
|
} from '../../src/controllers/groups.js';
|
||||||
import { NotFoundException } from "../../src/exceptions/not-found-exception";
|
import { NotFoundException } from '../../src/exceptions/not-found-exception';
|
||||||
import { getClass01 } from "../test_assets/classes/classes.testdata";
|
import { getClass01 } from '../test_assets/classes/classes.testdata';
|
||||||
import { getAssignment01, getAssignment02 } from "../test_assets/assignments/assignments.testdata";
|
import { getAssignment01, getAssignment02 } from '../test_assets/assignments/assignments.testdata';
|
||||||
import { getTestGroup01 } from "../test_assets/assignments/groups.testdata";
|
import { getTestGroup01 } from '../test_assets/assignments/groups.testdata';
|
||||||
|
|
||||||
function createRequestObject(classid: string, assignmentid: string, groupNumber: string) {
|
function createRequestObject(classid: string, assignmentid: string, groupNumber: string) {
|
||||||
return {
|
return {
|
||||||
|
@ -35,7 +35,7 @@ describe('Group controllers', () => {
|
||||||
await setupTestApp();
|
await setupTestApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jsonMock = vi.fn();
|
jsonMock = vi.fn();
|
||||||
statusMock = vi.fn().mockReturnThis();
|
statusMock = vi.fn().mockReturnThis();
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ describe('Group controllers', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(async () => getGroupHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
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 () => {
|
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() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ group: expect.anything() }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Create and delete', async () => {
|
it('Create and delete', async () => {
|
||||||
const assignment = getAssignment02();
|
const assignment = getAssignment02();
|
||||||
const classId = assignment.within.classId as string;
|
const classId = assignment.within.classId as string;
|
||||||
req = createRequestObject(classId, (assignment.id ?? 1).toString(), '1');
|
req = createRequestObject(classId, (assignment.id ?? 1).toString(), '1');
|
||||||
req.body = {
|
req.body = {
|
||||||
members: [
|
members: ['Noordkaap', 'DireStraits'],
|
||||||
'Noordkaap',
|
|
||||||
'DireStraits',
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await createGroupHandler(req as Request, res as Response);
|
await createGroupHandler(req as Request, res as Response);
|
||||||
|
|
|
@ -2,24 +2,26 @@ import { setupTestApp } from '../setup-tests.js';
|
||||||
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
||||||
import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js';
|
import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { NotFoundException } from "../../src/exceptions/not-found-exception";
|
import { NotFoundException } from '../../src/exceptions/not-found-exception';
|
||||||
import { getClass02 } from "../test_assets/classes/classes.testdata";
|
import { getClass02 } from '../test_assets/classes/classes.testdata';
|
||||||
|
|
||||||
|
function createRequestObject(
|
||||||
function createRequestObject(hruid: string, submissionNumber: string): {
|
hruid: string,
|
||||||
|
submissionNumber: string
|
||||||
|
): {
|
||||||
query: { language: string; version: string };
|
query: { language: string; version: string };
|
||||||
params: { hruid: string; id: string }
|
params: { hruid: string; id: string };
|
||||||
} {
|
} {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
hruid: hruid,
|
hruid: hruid,
|
||||||
id: submissionNumber,
|
id: submissionNumber,
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
language: 'en',
|
language: 'en',
|
||||||
version: '1',
|
version: '1',
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Submission controllers', () => {
|
describe('Submission controllers', () => {
|
||||||
|
@ -33,7 +35,7 @@ describe('Submission controllers', () => {
|
||||||
await setupTestApp();
|
await setupTestApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jsonMock = vi.fn();
|
jsonMock = vi.fn();
|
||||||
statusMock = vi.fn().mockReturnThis();
|
statusMock = vi.fn().mockReturnThis();
|
||||||
|
|
||||||
|
@ -44,17 +46,16 @@ describe('Submission controllers', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('error submission is not found', async () => {
|
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);
|
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 () => {
|
it('should return a list of submissions for a learning object', async () => {
|
||||||
req = createRequestObject(getClass02().classId as string, 'irrelevant');
|
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() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ submissions: expect.anything() }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue