style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-30 21:24:37 +00:00
parent 9895d22521
commit ee5f69cbc8
20 changed files with 188 additions and 192 deletions

View file

@ -12,14 +12,14 @@ import {
getStudentQuestionsHandler,
createStudentRequestHandler,
getStudentRequestHandler,
deleteClassJoinRequestHandler
deleteClassJoinRequestHandler,
} from '../../src/controllers/students.js';
import {TEST_STUDENTS} from "../test_assets/users/students.testdata.js";
import {NotFoundException} from "../../src/exceptions/not-found-exception.js";
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
import {ConflictException} from "../../src/exceptions/conflict-exception.js";
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
import {StudentDTO} from "../../src/interfaces/student.js";
import { TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { StudentDTO } from '../../src/interfaces/student.js';
describe('Student controllers', () => {
let req: Partial<Request>;
@ -45,7 +45,7 @@ describe('Student controllers', () => {
});
it('Get student', async () => {
req = { params: { username: 'DireStraits' }};
req = { params: { username: 'DireStraits' } };
await getStudentHandler(req as Request, res as Response);
@ -55,17 +55,13 @@ describe('Student controllers', () => {
it('Student not found', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => getStudentHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => getStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('No username', async () => {
req = { params: {} };
await expect(() => getStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => getStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Create and delete student', async () => {
@ -73,8 +69,8 @@ describe('Student controllers', () => {
body: {
username: 'coolstudent',
firstName: 'New',
lastName: 'Student'
}
lastName: 'Student',
},
};
await createStudentHandler(req as Request, res as Response);
@ -88,27 +84,22 @@ describe('Student controllers', () => {
expect(sendStatusMock).toHaveBeenCalledWith(200);
});
it('Create duplicate student', async () => {
req = {
body: {
username: 'DireStraits',
firstName: 'dupe',
lastName: 'dupe'
}
lastName: 'dupe',
},
};
await expect(() => createStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(EntityAlreadyExistsException);
await expect(() => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
});
it('Create student no body', async () => {
req = { body: {} };
await expect(() => createStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Student list', async () => {
@ -133,7 +124,6 @@ describe('Student controllers', () => {
await getStudentClassesHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
const result = jsonMock.mock.lastCall?.[0];
@ -176,9 +166,7 @@ describe('Student controllers', () => {
it('Deleting non-existent student', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => deleteStudentHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('Get join requests by student', async () => {
@ -203,7 +191,7 @@ describe('Student controllers', () => {
it('Create join request', async () => {
req = {
params: { username: 'Noordkaap' },
body: { classId: 'id02' }
body: { classId: 'id02' },
};
await createStudentRequestHandler(req as Request, res as Response);
@ -214,15 +202,12 @@ describe('Student controllers', () => {
it('Create join request duplicate', async () => {
req = {
params: { username: 'Tool' },
body: { classId: 'id02' }
body: { classId: 'id02' },
};
await expect(() => createStudentRequestHandler(req as Request, res as Response))
.rejects
.toThrow(ConflictException);
await expect(() => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
});
it('Delete join request', async () => {
req = {
params: { username: 'Noordkaap', classId: 'id02' },
@ -232,9 +217,6 @@ describe('Student controllers', () => {
expect(sendStatusMock).toHaveBeenCalledWith(204);
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
});

View file

@ -1,17 +1,22 @@
import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest";
import {Request, Response} from "express";
import {setupTestApp} from "../setup-tests.js";
import {NotFoundException} from "../../src/exceptions/not-found-exception.js";
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { Request, Response } from 'express';
import { setupTestApp } from '../setup-tests.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import {
createTeacherHandler,
deleteTeacherHandler,
getAllTeachersHandler, getStudentJoinRequestHandler, getTeacherClassHandler,
getTeacherHandler, getTeacherQuestionHandler, getTeacherStudentHandler, updateStudentJoinRequestHandler
} from "../../src/controllers/teachers.js";
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
import {getStudentRequestHandler} from "../../src/controllers/students.js";
import {TeacherDTO} from "../../src/interfaces/teacher.js";
getAllTeachersHandler,
getStudentJoinRequestHandler,
getTeacherClassHandler,
getTeacherHandler,
getTeacherQuestionHandler,
getTeacherStudentHandler,
updateStudentJoinRequestHandler,
} from '../../src/controllers/teachers.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { getStudentRequestHandler } from '../../src/controllers/students.js';
import { TeacherDTO } from '../../src/interfaces/teacher.js';
describe('Teacher controllers', () => {
let req: Partial<Request>;
@ -37,7 +42,7 @@ describe('Teacher controllers', () => {
});
it('Get teacher', async () => {
req = { params: { username: 'FooFighters' }};
req = { params: { username: 'FooFighters' } };
await getTeacherHandler(req as Request, res as Response);
@ -45,19 +50,15 @@ describe('Teacher controllers', () => {
});
it('Teacher not found', async () => {
req = {params: {username: 'doesnotexist'}};
req = { params: { username: 'doesnotexist' } };
await expect(() => getTeacherHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => getTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('No username', async () => {
req = { params: {} };
await expect(() => getTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => getTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Create and delete teacher', async () => {
@ -65,8 +66,8 @@ describe('Teacher controllers', () => {
body: {
username: 'coolteacher',
firstName: 'New',
lastName: 'Teacher'
}
lastName: 'Teacher',
},
};
await createTeacherHandler(req as Request, res as Response);
@ -86,20 +87,16 @@ describe('Teacher controllers', () => {
username: 'FooFighters',
firstName: 'Dave',
lastName: 'Grohl',
}
},
};
await expect(() => createTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(EntityAlreadyExistsException);
await expect(() => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
});
it('Create teacher no body', async () => {
req = { body: {} };
await expect(() => createTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Teacher list', async () => {
@ -120,12 +117,9 @@ describe('Teacher controllers', () => {
it('Deleting non-existent student', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => deleteTeacherHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('Get teacher classes', async () => {
req = {
params: { username: 'FooFighters' },
@ -196,7 +190,7 @@ describe('Teacher controllers', () => {
req = {
query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' },
params: { classId: 'id02' },
body: { accepted: 'true' }
body: { accepted: 'true' },
};
await updateStudentJoinRequestHandler(req as Request, res as Response);
@ -209,11 +203,7 @@ describe('Teacher controllers', () => {
await getStudentRequestHandler(req as Request, res as Response);
const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status
const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status;
expect(status).toBeTruthy;
});
});