Files
Investidor-V2/tests/frontend/preparation-intent.test.mjs
T
2026-11-15 18:56:39 +02:00

90 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test';
import assert from 'node:assert/strict';
import {
currencyChoices,
matchesChoice,
} from '../../resources/js/lib/catalogue-choice.ts';
import {
createInvestmentHref,
preparationSearch,
} from '../../resources/js/lib/preparation-intent.ts';
test('an own investment carries explicit sector, geography and an interval, without an advert or corridor', () => {
const path = [
{ id: 'province-qa', location_type: 'province' },
{ id: 'district-qa', location_type: 'district' },
{ id: 'locality-qa', location_type: 'locality' },
];
const url = new URL(
createInvestmentHref(
{
sector: 'agro',
min_amount: '1000000',
max_amount: '5000000',
currency: 'MZN',
q: 'Hotel',
corridor_id: 'unrelated',
opportunities: [42],
},
path,
),
'https://qa.example.test',
);
assert.equal(url.pathname, '/investimentos/iniciar');
assert.equal(url.searchParams.get('investment_budget_min'), '1000000');
assert.equal(url.searchParams.get('investment_budget_max'), '5000000');
assert.equal(url.searchParams.get('currency'), 'MZN');
assert.equal(url.searchParams.get('locality_id'), 'locality-qa');
assert.equal(url.searchParams.get('sector'), 'agro');
for (const key of [
'q',
'project_title',
'corridor_id',
'opportunities',
'total_investment',
])
assert.equal(url.searchParams.has(key), false);
const empty = new URL(createInvestmentHref({ q: 'Criar Hotel' }), url);
assert.equal(
empty.search,
'',
'a title does not assign a definitive activity or sector',
);
});
test('optional opportunity searches use only confirmed criteria and do not carry budget or private declarations', () => {
const query = new URLSearchParams(
preparationSearch('hotel', 'sector:7', [
{ id: 'province-qa', location_type: 'province' },
]),
);
assert.deepEqual(
[...query.entries()],
[
['q', 'hotel'],
['sector_id', '7'],
['province_id', 'province-qa'],
],
);
assert.equal(preparationSearch('', '', []), '');
});
test('country and currency search accepts names, three letters, accents, case and short codes', () => {
for (const query of ['MOC', 'moç', 'MZ', 'mocambique'])
assert.equal(matchesChoice(query, ['Moçambique — MZ']), true);
const metical = currencyChoices().find((choice) => choice.value === 'MZN');
assert.ok(metical);
assert.match(metical.label, /metical/i);
for (const query of ['MET', 'met', 'MZN'])
assert.equal(
matchesChoice(query, [metical.label, ...metical.keywords]),
true,
);
assert.deepEqual(
currencyChoices(['MZN', 'USD']).map((choice) => choice.value),
['MZN', 'USD'],
'preserve a consumer’s approved currency constraints',
);
assert.equal(matchesChoice('euro', [metical.label]), false);
});