test: student repository is getest
This commit is contained in:
parent
3cd7496989
commit
5502c6c58e
5 changed files with 2520 additions and 393 deletions
|
@ -11,13 +11,15 @@
|
||||||
"format": "prettier --write src/",
|
"format": "prettier --write src/",
|
||||||
"format-check": "prettier --check src/",
|
"format-check": "prettier --check src/",
|
||||||
"lint": "eslint . --fix",
|
"lint": "eslint . --fix",
|
||||||
|
"test": "vitest",
|
||||||
"test:unit": "vitest"
|
"test:unit": "vitest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mikro-orm/core": "^6.4.6",
|
"@mikro-orm/core": "^6.4.9",
|
||||||
|
"@mikro-orm/knex": "^6.4.9",
|
||||||
"@mikro-orm/postgresql": "^6.4.6",
|
"@mikro-orm/postgresql": "^6.4.6",
|
||||||
"@mikro-orm/reflection": "^6.4.6",
|
"@mikro-orm/reflection": "^6.4.6",
|
||||||
"@mikro-orm/sqlite": "6.4.6",
|
"@mikro-orm/sqlite": "^6.4.9",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"axios": "^1.8.1",
|
"axios": "^1.8.1",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
|
|
|
@ -15,6 +15,20 @@ describe('StudentRepository', () => {
|
||||||
studentRepository = getStudentRepository();
|
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 () => {
|
it('should return the queried student after he was added', async () => {
|
||||||
await studentRepository.insert(
|
await studentRepository.insert(
|
||||||
new Student(username, firstName, lastName)
|
new Student(username, firstName, lastName)
|
0
backend/tests/data/teachers.test.ts
Normal file
0
backend/tests/data/teachers.test.ts
Normal 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';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
export async function setupTestApp() {
|
export async function setupTestApp() {
|
||||||
dotenv.config({ path: '.env.test' });
|
dotenv.config({ path: '.env.test' });
|
||||||
await initORM(true);
|
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]);
|
||||||
}
|
}
|
||||||
|
|
2882
package-lock.json
generated
2882
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue