Skip to content

Commit

Permalink
weird test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBrax committed Apr 17, 2024
1 parent c622243 commit dfce8b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions server/src/Core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ export class Config {

const example: Record<string, string | boolean | number | string[]> =
{};
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"] = [];
Expand Down
22 changes: 16 additions & 6 deletions server/tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dfce8b1

Please sign in to comment.