wip(qa): preserve package one pending functional acceptance
This commit is contained in:
@@ -69,6 +69,9 @@ function editor(initialSnapshot) {
|
||||
}).outputText;
|
||||
compileFunction(code, ['require', 'module', 'exports'])(
|
||||
(name) =>
|
||||
(name === '@/components/integral-financial-plan'
|
||||
? { IntegralFinancialPlan: () => null }
|
||||
: undefined) ??
|
||||
(name === '@/components/business-plan-warnings'
|
||||
? { BusinessPlanWarnings: () => null }
|
||||
: name === '@/components/simulation-annual-example'
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { newReportAssumptions } from '../../../resources/js/lib/integral-financial-report.ts';
|
||||
|
||||
export function financialReportFixture(periods = 24) {
|
||||
const value = {
|
||||
currency: 'MZN',
|
||||
openingCash: '1000',
|
||||
assetInvestment: '600',
|
||||
equity: '600',
|
||||
products: [
|
||||
{
|
||||
label: 'Serviço declarado',
|
||||
monthlyUnits: '10',
|
||||
unitPrice: '100',
|
||||
unitVariableCost: '40',
|
||||
},
|
||||
],
|
||||
depreciationLifeMonths: 60,
|
||||
periods,
|
||||
...Object.fromEntries(
|
||||
[
|
||||
'monthlyCollections',
|
||||
'monthlyVariableCostPayments',
|
||||
'monthlyInventoryPurchases',
|
||||
'monthlyOperatingExpenses',
|
||||
'monthlyOperatingPayments',
|
||||
'monthlyPayrollExpense',
|
||||
'monthlyPayrollPayments',
|
||||
'inventory',
|
||||
'receivables',
|
||||
'payables',
|
||||
'shareholderLoans',
|
||||
'bankLoanProceeds',
|
||||
'grants',
|
||||
'assetDepreciation',
|
||||
'monthlyInterestExpense',
|
||||
'monthlyInterestPayment',
|
||||
'monthlyPrincipalRepayment',
|
||||
].map((key) => [key, '0']),
|
||||
),
|
||||
};
|
||||
Object.assign(value, {
|
||||
monthlyVariableCostPayments: '400',
|
||||
monthlyInventoryPurchases: '400',
|
||||
monthlyOperatingExpenses: '100',
|
||||
monthlyOperatingPayments: '100',
|
||||
monthlyPayrollExpense: '200',
|
||||
monthlyPayrollPayments: '200',
|
||||
assetDepreciation: '600',
|
||||
salesCollectionLagMonths: 0,
|
||||
salesCollectionPercent: '100',
|
||||
openingReceivablesCollectionPercent: '0',
|
||||
});
|
||||
value.reportAssumptions = {
|
||||
...newReportAssumptions(periods),
|
||||
startYear: '2027',
|
||||
openingFixedAssets: '0',
|
||||
openingOtherAssets: '0',
|
||||
openingEquity: '1000',
|
||||
startupExpenses: [{ label: 'Constituição', amount: '100' }],
|
||||
taxExpenseByMonth: Array(periods).fill('30'),
|
||||
taxPaymentByMonth: Array(periods).fill('20'),
|
||||
taxSource: 'Hipótese sintética de teste; não é taxa legal',
|
||||
};
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import { financialReportFixture as plan } from './fixtures/integral-financial-plan.mjs';
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import JSZip from 'jszip';
|
||||
import {
|
||||
buildIntegralFinancialTables,
|
||||
displayReportMoney,
|
||||
} from '../../resources/js/lib/integral-financial-report.ts';
|
||||
import {
|
||||
forecastBusinessPlan,
|
||||
serializeBusinessPlanSnapshot,
|
||||
restoreBusinessPlanSnapshot,
|
||||
} from '../../resources/js/lib/business-financial-plan.ts';
|
||||
import {
|
||||
createProjectDossierReport,
|
||||
createProjectDossierPrintHtml,
|
||||
generateProjectDossierDocx,
|
||||
} from '../../resources/js/lib/project-dossier-report.ts';
|
||||
import {
|
||||
partitionSimulationDraft,
|
||||
restoreSimulationDraft,
|
||||
} from '../../resources/js/lib/simulation-form.ts';
|
||||
|
||||
const get = (tables, id, label) =>
|
||||
tables
|
||||
.find((table) => table.id === id)
|
||||
.rows.find((row) => row[0] === label);
|
||||
|
||||
void test('seven integrated statements reconcile monthly flows, annual totals and closing stocks without changing the existing engine', () => {
|
||||
const input = plan(),
|
||||
before = JSON.stringify(input),
|
||||
forecast = forecastBusinessPlan(input),
|
||||
tables = buildIntegralFinancialTables(input);
|
||||
assert.equal(tables.length, 7);
|
||||
assert.ok(
|
||||
tables.every((table) => table.issues.length === 0),
|
||||
JSON.stringify(tables.map((t) => [t.id, t.issues])),
|
||||
);
|
||||
assert.equal(get(tables, 'startup', 'Despesas de arranque')[1], '100.00');
|
||||
assert.equal(
|
||||
get(tables, 'funding', 'Caixa após financiamento e arranque')[1],
|
||||
'900.00',
|
||||
);
|
||||
assert.deepEqual(get(tables, 'sales', 'Vendas totais').slice(-2), [
|
||||
'12000.00',
|
||||
'12000.00',
|
||||
]);
|
||||
assert.deepEqual(get(tables, 'profit-loss', 'Lucro líquido').slice(-2), [
|
||||
'3120.00',
|
||||
'3120.00',
|
||||
]);
|
||||
assert.deepEqual(get(tables, 'cashflow', 'Caixa inicial').slice(-2), [
|
||||
'900.00',
|
||||
'4260.00',
|
||||
]);
|
||||
assert.deepEqual(get(tables, 'cashflow', 'Caixa final').slice(-2), [
|
||||
'4260.00',
|
||||
'7620.00',
|
||||
]);
|
||||
assert.deepEqual(get(tables, 'balance', 'Total do activo').slice(-2), [
|
||||
'4740.00',
|
||||
'7980.00',
|
||||
]);
|
||||
assert.ok(
|
||||
get(tables, 'balance', 'Diferença do balanço')
|
||||
.slice(1)
|
||||
.every((value) => value === '0.00'),
|
||||
);
|
||||
assert.equal(
|
||||
get(tables, 'break-even', 'Vendas de equilíbrio')[1],
|
||||
'516.67',
|
||||
);
|
||||
assert.equal(JSON.stringify(input), before);
|
||||
const withoutSupplement = { ...input };
|
||||
delete withoutSupplement.reportAssumptions;
|
||||
assert.deepEqual(
|
||||
forecastBusinessPlan(withoutSupplement),
|
||||
forecast,
|
||||
'no changes to approved base forecast',
|
||||
);
|
||||
const draft = {
|
||||
purpose: 'own_investment',
|
||||
business_plan_snapshot: serializeBusinessPlanSnapshot(input),
|
||||
};
|
||||
const stored = JSON.parse(
|
||||
JSON.stringify(partitionSimulationDraft(draft, false)),
|
||||
);
|
||||
const recovered = restoreBusinessPlanSnapshot(
|
||||
restoreSimulationDraft(stored.economic_snapshot, {})
|
||||
.business_plan_snapshot,
|
||||
);
|
||||
assert.deepEqual(buildIntegralFinancialTables(recovered), tables);
|
||||
});
|
||||
|
||||
void test('missing inputs, insufficient inventory and inconsistent opening capital remain explicit, never balancing plugs', () => {
|
||||
const input = plan(12);
|
||||
input.reportAssumptions.openingEquity = '999.99';
|
||||
let tables = buildIntegralFinancialTables(input);
|
||||
assert.match(
|
||||
tables.find((t) => t.id === 'balance').issues.join(' '),
|
||||
/abertura/,
|
||||
);
|
||||
assert.equal(get(tables, 'balance', 'Diferença do balanço')[1], '0.01');
|
||||
input.reportAssumptions.openingEquity = '1000';
|
||||
input.monthlyInventoryPurchases = '';
|
||||
tables = buildIntegralFinancialTables(input);
|
||||
assert.match(
|
||||
tables.find((t) => t.id === 'balance').issues.join(' '),
|
||||
/agenda/,
|
||||
);
|
||||
assert.equal(
|
||||
get(tables, 'balance', 'Diferença do balanço')[1],
|
||||
'Por determinar',
|
||||
);
|
||||
input.monthlyInventoryPurchases = '0';
|
||||
assert.match(
|
||||
buildIntegralFinancialTables(input)
|
||||
.find((t) => t.id === 'balance')
|
||||
.issues.join(' '),
|
||||
/insuficientes/,
|
||||
);
|
||||
input.reportAssumptions.taxExpenseByMonth[0] = '';
|
||||
assert.ok(
|
||||
buildIntegralFinancialTables(input).every((t) => t.issues.length > 0),
|
||||
);
|
||||
});
|
||||
|
||||
void test('partial years, changing product schedules and negative cash keep exact amounts and disclosed assumptions', () => {
|
||||
const input = plan(13);
|
||||
input.products[0].unitPriceByPeriod = Array(13).fill('100.01');
|
||||
input.reportAssumptions.startupExpenses[0].amount = '10000.01';
|
||||
const tables = buildIntegralFinancialTables(input);
|
||||
assert.ok(
|
||||
tables
|
||||
.find((t) => t.id === 'sales')
|
||||
.headers.at(-1)
|
||||
.endsWith('(parcial)'),
|
||||
);
|
||||
assert.equal(get(tables, 'sales', 'Vendas totais').at(-1), '1000.10');
|
||||
assert.equal(get(tables, 'cashflow', 'Caixa inicial')[1], '-9000.01');
|
||||
assert.ok(
|
||||
get(tables, 'balance', 'Diferença do balanço')
|
||||
.slice(1)
|
||||
.every((value) => value === '0.00'),
|
||||
);
|
||||
assert.equal(displayReportMoney('-1234567.89'), '-1 234 567,89');
|
||||
});
|
||||
|
||||
void test('dossier print and Word exports include the same seven statements, escape labels and split wide tables', async () => {
|
||||
const input = plan(13);
|
||||
input.products[0].label = '<script>não executar</script>';
|
||||
const report = createProjectDossierReport(
|
||||
{
|
||||
project_title: 'Teste QA',
|
||||
business_plan_snapshot: serializeBusinessPlanSnapshot(input),
|
||||
},
|
||||
{
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-20T12:00:00Z',
|
||||
},
|
||||
);
|
||||
assert.equal(report.sections[0].tables.length, 7);
|
||||
const html = await createProjectDossierPrintHtml(report, []);
|
||||
assert.match(html, /Balanço Projectado/);
|
||||
assert.match(html, /<script>/);
|
||||
assert.doesNotMatch(html, /<script>não executar/);
|
||||
const output = await generateProjectDossierDocx(report, []);
|
||||
const zip = await JSZip.loadAsync(
|
||||
output instanceof Blob ? await output.arrayBuffer() : output,
|
||||
);
|
||||
const xml = await zip.file('word/document.xml').async('string');
|
||||
assert.match(xml, /Balanço Projectado/);
|
||||
assert.match(xml, /Lucros e Perdas/);
|
||||
assert.match(xml, /7 620,00|7620,00|4 540,00|4540,00/);
|
||||
});
|
||||
Reference in New Issue
Block a user