feat: bootstrap walking skeleton
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildContent } from '../schema';
|
||||
|
||||
const validResources = [{ id: 'gold', name: 'Gold' }];
|
||||
const validActions = [
|
||||
{ id: 'forage', name: 'Forage', durationMs: 3000, yields: { resourceId: 'gold', amount: 1 } },
|
||||
];
|
||||
|
||||
describe('buildContent()', () => {
|
||||
it('validates definitions and indexes them by id', () => {
|
||||
const content = buildContent({ resources: validResources, actions: validActions });
|
||||
expect(content.resourcesById.gold.name).toBe('Gold');
|
||||
expect(content.actionsById.forage.durationMs).toBe(3000);
|
||||
});
|
||||
|
||||
it('applies the startAmount default of 0', () => {
|
||||
const content = buildContent({ resources: validResources, actions: validActions });
|
||||
expect(content.resourcesById.gold.startAmount).toBe(0);
|
||||
});
|
||||
|
||||
it('rejects an action that yields an unknown resource', () => {
|
||||
const actions = [
|
||||
{
|
||||
id: 'forage',
|
||||
name: 'Forage',
|
||||
durationMs: 3000,
|
||||
yields: { resourceId: 'ghost', amount: 1 },
|
||||
},
|
||||
];
|
||||
expect(() => buildContent({ resources: validResources, actions })).toThrow(/unknown resource/i);
|
||||
});
|
||||
|
||||
it('rejects duplicate resource ids', () => {
|
||||
const resources = [
|
||||
{ id: 'gold', name: 'Gold' },
|
||||
{ id: 'gold', name: 'Gold Again' },
|
||||
];
|
||||
expect(() => buildContent({ resources, actions: validActions })).toThrow(/duplicate/i);
|
||||
});
|
||||
|
||||
it('rejects a structurally invalid definition', () => {
|
||||
const actions = [
|
||||
{ id: 'forage', name: 'Forage', durationMs: -1, yields: { resourceId: 'gold', amount: 1 } },
|
||||
];
|
||||
expect(() => buildContent({ resources: validResources, actions })).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user