fix: mode handling #10

Closed
t.behrendt wants to merge 2 commits from fix-mode-handling into main
6 changed files with 48 additions and 6 deletions

9
.env.test Normal file
View File

@@ -0,0 +1,9 @@
LOG_LEVEL=debug
TS3_HOST=fake
TS3_USERNAME=fake
TS3_PASSWORD=fake
TS3_NICKNAME=fake
GOTIFY_URL=https://example.com
GOTIFY_TOKEN=fake
GOTIFY_TITLE=fake
MODE='[]'

View File

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

View File

@@ -23,3 +23,6 @@ jobs:
- name: Run spellcheck - name: Run spellcheck
run: bun run check:spell 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", "build": "bun build --minify --target bun --outdir dist --sourcemap src/app.ts",
"check:code": "eslint src/ --ext .ts", "check:code": "eslint src/ --ext .ts",
"check:spell": "cspell --config cspell.code.json **/*.ts", "check:spell": "cspell --config cspell.code.json **/*.ts",
"test:unit": "NODE_ENV=test bun test",
"start": "bun run src/app.ts" "start": "bun run src/app.ts"
}, },
"devDependencies": { "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, title: GOTIFY_TITLE,
}; };
function getModes(): { export function getModes(modeInput: Mode[]): {
[key in Mode]: boolean; [key in Mode]: boolean;
} { } {
const modes = MODE.map((mode) => { const modes = modeInput
return { [mode]: true }; .map((mode) => {
}); return { [mode]: true };
})
.reduce((acc, cur) => {
return { ...acc, ...cur };
});
return { return {
connect: false, connect: false,
@@ -87,11 +91,11 @@ TeamSpeak.connect({
password: TS3_PASSWORD, password: TS3_PASSWORD,
nickname: TS3_NICKNAME, nickname: TS3_NICKNAME,
}).then((teamspeak) => { }).then((teamspeak) => {
const mode = getModes(); const mode = getModes(MODE);
logger.info( logger.info(
`connected to TS3 in modes: ${Object.entries(mode) `connected to TS3 in modes: ${Object.entries(mode)
.filter(([_, value]) => value) .filter(([, value]) => value)
.map(([key]) => key) .map(([key]) => key)
.join(", ")}` .join(", ")}`
); );