import { Decimal } from 'decimal.js'; import { describe, expect, it } from 'vitest'; import { Bloc } from '../../src/domain/bloc.js'; import { Module } from '../../src/domain/module.js'; const makeModule = (id: number, h: number) => new Module({ id, blocId: 1, nom: `M${id}`, heuresPrevues: new Decimal(h) }); describe('Bloc', () => { it('cree un bloc vide', () => { const b = new Bloc({ id: 1, formationId: 100, nom: 'B1', heuresPrevues: new Decimal(120) }); expect(b.modules.length).toBe(0); expect(b.heuresAttribuees().toNumber()).toBe(0); expect(b.heuresRestantes().toNumber()).toBe(120); }); it('throw si heuresPrevues < 0', () => { expect( () => new Bloc({ id: 1, formationId: 100, nom: 'B1', heuresPrevues: new Decimal(-1) }), ).toThrow(); }); it('ajouterModule rollup correct', () => { const b = new Bloc({ id: 1, formationId: 100, nom: 'B1', heuresPrevues: new Decimal(120) }); b.ajouterModule(makeModule(1, 40)); b.ajouterModule(makeModule(2, 60)); expect(b.heuresAttribuees().toNumber()).toBe(100); expect(b.heuresRestantes().toNumber()).toBe(20); }); it('throw si module duplique', () => { const b = new Bloc({ id: 1, formationId: 100, nom: 'B1', heuresPrevues: new Decimal(120) }); b.ajouterModule(makeModule(1, 40)); expect(() => b.ajouterModule(makeModule(1, 10))).toThrow(/deja present/); }); it('throw si capacite bloc depassee', () => { const b = new Bloc({ id: 1, formationId: 100, nom: 'B1', heuresPrevues: new Decimal(50) }); b.ajouterModule(makeModule(1, 30)); expect(() => b.ajouterModule(makeModule(2, 30))).toThrow(/depassee/); }); });