feat(frontend): add stations library reader with tdd
This commit is contained in:
parent
a1e24c6a81
commit
a7256bc13c
7 changed files with 153 additions and 0 deletions
4
frontend/src/tests/fixtures/library/alpha/_meta.yml
vendored
Normal file
4
frontend/src/tests/fixtures/library/alpha/_meta.yml
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
name: Alpha
|
||||
description: alpha station
|
||||
color: '#ff0000'
|
||||
tags: [test, alpha]
|
||||
2
frontend/src/tests/fixtures/library/bad-yaml/_meta.yml
vendored
Normal file
2
frontend/src/tests/fixtures/library/bad-yaml/_meta.yml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name: "unterminated
|
||||
description: never closes
|
||||
4
frontend/src/tests/fixtures/library/beta/_meta.yml
vendored
Normal file
4
frontend/src/tests/fixtures/library/beta/_meta.yml
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
name: Beta
|
||||
description: beta station
|
||||
color: '#00ff00'
|
||||
tags: [test, beta]
|
||||
1
frontend/src/tests/fixtures/library/beta/cover.jpg
vendored
Normal file
1
frontend/src/tests/fixtures/library/beta/cover.jpg
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
fake cover
|
||||
0
frontend/src/tests/fixtures/library/empty/.gitkeep
vendored
Normal file
0
frontend/src/tests/fixtures/library/empty/.gitkeep
vendored
Normal file
56
frontend/src/tests/stations.test.ts
Normal file
56
frontend/src/tests/stations.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { listStations, readMeta } from '@lib/stations';
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
const FIXTURES = path.resolve(HERE, 'fixtures/library');
|
||||
|
||||
describe('readMeta', () => {
|
||||
it('returns null for missing _meta.yml', async () => {
|
||||
expect(await readMeta(FIXTURES, 'empty')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for malformed yaml (logged, not thrown)', async () => {
|
||||
expect(await readMeta(FIXTURES, 'bad-yaml')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when the id has uppercase letters (regex rejection, no fs read)', async () => {
|
||||
expect(await readMeta(FIXTURES, 'NotLower')).toBeNull();
|
||||
});
|
||||
|
||||
it('parses a valid station', async () => {
|
||||
const s = await readMeta(FIXTURES, 'alpha');
|
||||
expect(s).toEqual({
|
||||
id: 'alpha',
|
||||
name: 'Alpha',
|
||||
description: 'alpha station',
|
||||
color: '#ff0000',
|
||||
tags: ['test', 'alpha'],
|
||||
mounts: { mp3: '/alpha.mp3', opus: '/alpha.opus' },
|
||||
cover: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('sets cover when a cover file exists', async () => {
|
||||
const s = await readMeta(FIXTURES, 'beta');
|
||||
expect(s?.cover).toBe('/api/stations/beta/cover');
|
||||
});
|
||||
});
|
||||
|
||||
describe('listStations', () => {
|
||||
it('returns only valid stations, sorted by id', async () => {
|
||||
const ss = await listStations(FIXTURES);
|
||||
expect(ss.map((s) => s.id)).toEqual(['alpha', 'beta']);
|
||||
});
|
||||
|
||||
it('skips empty and bad-yaml folders', async () => {
|
||||
const ss = await listStations(FIXTURES);
|
||||
expect(ss.find((s) => s.id === 'empty')).toBeUndefined();
|
||||
expect(ss.find((s) => s.id === 'bad-yaml')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('handles a non-existent root gracefully', async () => {
|
||||
expect(await listStations('/no/such/dir')).toEqual([]);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue