Merge remote-tracking branch 'origin/dev' into feat/endpoints-beschermen-met-authenticatie-#105
This commit is contained in:
commit
c13788f269
26 changed files with 9315 additions and 630 deletions
47
backend/tests/controllers/classes.test.ts
Normal file
47
backend/tests/controllers/classes.test.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { setupTestApp } from '../setup-tests.js';
|
||||
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
||||
import { Request, Response } from 'express';
|
||||
import { createClassHandler, deleteClassHandler } from '../../src/controllers/classes';
|
||||
|
||||
describe('Class controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
let res: Partial<Response>;
|
||||
|
||||
let jsonMock: Mock;
|
||||
let statusMock: Mock;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
jsonMock = vi.fn();
|
||||
statusMock = vi.fn().mockReturnThis();
|
||||
|
||||
res = {
|
||||
json: jsonMock,
|
||||
status: statusMock,
|
||||
};
|
||||
});
|
||||
|
||||
it('create and delete class', async () => {
|
||||
req = {
|
||||
body: { displayName: 'coole_nieuwe_klas' },
|
||||
};
|
||||
|
||||
await createClassHandler(req as Request, res as Response);
|
||||
|
||||
const result = jsonMock.mock.lastCall?.[0];
|
||||
// Console.log('class', result.class);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ class: expect.anything() }));
|
||||
|
||||
req = {
|
||||
params: { id: result.class.id },
|
||||
};
|
||||
|
||||
await deleteClassHandler(req as Request, res as Response);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ class: expect.anything() }));
|
||||
});
|
||||
});
|
|
@ -21,6 +21,7 @@ import { BadRequestException } from '../../src/exceptions/bad-request-exception.
|
|||
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
|
||||
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
|
||||
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
||||
import { getClass02 } from '../test_assets/classes/classes.testdata';
|
||||
|
||||
describe('Student controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -186,7 +187,7 @@ describe('Student controllers', () => {
|
|||
|
||||
it('Get join request by student and class', async () => {
|
||||
req = {
|
||||
params: { username: 'PinkFloyd', classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
params: { username: 'PinkFloyd', classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await getStudentRequestHandler(req as Request, res as Response);
|
||||
|
@ -201,7 +202,7 @@ describe('Student controllers', () => {
|
|||
it('Create and delete join request', async () => {
|
||||
req = {
|
||||
params: { username: 'TheDoors' },
|
||||
body: { classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
body: { classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await createStudentRequestHandler(req as Request, res as Response);
|
||||
|
@ -209,7 +210,7 @@ describe('Student controllers', () => {
|
|||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() }));
|
||||
|
||||
req = {
|
||||
params: { username: 'TheDoors', classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
params: { username: 'TheDoors', classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await deleteClassJoinRequestHandler(req as Request, res as Response);
|
||||
|
@ -222,7 +223,7 @@ describe('Student controllers', () => {
|
|||
it('Create join request student already in class error', async () => {
|
||||
req = {
|
||||
params: { username: 'Noordkaap' },
|
||||
body: { classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
body: { classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await expect(async () => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
|
||||
|
@ -231,7 +232,7 @@ describe('Student controllers', () => {
|
|||
it('Create join request duplicate', async () => {
|
||||
req = {
|
||||
params: { username: 'Tool' },
|
||||
body: { classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
body: { classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await expect(async () => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
|
||||
|
|
|
@ -12,6 +12,7 @@ import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invit
|
|||
import { getClassHandler } from '../../src/controllers/classes';
|
||||
import { BadRequestException } from '../../src/exceptions/bad-request-exception';
|
||||
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
|
||||
import { getClass02 } from '../test_assets/classes/classes.testdata';
|
||||
|
||||
describe('Teacher controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -57,7 +58,7 @@ describe('Teacher controllers', () => {
|
|||
const body = {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
class: getClass02().classId,
|
||||
} as TeacherInvitationData;
|
||||
req = { body };
|
||||
|
||||
|
@ -67,7 +68,7 @@ describe('Teacher controllers', () => {
|
|||
params: {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
classId: getClass02().classId,
|
||||
},
|
||||
body: { accepted: 'false' },
|
||||
};
|
||||
|
@ -80,7 +81,7 @@ describe('Teacher controllers', () => {
|
|||
params: {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'FooFighters',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
classId: getClass02().classId,
|
||||
},
|
||||
};
|
||||
await getInvitationHandler(req as Request, res as Response);
|
||||
|
@ -100,7 +101,7 @@ describe('Teacher controllers', () => {
|
|||
const body = {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'FooFighters',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
class: getClass02().classId,
|
||||
} as TeacherInvitationData;
|
||||
req = { body };
|
||||
|
||||
|
@ -111,7 +112,7 @@ describe('Teacher controllers', () => {
|
|||
|
||||
req = {
|
||||
params: {
|
||||
id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
id: getClass02().classId,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import { BadRequestException } from '../../src/exceptions/bad-request-exception.
|
|||
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
|
||||
import { getStudentRequestsHandler } from '../../src/controllers/students.js';
|
||||
import { getClassHandler } from '../../src/controllers/classes';
|
||||
import { getClass02 } from '../test_assets/classes/classes.testdata';
|
||||
|
||||
describe('Teacher controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -167,7 +168,7 @@ describe('Teacher controllers', () => {
|
|||
|
||||
it('Get join requests by class', async () => {
|
||||
req = {
|
||||
params: { classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
params: { classId: getClass02().classId },
|
||||
};
|
||||
|
||||
await getStudentJoinRequestHandler(req as Request, res as Response);
|
||||
|
@ -181,7 +182,7 @@ describe('Teacher controllers', () => {
|
|||
|
||||
it('Update join request status', async () => {
|
||||
req = {
|
||||
params: { classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', studentUsername: 'PinkFloyd' },
|
||||
params: { classId: getClass02().classId, studentUsername: 'PinkFloyd' },
|
||||
body: { accepted: 'true' },
|
||||
};
|
||||
|
||||
|
@ -199,7 +200,7 @@ describe('Teacher controllers', () => {
|
|||
expect(status).toBeTruthy();
|
||||
|
||||
req = {
|
||||
params: { id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' },
|
||||
params: { id: getClass02().classId },
|
||||
};
|
||||
|
||||
await getClassHandler(req as Request, res as Response);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue