feat(iva): classify P052 onboard supply imports with statutory exclusions
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaImportSuppliesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_fiscal_snapshot_remains_bounded_after_preserving_larger_histories(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$snapshot = json_encode(['padding' => str_repeat('x', 4000000)], JSON_THROW_ON_ERROR);
|
||||
$this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => ['modelo_a_snapshot' => $snapshot]], ['Idempotency-Key' => (string) Str::uuid()])
|
||||
->assertUnprocessable()->assertJsonValidationErrors('economic_snapshot.modelo_a_snapshot');
|
||||
}
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6e-imports.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:335', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:335'];
|
||||
$this->assertCount(8, $book['rows']);
|
||||
$this->assertSame(['ship_provisions_import','ship_fuel_import','ship_technical_products_import','ship_cargo_accessories_import','aircraft_provisions_import','aircraft_fuel_import','aircraft_technical_products_import','aircraft_cargo_accessories_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(array_fill(0, 8, '0.00'), array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(array_fill(0, 8, 'exempt'), array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6E ship_provisions_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(g)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offers-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertSame($prior['importExemptions'], array_diff_key($store['importExemptions'], ['opportunity:335' => true]));
|
||||
$this->assertSame($prior['offerPreparations'], $store['offerPreparations']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6e-supplies-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { newImportExemption,evaluateImportExemption,recordImportExemptions,saveImportExemptionBook,importExemptionBook,importExemptionCurrent,importExemptionRules,importSupplySource } from '../../resources/js/lib/iva-import-exemptions.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
const frozen=JSON.parse(fs.readFileSync(new URL('./fixtures/iva-offers-inputs.json',import.meta.url),'utf8'));
|
||||
const rules=importExemptionRules.filter(r=>r.branch==='P052');
|
||||
const row=rule=>({...newImportExemption('g6e-'+rule.id,'MZN'),treatment:rule.id,description:'SYNTHETIC QA '+rule.label,period:'2026-12',declaredValue:'5000',importer:'SYNTHETIC QA importador',documentRef:'SYNTHETIC QA G6E '+rule.id,documentDate:'2026-11-14',evidence:'SYNTHETIC QA tipo de abastecimento, embarcação/avião e navegação internacional, percurso e datas normais identificados; pressuposto expresso, não documento real',conditions:Object.fromEntries(rule.conditions.map(([key])=>[key,'yes']))});
|
||||
const draft=()=>({...structuredClone(frozen),context_opportunity:'opportunity:335',project_title:'SYNTHETIC QA — G6E / Abastecimentos importados'});
|
||||
test('P052 eight profiles have own navigation/goods/window/onboard conditions;every failed or missing condition prevents zero',()=>{
|
||||
assert.equal(rules.length,8);assert.match(importSupplySource,/12\(3\)/);
|
||||
for(const rule of rules){const input=row(rule);assert.equal(evaluateImportExemption(input,'MZN').importVat,'0.00');for(const [key] of rule.conditions)for(const value of ['','unknown','no']){const result=evaluateImportExemption({...input,conditions:{...input.conditions,[key]:value}},'MZN');assert.equal(result.status,value==='no'?'not_applicable':'indeterminate');assert.equal(result.importVat,null);}for(const patch of [{period:'2025-12'},{currency:'USD'},{documentRef:''},{documentDate:'2026-02-30'},{evidence:''}])assert.equal(evaluateImportExemption({...input,...patch},'MZN').importVat,null);}
|
||||
});
|
||||
test('12(3) exclusions are applied only to own goods/navigation profile;P053/P054 confirmations cannot substitute',()=>{
|
||||
const ship=rules.find(r=>r.id==='ship_provisions_import'),air=rules.find(r=>r.id==='aircraft_provisions_import');const exclusions=['supplyNoDismantleOtherUse','supplyNoFloatingHospitality','supplyNoRecreation','supplyNoCoastalFishing'];for(const key of exclusions){assert.ok(ship.conditions.some(c=>c[0]===key));assert.ok(!air.conditions.some(c=>c[0]===key));assert.equal(evaluateImportExemption({...row(ship),conditions:{...row(ship).conditions,[key]:'no'}},'MZN').status,'not_applicable');}
|
||||
for(const rule of rules)assert.equal(rule.conditions.some(([key])=>key==='supplyNormalTanks'),rule.id.includes('_fuel_'));
|
||||
const fuel=rules.find(r=>r.id==='ship_fuel_import');assert.equal(evaluateImportExemption({...row(fuel),conditions:{...row(fuel).conditions,supplyNormalTanks:'no'}},'MZN').importVat,null);assert.ok(!fuel.conditions.some(([key])=>exclusions.includes(key)));
|
||||
const input=row(air);delete input.conditions.supplyInternationalAircraft;input.conditions.eligibleAircraft='yes';assert.equal(evaluateImportExemption(input,'MZN').status,'indeterminate');const switched={...row(ship),treatment:'ship_fuel_import'};assert.equal(evaluateImportExemption(switched,'MZN').status,'indeterminate');assert.equal(switched.documentRef,row(ship).documentRef);
|
||||
});
|
||||
test('P052 save/recover/report preserve26fiscalbooks and two offer drafts exactly;archive unknown/failed and keep old keys current',()=>{
|
||||
const d=draft(),prior=JSON.parse(frozen.modelo_a_snapshot);let book=recordImportExemptions(d,{rows:rules.map(rule=>({...row(rule),conditions:{}}))});book=recordImportExemptions(d,{...book,rows:rules.map(rule=>({...row(rule),conditions:{...row(rule).conditions,supplyImportWindow:'no'}}))});book=recordImportExemptions(d,{...book,rows:rules.map(row)});assert.equal(book.history.length,2);assert.ok(book.history.every(h=>h.rows.every(r=>r.importVat===null)));d.modelo_a_snapshot=saveImportExemptionBook(d,book);assert.deepEqual(importExemptionBook(JSON.parse(JSON.stringify(d))),book);assert.ok(importExemptionCurrent(d,book));assert.match(book.result.sourceKey,/import-onboard-supplies\/1/);const next=JSON.parse(d.modelo_a_snapshot);for(const key of ['salesOperations','books','offerPreparations'])assert.deepEqual(next[key],prior[key]);for(const [scope,previous] of Object.entries(prior.importExemptions)){assert.deepEqual(next.importExemptions[scope],previous);assert.ok(importExemptionCurrent({...d,context_opportunity:scope},previous));}assert.equal(next.books['opportunity:329'].result.periods[0].fields['11'],null);
|
||||
const report=JSON.stringify(createProjectDossierReport(d,{selectedSections:new Set(['finance']),version:'QA G6E'}));for(const token of ['P052','opportunity:335','Manica','2026-12','SYNTHETIC QA G6E','0.00','12(1)(g)','campo11',...rules.map(r=>r.id)])assert.ok(report.includes(token),token);if(process.env.IVA_G6E_CALCULATED)fs.writeFileSync(process.env.IVA_G6E_CALCULATED,JSON.stringify(d));
|
||||
});
|
||||
Reference in New Issue
Block a user