From f6bf37b3bcd155d4cf82698c58fd356bffb044ff Mon Sep 17 00:00:00 2001 From: laurejablonski Date: Fri, 16 May 2025 23:39:27 +0200 Subject: [PATCH] test: extra test (werkt nog niet) --- .../controllers/questions-controller.test.ts | 30 +++++++++++++++++++ frontend/tests/setup-backend.ts | 5 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 frontend/tests/controllers/questions-controller.test.ts diff --git a/frontend/tests/controllers/questions-controller.test.ts b/frontend/tests/controllers/questions-controller.test.ts new file mode 100644 index 00000000..cb657307 --- /dev/null +++ b/frontend/tests/controllers/questions-controller.test.ts @@ -0,0 +1,30 @@ +import { describe, it, expect, beforeEach } from "vitest"; +import { Language } from "@dwengo-1/common/util/language"; +import { QuestionController } from "../../src/controllers/questions"; + +describe("QuestionController Tests", () => { + let controller: QuestionController; + + beforeEach(() => { + const loiDTO = { + hruid: "u_test_multiple_choice", + language: Language.English, + version: 1, + }; + controller = new QuestionController(loiDTO); + }); + + it("should fetch all questions", async () => { + const result = await controller.getAll(true); + expect(result).toHaveProperty("questions"); + expect(Array.isArray(result.questions)).toBe(true); + expect(result.questions.length).toBeGreaterThan(0); + }); + + it("should fetch an question by sequencenumber", async () => { + const questionNumber = 1; // Example sequence number + const result = await controller.getBy(questionNumber); + expect(result).toHaveProperty("question"); + expect(result.question).toHaveProperty("sequenceNumber", questionNumber); + }); +}); diff --git a/frontend/tests/setup-backend.ts b/frontend/tests/setup-backend.ts index 6a0a256d..d1278d55 100644 --- a/frontend/tests/setup-backend.ts +++ b/frontend/tests/setup-backend.ts @@ -1,5 +1,6 @@ import { spawn } from "child_process"; import { ChildProcess, spawnSync } from "node:child_process"; +import { getLogger } from "../../backend/src/logging/initalize"; let backendProcess: ChildProcess; @@ -35,6 +36,8 @@ export async function setup(): Promise { export async function teardown(): Promise { if (backendProcess) { - backendProcess.kill(); + while (!backendProcess.kill()) { + getLogger().error(`Failed to kill backend process! Retrying...`); + } } }