const { test, describe } = require('node:test') const assert = require('node:assert/strict') const { BUILDINGS, getBuildingById } = require('../../src/game/buildings') describe('buildings.js', () => { test('expose exactement 2 bâtiments', () => { assert.equal(BUILDINGS.length, 2) }) test('chaque bâtiment a un id unique', () => { const ids = BUILDINGS.map(b => b.id) assert.equal(new Set(ids).size, ids.length) }) test('chaque bâtiment couvre exactement 2 attributs valides', () => { const validAttrs = ['food', 'war', 'health', 'diplo'] for (const b of BUILDINGS) { assert.equal(b.attrs.length, 2, `${b.id} doit couvrir 2 attributs`) b.attrs.forEach(a => assert.ok(validAttrs.includes(a), `${b.id} a un attribut invalide: ${a}`)) } }) test('le coût est défini pour chacun des 2 attributs et est positif', () => { for (const b of BUILDINGS) { b.attrs.forEach(attr => { assert.ok(typeof b.cost[attr] === 'number', `${b.id}.cost.${attr} manquant`) assert.ok(b.cost[attr] > 0, `${b.id}.cost.${attr} doit être positif`) }) } }) test('baseGuaranteed est un nombre positif pour chaque bâtiment', () => { for (const b of BUILDINGS) { assert.ok(typeof b.baseGuaranteed === 'number' && b.baseGuaranteed > 0) } }) test('synergyItems référence un objet existant pour chaque attribut', () => { const { getItemById } = require('../../src/game/items') for (const b of BUILDINGS) { b.attrs.forEach(attr => { const itemId = b.synergyItems?.[attr] assert.ok(itemId, `${b.id}.synergyItems.${attr} manquant`) assert.ok(getItemById(itemId), `${b.id}.synergyItems.${attr} référence un objet inconnu: ${itemId}`) }) } }) test('les 2 bâtiments couvrent ensemble les 4 attributs sans chevauchement', () => { const allAttrs = BUILDINGS.flatMap(b => b.attrs) assert.equal(new Set(allAttrs).size, 4) assert.equal(allAttrs.length, 4) }) describe('getBuildingById', () => { test('retourne le bâtiment correspondant à un id existant', () => { const church = getBuildingById('church') assert.ok(church) assert.equal(church.name, 'Église') assert.deepEqual(church.attrs, ['health', 'diplo']) }) test('retourne null pour un id inconnu', () => { assert.equal(getBuildingById('does-not-exist'), null) }) test('retourne null pour undefined/null', () => { assert.equal(getBuildingById(undefined), null) assert.equal(getBuildingById(null), null) }) }) })