dd-timer/tests/unit/application/CommandBus.test.ts
POL Mickaël 203c423f19 test: 302 tests unitaires + 20 E2E Playwright (couverture 94%)
- Unit : domain (GaugeCalculator, Enclos, Dragodinde, XpTable, Race, Tier...)
- Unit : application (commands, queries, CommandBus)
- Fonctionnel : breeding-workflow, enclos-management, timer-workflow
- Régression : gauge-tier, gauge-recharge, xp-timer, level-target, breeding
- E2E Playwright + Electron : navigation, timer, recharge jauge,
  accouplement, persistance des données

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 05:43:29 +02:00

46 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { CommandBus } from '@application/handlers/CommandBus';
import { QueryBus } from '@application/handlers/QueryBus';
describe('CommandBus', () => {
it('dispatches to registered handler', () => {
const bus = new CommandBus();
const handler = vi.fn();
bus.register('start-timer', handler);
bus.execute({ type: 'start-timer', enclosId: 1 });
expect(handler).toHaveBeenCalledWith({ type: 'start-timer', enclosId: 1 });
});
it('throws on unknown command', () => {
const bus = new CommandBus();
expect(() => bus.execute({ type: 'unknown' })).toThrow('No handler for command: unknown');
});
it('has returns true for registered', () => {
const bus = new CommandBus();
bus.register('test', vi.fn());
expect(bus.has('test')).toBe(true);
expect(bus.has('other')).toBe(false);
});
});
describe('QueryBus', () => {
it('returns value from handler', () => {
const bus = new QueryBus();
bus.register('get-dashboard', () => ({ total: 42 }));
const result = bus.execute<{ total: number }>({ type: 'get-dashboard' });
expect(result.total).toBe(42);
});
it('throws on unknown query', () => {
const bus = new QueryBus();
expect(() => bus.execute({ type: 'unknown' })).toThrow('No handler for query: unknown');
});
it('has returns true for registered', () => {
const bus = new QueryBus();
bus.register('test', () => null);
expect(bus.has('test')).toBe(true);
});
});