fix: mode handling
Some checks failed
CI / Test (pull_request) Failing after 22s

This commit is contained in:
2025-01-08 18:23:40 +01:00
parent 6ed44211c4
commit 07fcfc1539
5 changed files with 39 additions and 6 deletions

View File

@@ -29,6 +29,9 @@ jobs:
- name: Run spellcheck
run: bun run check:spell
- name: Run tests
run: bun test:unit
build_and_push:
name: Build and push
strategy:

View File

@@ -23,3 +23,6 @@ jobs:
- name: Run spellcheck
run: bun run check:spell
- name: Run tests
run: bun test:unit

View File

@@ -3,6 +3,7 @@
"build": "bun build --minify --target bun --outdir dist --sourcemap src/app.ts",
"check:code": "eslint src/ --ext .ts",
"check:spell": "cspell --config cspell.code.json **/*.ts",
"test:unit": "bun test",
"start": "bun run src/app.ts"
},
"devDependencies": {

22
src/app.test.ts Normal file
View File

@@ -0,0 +1,22 @@
import { test, expect } from "bun:test";
import { getModes } from "./app";
test("getModes", () => {
test("defaults to false", () => {
expect(getModes([])).toEqual({
connect: false,
disconnect: false,
moved: false,
message: false,
});
});
test("modes are true if set in input", () => {
expect(getModes(["connect", "moved"])).toEqual({
connect: true,
disconnect: false,
moved: false,
message: false,
});
});
});

View File

@@ -36,12 +36,16 @@ const gotifyConfig = {
title: GOTIFY_TITLE,
};
function getModes(): {
export function getModes(modeInput: Mode[]): {
[key in Mode]: boolean;
} {
const modes = MODE.map((mode) => {
return { [mode]: true };
});
const modes = modeInput
.map((mode) => {
return { [mode]: true };
})
.reduce((acc, cur) => {
return { ...acc, ...cur };
});
return {
connect: false,
@@ -87,11 +91,11 @@ TeamSpeak.connect({
password: TS3_PASSWORD,
nickname: TS3_NICKNAME,
}).then((teamspeak) => {
const mode = getModes();
const mode = getModes(MODE);
logger.info(
`connected to TS3 in modes: ${Object.entries(mode)
.filter(([_, value]) => value)
.filter(([, value]) => value)
.map(([key]) => key)
.join(", ")}`
);