fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,36 +1,101 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { searchTerritoryHref, investmentPreparationHref } from '../../resources/js/lib/search-territory.ts';
|
||||
import {
|
||||
searchTerritoryHref,
|
||||
investmentPreparationHref,
|
||||
} from '../../resources/js/lib/search-territory.ts';
|
||||
|
||||
test('preparation carries only the validated portfolio origin and territorial choices, including nested catalogue return context',()=>{
|
||||
const href=investmentPreparationHref(53,'/oportunidades/florestas?province_id=p&district_id=d&q=private-note&context=other','origin');
|
||||
const query=new URL(href,'https://portal.invalid').searchParams;
|
||||
assert.equal(query.get('source'),'opportunity:53');assert.equal(query.get('from_dossier'),'origin');
|
||||
assert.equal(query.get('province_id'),'p');assert.equal(query.get('district_id'),'d');
|
||||
assert.equal(query.has('q'),false);assert.equal(query.has('context'),false);
|
||||
assert.equal(new URL(investmentPreparationHref(53,'/oportunidades/florestas?catalogue_query='+encodeURIComponent('province_id=p&district_id=d')),'https://portal.invalid').searchParams.get('district_id'),'d');
|
||||
void test('preparation carries only the validated portfolio origin and territorial choices, including nested catalogue return context', () => {
|
||||
const href = investmentPreparationHref(
|
||||
53,
|
||||
'/oportunidades/florestas?province_id=p&district_id=d&q=private-note&context=other',
|
||||
'origin',
|
||||
);
|
||||
const query = new URL(href, 'https://portal.invalid').searchParams;
|
||||
assert.equal(query.get('source'), 'opportunity:53');
|
||||
assert.equal(query.get('from_dossier'), 'origin');
|
||||
assert.equal(query.get('province_id'), 'p');
|
||||
assert.equal(query.get('district_id'), 'd');
|
||||
assert.equal(query.has('q'), false);
|
||||
assert.equal(query.has('context'), false);
|
||||
assert.equal(
|
||||
new URL(
|
||||
investmentPreparationHref(
|
||||
53,
|
||||
'/oportunidades/florestas?catalogue_query=' +
|
||||
encodeURIComponent('province_id=p&district_id=d'),
|
||||
),
|
||||
'https://portal.invalid',
|
||||
).searchParams.get('district_id'),
|
||||
'd',
|
||||
);
|
||||
});
|
||||
|
||||
test('portfolio to catalogue to related screen retains only territorial search filters', () => {
|
||||
const start = '/carteira?province_id=inh&district_id=vil&q=airport&kind=project';
|
||||
void test('portfolio to catalogue to related screen retains only territorial search filters', () => {
|
||||
const start =
|
||||
'/carteira?province_id=inh&district_id=vil&q=airport&kind=project';
|
||||
const catalogue = searchTerritoryHref('/oportunidades?view=grid', start);
|
||||
assert.equal(catalogue, '/oportunidades?view=grid&province_id=inh&district_id=vil');
|
||||
assert.equal(
|
||||
catalogue,
|
||||
'/oportunidades?view=grid&province_id=inh&district_id=vil',
|
||||
);
|
||||
const detail = searchTerritoryHref('/carteira/id', catalogue);
|
||||
assert.equal(searchTerritoryHref('/carteira', detail), '/carteira?province_id=inh&district_id=vil');
|
||||
assert.equal(searchTerritoryHref('/zonas?category=zee', start), '/zonas?category=zee&province_id=inh&district_id=vil');
|
||||
assert.equal(
|
||||
searchTerritoryHref('/carteira', detail),
|
||||
'/carteira?province_id=inh&district_id=vil',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref('/zonas?category=zee', start),
|
||||
'/zonas?category=zee&province_id=inh&district_id=vil',
|
||||
);
|
||||
});
|
||||
test('nested historical return query restores territory without importing unrelated filters', () => {
|
||||
assert.equal(searchTerritoryHref('/oportunidades', '/carteira/id?catalogue_query='+encodeURIComponent('province_id=inh&district_id=vil&q=airport')), '/oportunidades?province_id=inh&district_id=vil');
|
||||
void test('nested historical return query restores territory without importing unrelated filters', () => {
|
||||
assert.equal(
|
||||
searchTerritoryHref(
|
||||
'/oportunidades',
|
||||
'/carteira/id?catalogue_query=' +
|
||||
encodeURIComponent('province_id=inh&district_id=vil&q=airport'),
|
||||
),
|
||||
'/oportunidades?province_id=inh&district_id=vil',
|
||||
);
|
||||
});
|
||||
test('explicit parent changes or clearing never import incompatible descendants', () => {
|
||||
const current = '/oportunidades?province_id=inh&district_id=vil&admin_post_id=post&locality_id=loc';
|
||||
assert.equal(searchTerritoryHref('/carteira?province_id=cabo', current), '/carteira?province_id=cabo');
|
||||
assert.equal(searchTerritoryHref('/carteira?district_id=other', current), '/carteira?district_id=other&province_id=inh');
|
||||
assert.equal(searchTerritoryHref('/carteira?province_id=', current), '/carteira?province_id=');
|
||||
void test('explicit parent changes or clearing never import incompatible descendants', () => {
|
||||
const current =
|
||||
'/oportunidades?province_id=inh&district_id=vil&admin_post_id=post&locality_id=loc';
|
||||
assert.equal(
|
||||
searchTerritoryHref('/carteira?province_id=cabo', current),
|
||||
'/carteira?province_id=cabo',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref('/carteira?district_id=other', current),
|
||||
'/carteira?district_id=other&province_id=inh',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref('/carteira?province_id=', current),
|
||||
'/carteira?province_id=',
|
||||
);
|
||||
});
|
||||
test('no cross-tab, project, account, external or unrelated route inheritance', () => {
|
||||
assert.equal(searchTerritoryHref('/oportunidades','/carteira'), '/oportunidades');
|
||||
assert.equal(searchTerritoryHref('/oportunidades','/investimentos/id?province_id=private'), '/oportunidades');
|
||||
assert.equal(searchTerritoryHref('/investimentos/id','/carteira?province_id=inh'), '/investimentos/id');
|
||||
assert.equal(searchTerritoryHref('https://other.test/carteira','/carteira?province_id=inh'), 'https://other.test/carteira');
|
||||
void test('no cross-tab, project, account, external or unrelated route inheritance', () => {
|
||||
assert.equal(
|
||||
searchTerritoryHref('/oportunidades', '/carteira'),
|
||||
'/oportunidades',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref(
|
||||
'/oportunidades',
|
||||
'/investimentos/id?province_id=private',
|
||||
),
|
||||
'/oportunidades',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref('/investimentos/id', '/carteira?province_id=inh'),
|
||||
'/investimentos/id',
|
||||
);
|
||||
assert.equal(
|
||||
searchTerritoryHref(
|
||||
'https://other.test/carteira',
|
||||
'/carteira?province_id=inh',
|
||||
),
|
||||
'https://other.test/carteira',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user