From dfce8b1354f07f3258cea767e585fd60bcb1933b Mon Sep 17 00:00:00 2001 From: "CATERPILLAR\\Braxen" Date: Wed, 17 Apr 2024 10:55:15 +0200 Subject: [PATCH] weird test errors --- server/src/Core/Config.ts | 10 +++++----- server/tests/api.test.ts | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/server/src/Core/Config.ts b/server/src/Core/Config.ts index 6e09d941..b9ea24c4 100644 --- a/server/src/Core/Config.ts +++ b/server/src/Core/Config.ts @@ -306,12 +306,12 @@ export class Config { const example: Record = {}; - for (const key in Config.settingsFields) { - const field = Config.getSettingField( - key as keyof typeof settingsFields - ); - if (field !== undefined && field["default"] !== undefined) + for (const rawKey in Config.settingsFields) { + const key = rawKey as keyof typeof settingsFields; + const field = Config.getSettingField(key); + if (field !== undefined && field["default"] !== undefined) { example[key] = field["default"]; + } } // example["favourites"] = []; // example["streamers"] = []; diff --git a/server/tests/api.test.ts b/server/tests/api.test.ts index 9eb4089c..b10b59b9 100644 --- a/server/tests/api.test.ts +++ b/server/tests/api.test.ts @@ -1,4 +1,5 @@ import { applySessionParser } from "@/Extend/express-session"; +import type { ApiSettingsResponse } from "@common/Api/Api"; import type { Express } from "express"; import express from "express"; import request from "supertest"; @@ -101,18 +102,27 @@ afterAll(() => { describe("settings", () => { it("should return settings", async () => { const res = await request(app).get("/api/v0/settings"); - // console.log(res.status, res.body); + + const body = res.body as ApiSettingsResponse; + expect(res.status).toBe(200); - expect(res.body).toHaveProperty("data.app_name"); - expect(res.body).toHaveProperty("data.version"); - expect(res.body).toHaveProperty("data.config"); + expect(body).toHaveProperty("data.app_name"); + expect(body).toHaveProperty("data.version"); + expect(body).toHaveProperty("data.config"); + expect(Object.keys(body.data.config).length).toBeGreaterThan(0); const fields = Config.settingsFields; for (const key in fields) { const field = fields[key as keyof typeof fields]; - if (field === undefined || ("default" in field && !field.default)) + if (field === undefined) { + console.error("Field is undefined", key); continue; - expect(res.body.data.config[key]).toBeDefined(); + } + if ("default" in field && !field.default) { + console.error("Field has no default", key); + continue; + } + expect(body.data.config[key]).toBeDefined(); } expect(res.body.data.app_name).toBe(AppName);