chore: Cleanup

This commit is contained in:
Tibo De Peuter 2025-04-20 20:48:06 +02:00
parent 2d5988552f
commit b24f577975
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
6 changed files with 30 additions and 16 deletions

View file

@ -12,4 +12,9 @@ DWENGO_PORT=3000
DWENGO_DB_NAME=":memory:"
DWENGO_DB_UPDATE=true
DWENGO_AUTH_STUDENT_URL=http://localhost:7080/realms/student
DWENGO_AUTH_STUDENT_JWKS_ENDPOINT=http://localhost:7080/realms/student/protocol/openid-connect/certs
DWENGO_AUTH_TEACHER_URL=http://localhost:7080/realms/teacher
DWENGO_AUTH_TEACHER_JWKS_ENDPOINT=http://localhost:7080/realms/teacher/protocol/openid-connect/certs
DWENGO_CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000

View file

@ -14,14 +14,12 @@ import { makeTestQuestions } from '../tests/test_assets/questions/questions.test
import { makeTestStudents } from '../tests/test_assets/users/students.testdata.js';
import { makeTestTeachers } from '../tests/test_assets/users/teachers.testdata.js';
import { getLogger, Logger } from '../src/logging/initalize.js';
import { Collection } from '@mikro-orm/core';
import { Collection, MikroORM } from '@mikro-orm/core';
import { Group } from '../src/entities/assignments/group.entity.js';
const logger: Logger = getLogger();
export async function seedDatabase(envFile = '.env.development.local', testMode = false): Promise<void> {
dotenv.config({ path: envFile });
const orm = await initORM(testMode);
export async function seedORM(orm: MikroORM): Promise<void> {
await orm.schema.clearDatabase();
const em = forkEntityManager();
@ -67,6 +65,13 @@ export async function seedDatabase(envFile = '.env.development.local', testMode
]);
logger.info('Development database seeded successfully!');
}
export async function seedDatabase(envFile = '.env.development.local', testMode = false): Promise<void> {
dotenv.config({ path: envFile });
const orm = await initORM(testMode);
await seedORM(orm);
await orm.close();
}

View file

@ -5,10 +5,9 @@ import { errorHandler } from '../src/middleware/error-handling/error-handler.js'
import dotenv from 'dotenv';
import cors from '../src/middleware/cors';
import { authenticateUser } from '../src/middleware/auth/auth';
import { seedDatabase } from './seed';
import { seedORM } from './seed';
const envFile = '../.env.test';
console.log(`Using env file: ${envFile}`);
dotenv.config({ path: envFile });
@ -22,12 +21,9 @@ app.use('/api', apiRouter);
app.use(errorHandler);
async function startServer(): Promise<void> {
await seedDatabase(envFile, true);
await initORM(true);
await seedORM(await initORM(true));
app.listen(9876, () => {
console.log('Server is running on http://localhost:9876/api');
});
app.listen(9876);
}
await startServer();