chore: Cleanup
This commit is contained in:
parent
2d5988552f
commit
b24f577975
6 changed files with 30 additions and 16 deletions
|
@ -12,4 +12,9 @@ DWENGO_PORT=3000
|
||||||
DWENGO_DB_NAME=":memory:"
|
DWENGO_DB_NAME=":memory:"
|
||||||
DWENGO_DB_UPDATE=true
|
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
|
DWENGO_CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000
|
||||||
|
|
|
@ -14,14 +14,12 @@ import { makeTestQuestions } from '../tests/test_assets/questions/questions.test
|
||||||
import { makeTestStudents } from '../tests/test_assets/users/students.testdata.js';
|
import { makeTestStudents } from '../tests/test_assets/users/students.testdata.js';
|
||||||
import { makeTestTeachers } from '../tests/test_assets/users/teachers.testdata.js';
|
import { makeTestTeachers } from '../tests/test_assets/users/teachers.testdata.js';
|
||||||
import { getLogger, Logger } from '../src/logging/initalize.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';
|
import { Group } from '../src/entities/assignments/group.entity.js';
|
||||||
|
|
||||||
const logger: Logger = getLogger();
|
const logger: Logger = getLogger();
|
||||||
|
|
||||||
export async function seedDatabase(envFile = '.env.development.local', testMode = false): Promise<void> {
|
export async function seedORM(orm: MikroORM): Promise<void> {
|
||||||
dotenv.config({ path: envFile });
|
|
||||||
const orm = await initORM(testMode);
|
|
||||||
await orm.schema.clearDatabase();
|
await orm.schema.clearDatabase();
|
||||||
|
|
||||||
const em = forkEntityManager();
|
const em = forkEntityManager();
|
||||||
|
@ -67,6 +65,13 @@ export async function seedDatabase(envFile = '.env.development.local', testMode
|
||||||
]);
|
]);
|
||||||
|
|
||||||
logger.info('Development database seeded successfully!');
|
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();
|
await orm.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,9 @@ import { errorHandler } from '../src/middleware/error-handling/error-handler.js'
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import cors from '../src/middleware/cors';
|
import cors from '../src/middleware/cors';
|
||||||
import { authenticateUser } from '../src/middleware/auth/auth';
|
import { authenticateUser } from '../src/middleware/auth/auth';
|
||||||
import { seedDatabase } from './seed';
|
import { seedORM } from './seed';
|
||||||
|
|
||||||
const envFile = '../.env.test';
|
const envFile = '../.env.test';
|
||||||
console.log(`Using env file: ${envFile}`);
|
|
||||||
|
|
||||||
dotenv.config({ path: envFile });
|
dotenv.config({ path: envFile });
|
||||||
|
|
||||||
|
@ -22,12 +21,9 @@ app.use('/api', apiRouter);
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
async function startServer(): Promise<void> {
|
async function startServer(): Promise<void> {
|
||||||
await seedDatabase(envFile, true);
|
await seedORM(await initORM(true));
|
||||||
await initORM(true);
|
|
||||||
|
|
||||||
app.listen(9876, () => {
|
app.listen(9876);
|
||||||
console.log('Server is running on http://localhost:9876/api');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await startServer();
|
await startServer();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"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:unit": "vitest --run",
|
"test:unit": "VITE_API_BASE_URL='http://localhost:9876/api' vitest --run",
|
||||||
"test:e2e": "playwright test"
|
"test:e2e": "playwright test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import apiClient from "@/services/api-client/api-client.ts";
|
import apiClient from "@/services/api-client/api-client.ts";
|
||||||
import type { AxiosResponse, ResponseType } from "axios";
|
import type { AxiosResponse, ResponseType } from "axios";
|
||||||
import { HttpErrorResponseException } from "@/exception/http-error-response-exception.ts";
|
import { HttpErrorResponseException } from "@/exception/http-error-response-exception.ts";
|
||||||
|
import { apiConfig } from '@/config.ts';
|
||||||
|
|
||||||
export abstract class BaseController {
|
export abstract class BaseController {
|
||||||
protected basePath: string;
|
protected basePath: string;
|
||||||
|
@ -16,9 +17,16 @@ export abstract class BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async get<T>(path: string, queryParams?: QueryParams, responseType?: ResponseType): Promise<T> {
|
protected async get<T>(path: string, queryParams?: QueryParams, responseType?: ResponseType): Promise<T> {
|
||||||
const response = await apiClient.get<T>(this.absolutePathFor(path), { params: queryParams, responseType });
|
try {
|
||||||
BaseController.assertSuccessResponse(response);
|
const response = await apiClient.get<T>(this.absolutePathFor(path), { params: queryParams, responseType });
|
||||||
return response.data;
|
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> {
|
protected async post<T>(path: string, body: unknown, queryParams?: QueryParams): Promise<T> {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export async function setup(): Promise<void> {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Spin up the backend
|
// 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",
|
cwd: "../backend",
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
env: {
|
env: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue