Files
board-viewer/tests/config.test.ts
vitya d093693795 feat(reader): Gitea client + config + board orchestrator
closes board-viewer-gitea-reader

- src/gitea.ts: HTTP client (getFile, getLatestCommitIso, rawUrl); DI'd fetch
- src/reader.ts: readBoard(client, repos) → TaskRecord[]
- src/config.ts: TOML config loader with board_viewer_repos whitelist
- 25 tests total (9 parser incl. 3 real-repo fixtures, 7 gitea, 5 reader, 4 config)
- emoji contract 🔴🟡🔵🟢 (open/in_progress/paused/blocked/done)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 12:48:37 +03:00

56 lines
1.6 KiB
TypeScript

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/);
});
});