test: student repository is getest

This commit is contained in:
Laure Jablonski 2025-03-07 11:48:52 +01:00
parent 3cd7496989
commit 5502c6c58e
5 changed files with 2520 additions and 393 deletions

View file

@ -15,6 +15,20 @@ describe('StudentRepository', () => {
studentRepository = getStudentRepository();
});
it('should not return a student because username does not exist', async() => {
const student = await studentRepository.findByUsername('test');
expect(student).toBeNull();
});
it('should return student from the datbase', async() => {
const student = await studentRepository.findByUsername('DireStraits');
expect(student).toBeTruthy();
expect(student?.firstName).toBe('Mark');
expect(student?.lastName).toBe('Knopfler');
})
it('should return the queried student after he was added', async () => {
await studentRepository.insert(
new Student(username, firstName, lastName)

View file

View file

@ -1,7 +1,16 @@
import { initORM } from '../src/orm.js';
import { Student } from '../src/entities/users/student.entity.js';
import { forkEntityManager, initORM } from '../src/orm.js';
import dotenv from 'dotenv';
export async function setupTestApp() {
dotenv.config({ path: '.env.test' });
await initORM(true);
const em = forkEntityManager();
const user01 = em.create(Student, {username: 'Noordkaap', firstName: 'Stijn', lastName: 'Meuris'})
const user02 = em.create(Student, {username: 'DireStraits', firstName: 'Mark', lastName: 'Knopfler'})
const user03 = em.create(Student, {username: 'SmashingPumpkins', firstName: 'Billy', lastName: 'Corgan'})
await em.persistAndFlush([user01, user02, user03]);
}