test(frontend): Coverage verbeteren

This commit is contained in:
Tibo De Peuter 2025-04-24 16:54:52 +02:00
parent c47da0c826
commit 4a6b6ee061
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
10 changed files with 387 additions and 16 deletions

View file

@ -0,0 +1,71 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { TeacherController } from '../../src/controllers/teachers';
describe("Test controller teachers", () => {
let controller: TeacherController;
beforeEach(async () => {
controller = new TeacherController();
});
it("Get all teachers", async () => {
const data = await controller.getAll(true);
expect(data.teachers).to.have.length.greaterThan(0);
expect(data.teachers[0]).to.have.property("username");
expect(data.teachers[0]).to.have.property("firstName");
expect(data.teachers[0]).to.have.property("lastName");
});
it("Get teacher by username", async () => {
const username = "testleerkracht1";
const data = await controller.getByUsername(username);
expect(data.teacher.username).to.equal(username);
expect(data.teacher).to.have.property("firstName");
expect(data.teacher).to.have.property("lastName");
});
it("Get teacher by non-existent username", async () => {
const username = "nonexistentuser";
await expect(controller.getByUsername(username)).rejects.toThrow();
});
it("Create a new teacher", async () => {
const newTeacher = {
username: "newteacher",
firstName: "New",
lastName: "Teacher",
};
const data = await controller.createTeacher(newTeacher);
expect(data.teacher.username).to.equal(newTeacher.username);
expect(data.teacher.firstName).to.equal(newTeacher.firstName);
expect(data.teacher.lastName).to.equal(newTeacher.lastName);
});
it("Delete a teacher", async () => {
const username = "newteacher";
const data = await controller.deleteTeacher(username);
expect(data).toBeTruthy();
});
it("Handle deletion of non-existent teacher", async () => {
const username = "nonexistentuser";
await expect(controller.deleteTeacher(username)).rejects.toThrow();
});
it("Get classes for a teacher", async () => {
const username = "testleerkracht1";
const data = await controller.getClasses(username, true);
expect(data.classes).to.have.length.greaterThan(0);
expect(data.classes[0]).to.have.property("id");
expect(data.classes[0]).to.have.property("displayName");
});
it("Get students for a teacher", async () => {
const username = "testleerkracht1";
const data = await controller.getStudents(username, true);
expect(data.students).to.have.length.greaterThan(0);
expect(data.students[0]).to.have.property("username");
expect(data.students[0]).to.have.property("firstName");
expect(data.students[0]).to.have.property("lastName");
});
});