import test from 'node:test'; import assert from 'node:assert/strict'; import { startupExpenseCategories, startupExpensesTotal, withStartupExpenseCategories, } from '../../resources/js/lib/startup-asset-requirements.ts'; import { productUnitMargin } from '../../resources/js/lib/product-margin.ts'; test('start-up expenses offer the usual categories without touching what the investor wrote, and show a total (tarefa 22)', () => { const rows = withStartupExpenseCategories([ { label: 'Seguros', amount: '12000' }, { label: 'Licença de hotelaria', amount: '35000.50' }, ]); assert.deepEqual(rows.slice(0, 2), [ { label: 'Seguros', amount: '12000' }, { label: 'Licença de hotelaria', amount: '35000.50' }, ]); assert.equal(rows.length, 2 + startupExpenseCategories.length - 1); assert.equal( rows.filter((row) => row.label === 'Seguros').length, 1, 'a category already present is not repeated', ); assert.equal(withStartupExpenseCategories(rows).length, rows.length); assert.equal( startupExpensesTotal(rows), null, 'empty amounts leave the total open', ); const filled = rows.map((row) => row.amount ? row : { ...row, amount: '0' }, ); filled[2].amount = '150000'; assert.equal(startupExpensesTotal(filled), '197000.50'); }); test('each product or service shows its unit margin, and a loss when the cost exceeds the price', () => { assert.deepEqual(productUnitMargin('1500.50', '900'), { amount: '600.50', percent: '40.0', }); assert.deepEqual(productUnitMargin('3500', '1200'), { amount: '2300.00', percent: '65.7', }); assert.deepEqual(productUnitMargin('100', '150'), { amount: '-50.00', percent: '-50.0', }); assert.equal(productUnitMargin('0', '10'), null); assert.equal(productUnitMargin('', '10'), null); assert.equal( productUnitMargin('25.000', '10'), null, 'an unconfirmed legacy value shows no margin', ); });