import { describe, expect, test } from 'vitest'; import { mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { loadConfig } from '../src/config.ts'; function writeToml(body: string): string { const dir = mkdtempSync(join(tmpdir(), 'board-viewer-cfg-')); const path = join(dir, 'auth.toml'); writeFileSync(path, body, 'utf8'); return path; } describe('loadConfig', () => { test('parses gitea_url, gitea_token, and board_viewer_repos from TOML', () => { const path = writeToml(` gitea_url = "https://git.example.com" gitea_token = "abc123" board_viewer_repos = ["OpeItcLoc03/board-viewer", "OpeItcLoc03/books"] `); const cfg = loadConfig(path); expect(cfg).toEqual({ baseUrl: 'https://git.example.com', token: 'abc123', repos: [ { owner: 'OpeItcLoc03', repo: 'board-viewer' }, { owner: 'OpeItcLoc03', repo: 'books' }, ], }); }); test('throws when board_viewer_repos field is missing', () => { const path = writeToml(`gitea_url = "x"\ngitea_token = "t"\n`); expect(() => loadConfig(path)).toThrow(/board_viewer_repos/); }); test('throws when gitea_token is missing', () => { const path = writeToml(`gitea_url = "x"\nboard_viewer_repos = []\n`); expect(() => loadConfig(path)).toThrow(/gitea_token/); }); test('throws on malformed "owner/repo" entry', () => { const path = writeToml(` gitea_url = "x" gitea_token = "t" board_viewer_repos = ["just-owner-no-slash"] `); expect(() => loadConfig(path)).toThrow(/just-owner-no-slash|owner\/repo/); }); });