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();

View file

@ -12,7 +12,7 @@
"format": "prettier --write src/",
"format-check": "prettier --check src/",
"lint": "eslint . --fix",
"test:unit": "vitest --run",
"test:unit": "VITE_API_BASE_URL='http://localhost:9876/api' vitest --run",
"test:e2e": "playwright test"
},
"dependencies": {

View file

@ -1,6 +1,7 @@
import apiClient from "@/services/api-client/api-client.ts";
import type { AxiosResponse, ResponseType } from "axios";
import { HttpErrorResponseException } from "@/exception/http-error-response-exception.ts";
import { apiConfig } from '@/config.ts';
export abstract class BaseController {
protected basePath: string;
@ -16,9 +17,16 @@ export abstract class BaseController {
}
protected async get<T>(path: string, queryParams?: QueryParams, responseType?: ResponseType): Promise<T> {
const response = await apiClient.get<T>(this.absolutePathFor(path), { params: queryParams, responseType });
BaseController.assertSuccessResponse(response);
return response.data;
try {
const response = await apiClient.get<T>(this.absolutePathFor(path), { params: queryParams, responseType });
BaseController.assertSuccessResponse(response);
return response.data;
} catch (error) {
if (error instanceof HttpErrorResponseException) {
throw error;
}
throw new Error(`An unexpected error occurred while fetching data from ${apiConfig.baseUrl}${this.absolutePathFor(path)}: ${error}`);
}
}
protected async post<T>(path: string, body: unknown, queryParams?: QueryParams): Promise<T> {

View file

@ -22,7 +22,7 @@ export async function setup(): Promise<void> {
});
// Spin up the backend
backendProcess = spawn("tsx", ["--env-file=.env.development.example", "tool/startTestApp.ts"], {
backendProcess = spawn("tsx", ["--env-file=.env.test", "tool/startTestApp.ts"], {
cwd: "../backend",
stdio: "inherit",
env: {