42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { availableGames, createCatalog, getGame, loadDefaultCatalog } from '../../src/sim/catalog';
|
|
import { START_DATE, parseISO } from '../../src/sim/calendar';
|
|
import { TEST_GAMES, testCatalog } from './helpers';
|
|
|
|
describe('catalog', () => {
|
|
it('indexes games by id', () => {
|
|
expect(getGame(testCatalog(), 'sml').title).toBe('Super Mario Land');
|
|
});
|
|
|
|
it('throws on unknown id', () => {
|
|
expect(() => getGame(testCatalog(), 'nope')).toThrow('Unknown game: nope');
|
|
});
|
|
|
|
it('rejects duplicate ids', () => {
|
|
expect(() => createCatalog([TEST_GAMES[0], TEST_GAMES[0]])).toThrow('Duplicate game id: tetris');
|
|
});
|
|
|
|
it('only lists released games', () => {
|
|
const ids = availableGames(testCatalog(), START_DATE).map((g) => g.id);
|
|
expect(ids).toEqual(['tetris', 'sml']);
|
|
const later = availableGames(testCatalog(), parseISO('1991-06-01')).map((g) => g.id);
|
|
expect(later).toContain('future');
|
|
});
|
|
|
|
it('loads the default GB catalog with francs converted to cents', () => {
|
|
const catalog = loadDefaultCatalog();
|
|
expect(catalog.games.length).toBeGreaterThanOrEqual(20);
|
|
expect(getGame(catalog, 'super-mario-land').launchPriceCents).toBe(3796);
|
|
for (const g of catalog.games) {
|
|
expect(g.releaseDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
expect(g.basePopularity).toBeGreaterThanOrEqual(0);
|
|
expect(g.basePopularity).toBeLessThanOrEqual(100);
|
|
}
|
|
expect(availableGames(catalog, START_DATE).map((g) => g.id)).toContain('tetris');
|
|
});
|
|
|
|
it('rejects games with a non-positive launch price', () => {
|
|
expect(() => createCatalog([{ ...TEST_GAMES[0], id: 'free', launchPriceCents: 0 }])).toThrow('Invalid launch price: free');
|
|
});
|
|
});
|