mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
- 211 tests across 15 files covering services (tracking, discovery, metadata, backup, credits, webhooks, settings, update-check, colors, person), utilities (config, cron, providers, title-theme), and TMDB image URL helpers - `lib/test-preload.ts` + `bunfig.toml` wire up a global in-memory SQLite DB with migrations for all DB-backed tests - `lib/test-utils.ts` provides `clearAllTables()` and seed helpers (insertUser, insertTitle, insertTvShow, insertMovieWatch, etc.) - Export `getBackupSource`, `isKnownBackup`, `isValidBackupFilename`, `buildBackupCron`, `performUpdateCheck` internals for direct testing - GitHub Actions workflow runs `bun test --coverage` on push/PR to main
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { beforeEach, describe, expect, test } from "bun:test";
|
|
import { clearAllTables, insertUser } from "@/lib/test-utils";
|
|
import {
|
|
getSetting,
|
|
getUserCount,
|
|
isRegistrationOpen,
|
|
setSetting,
|
|
} from "./settings";
|
|
|
|
beforeEach(() => {
|
|
clearAllTables();
|
|
});
|
|
|
|
// ── getSetting / setSetting ─────────────────────────────────────────
|
|
|
|
describe("getSetting / setSetting", () => {
|
|
test("returns null for missing key", () => {
|
|
expect(getSetting("nonexistent")).toBeNull();
|
|
});
|
|
|
|
test("stores and retrieves a value", () => {
|
|
setSetting("theme", "dark");
|
|
expect(getSetting("theme")).toBe("dark");
|
|
});
|
|
|
|
test("upserts: overwrites existing value", () => {
|
|
setSetting("theme", "dark");
|
|
setSetting("theme", "light");
|
|
expect(getSetting("theme")).toBe("light");
|
|
});
|
|
});
|
|
|
|
// ── getUserCount ────────────────────────────────────────────────────
|
|
|
|
describe("getUserCount", () => {
|
|
test("returns 0 when no users", () => {
|
|
expect(getUserCount()).toBe(0);
|
|
});
|
|
|
|
test("returns correct count", () => {
|
|
insertUser("user-1");
|
|
insertUser("user-2");
|
|
expect(getUserCount()).toBe(2);
|
|
});
|
|
});
|
|
|
|
// ── isRegistrationOpen ──────────────────────────────────────────────
|
|
|
|
describe("isRegistrationOpen", () => {
|
|
test("returns true when no users exist (first-run)", () => {
|
|
expect(isRegistrationOpen()).toBe(true);
|
|
});
|
|
|
|
test("returns false when users exist and setting is not set", () => {
|
|
insertUser();
|
|
expect(isRegistrationOpen()).toBe(false);
|
|
});
|
|
|
|
test("returns true when users exist and setting is 'true'", () => {
|
|
insertUser();
|
|
setSetting("registrationOpen", "true");
|
|
expect(isRegistrationOpen()).toBe(true);
|
|
});
|
|
|
|
test("returns false when users exist and setting is 'false'", () => {
|
|
insertUser();
|
|
setSetting("registrationOpen", "false");
|
|
expect(isRegistrationOpen()).toBe(false);
|
|
});
|
|
});
|