import {initializeTests} from "../testutils" import {Student} from "../../src/entities/users/student.entity"; import {describe, it, expect, beforeAll} from "vitest"; import {getRepository} from "../../src/orm"; import {StudentRepository} from "../../src/data/users/student-repository"; const username = "teststudent"; const firstName = "John"; const lastName = "Doe"; describe("StudentRepository", () => { let studentRepository: StudentRepository; beforeAll(async () => { await initializeTests() studentRepository = getRepository(Student) as StudentRepository; }); it("should return the queried student after he was added", async () => { await studentRepository.insert(new Student(username, firstName, lastName)); let retrievedStudent = await studentRepository.findByUsername(username); expect(retrievedStudent).toBeTruthy(); expect(retrievedStudent?.firstName).toBe(firstName); expect(retrievedStudent?.lastName).toBe(lastName); }); it("should no longer return the queried student after he was removed again", async () => { await studentRepository.deleteByUsername(username); let retrievedStudent = await studentRepository.findByUsername(username); expect(retrievedStudent).toBeNull(); }); });