fix: mode handling #10
@@ -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:
|
||||
|
||||
@@ -23,3 +23,6 @@ jobs:
|
||||
|
||||
- name: Run spellcheck
|
||||
run: bun run check:spell
|
||||
|
||||
- name: Run tests
|
||||
run: bun test:unit
|
||||
|
||||
@@ -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
22
src/app.test.ts
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
12
src/app.ts
12
src/app.ts
@@ -36,11 +36,15 @@ const gotifyConfig = {
|
||||
title: GOTIFY_TITLE,
|
||||
};
|
||||
|
||||
function getModes(): {
|
||||
export function getModes(modeInput: Mode[]): {
|
||||
[key in Mode]: boolean;
|
||||
} {
|
||||
const modes = MODE.map((mode) => {
|
||||
const modes = modeInput
|
||||
.map((mode) => {
|
||||
return { [mode]: true };
|
||||
})
|
||||
.reduce((acc, cur) => {
|
||||
return { ...acc, ...cur };
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -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(", ")}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user