feat(iva): prepare P111-P120 listed services as one compatible QA set
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?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 IvaListedServicesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_listed_services_recover_privately_preserving_all_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-g9-nondigital.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:350', $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['listedServices']['opportunity:350'];
|
||||
$this->assertCount(30, $book['rows']);
|
||||
$this->assertCount(10,array_unique(array_column($book['rows'],'treatment')));
|
||||
$this->assertSame(array_merge(...array_fill(0,10,['national','outside','national'])),array_column($book['result']['rows'],'territory'));
|
||||
$this->assertSame(array_merge(...array_fill(0,10,['acquirer','outside','provider'])),array_column($book['result']['rows'],'responsible'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g9-nondigital-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior, array_diff_key($store, ['listedServices' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g9-nondigital-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,33 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import {newListedService,switchListedTreatment,listedServiceConditions,ownListedConditions,listedServiceTreatments,evaluateListedService,recordListedServices,saveListedServiceBook,listedServiceBook,listedServiceCurrent,listedServiceReportRows} from '../../resources/js/lib/iva-listed-services.ts';
|
||||
const frozen=JSON.parse(fs.readFileSync('tests/frontend/fixtures/iva-g9-nondigital-preserved.json','utf8'));
|
||||
const draft={...frozen,context_opportunity:'opportunity:350',project_title:'SYNTHETIC QA — G9 não digital / Manica'};
|
||||
function row(t,route='inbound') {const rule=listedServiceTreatments.find(x=>x.id===t);return {...newListedService(t+'-'+route),treatment:t,description:'SYNTHETIC QA '+rule.branch+' '+route,period:'2026-12',origin:'projected',operationDate:'2026-12-12',operationRef:'SYNTHETIC QA operação',documentRef:'SYNTHETIC QA documento/pressuposto',documentDate:'2026-12-12',scope:'SYNTHETIC QA operação/serviço/dezembro2026',evidence:'SYNTHETIC QA pressupostos expressos',providerPlace:'SYNTHETIC QA estabelecimento prestador',providerCountry:route==='inbound'?'foreign':'MZ',providerRef:'SYNTHETIC QA referência estabelecimento prestador',buyerPlace:'SYNTHETIC QA adquirente EP/domicílio',buyerCountry:route==='outbound'?'foreign':'MZ',buyerRef:'SYNTHETIC QA referência adquirente',recipientType:'a',recipientRef:'SYNTHETIC QA SP2(1)a,inclui actividade exclusivamente isenta sem dedução',providerTaxable:'yes',providerTaxRef:'SYNTHETIC QA SPprestador',subjectRef:'SYNTHETIC QA objecto próprio '+rule.branch,useRef:'SYNTHETIC QA destinatário/utilização e âmbito',targetClause:'a',targetRef:'SYNTHETIC QA relação comdireito6(7)a',conditions:Object.fromEntries([...listedServiceConditions,...ownListedConditions(t)].map(([key])=>[key,'yes']))};}
|
||||
for(const rule of listedServiceTreatments)test(rule.branch+' ownnature,three routes,quality and no deduction prerequisite',()=>{
|
||||
for(const route of ['inbound','outbound','domestic']){
|
||||
const r=row(rule.id,route),result=evaluateListedService(r);assert.equal(result.status,'determined');assert.equal(result.territory,route==='outbound'?'outside':'national');assert.equal(result.responsible,route==='outbound'?'outside':route==='inbound'?'acquirer':'provider');assert.deepEqual(['baseAmount','vat','rate'].map(k=>result[k]),[null,null,null]);
|
||||
for(const [key] of [...listedServiceConditions,...ownListedConditions(rule.id)]){const missing=structuredClone(r);delete missing.conditions[key];assert.equal(evaluateListedService(missing).status,'indeterminate');missing.conditions[key]='no';assert.equal(evaluateListedService(missing).status,'not_applicable');assert.equal(evaluateListedService(missing).territory,null);}
|
||||
for(const field of ['operationRef','documentRef','scope','evidence','subjectRef','useRef','buyerRef','buyerPlace','buyerCountry'])assert.equal(evaluateListedService({...r,[field]:''}).status,'indeterminate',field);
|
||||
assert.equal(evaluateListedService({...r,operationDate:'2026-11-12'}).status,'indeterminate');assert.equal(evaluateListedService({...r,documentDate:'2026-02-30'}).status,'indeterminate');assert.equal(evaluateListedService({...r,period:'2025-12'}).status,'indeterminate');
|
||||
}
|
||||
const r=row(rule.id);for(const field of ['providerCountry','providerPlace','providerRef','recipientType','recipientRef'])assert.equal(evaluateListedService({...r,[field]:''}).status,'indeterminate',field);
|
||||
assert.equal(evaluateListedService({...r,recipientType:'b'}).responsible,'acquirer');assert.equal(evaluateListedService({...r,recipientType:'other'}).status,'not_applicable');
|
||||
assert.equal(evaluateListedService({...r,deductionRight:'no',exemptOnly:'yes'}).territory,'national');assert.match(evaluateListedService(r).obligationReason,/23\(2\)/);assert.match(evaluateListedService(r).obligationReason,/Não se aplica26\(4\)/);
|
||||
const domestic=row(rule.id,'domestic');assert.equal(evaluateListedService({...domestic,recipientType:'',recipientRef:''}).responsible,'provider');assert.equal(evaluateListedService({...domestic,providerTaxable:''}).territory,'national');assert.equal(evaluateListedService({...domestic,providerTaxable:''}).responsible,'indeterminate');
|
||||
const outbound=row(rule.id,'outbound');assert.equal(evaluateListedService({...outbound,providerCountry:'',providerPlace:'',providerRef:'',recipientType:''}).territory,'outside');assert.match(evaluateListedService(outbound).reason,/6\(8\)/);
|
||||
});
|
||||
test('P118/P119 require identified underlying service/right and preserve hidden references',()=>{
|
||||
for(const t of ['intermediation_service','abstention_service']){const r=row(t);for(const targetClause of ['',t==='intermediation_service'?'h':'i','k','aa'])assert.equal(evaluateListedService({...r,targetClause}).status,'indeterminate');assert.equal(evaluateListedService({...r,targetRef:''}).status,'indeterminate');}
|
||||
const r=row('intermediation_service');const next=switchListedTreatment(r,'advertising_service');assert.equal(next.targetRef,r.targetRef);assert.equal(next.recipientRef,r.recipientRef);assert.equal(next.conditions.advertisingNature,undefined);next.conditions.advertisingNature='yes';assert.equal(evaluateListedService({...next,targetClause:'',targetRef:''}).status,'determined');
|
||||
});
|
||||
test('Ten branches persist together with previous books,immutable history and report',()=>{
|
||||
const rows=listedServiceTreatments.flatMap(t=>['inbound','outbound','domestic'].map(route=>row(t.id,route)));
|
||||
let book=recordListedServices(draft,{rows});book=recordListedServices(draft,book);assert.equal(book.history.length,1);assert.notEqual(book.result.inputs,book.rows);
|
||||
const next={...draft,modelo_a_snapshot:saveListedServiceBook(draft,book)};assert.deepEqual(listedServiceBook(next),book);assert.ok(listedServiceCurrent(next,book));assert.equal(listedServiceCurrent({...next,context_opportunity:'other'},book),false);assert.equal(listedServiceCurrent({...next,currency:'USD',customer_nationality:'foreign'},book),true);
|
||||
assert.equal(listedServiceReportRows(next).length,30);for(const t of listedServiceTreatments)assert.ok(listedServiceReportRows(next).some(r=>r[1].includes(t.branch)));assert.ok(listedServiceReportRows(next).some(r=>r[2].includes('responsável: Adquirente')));
|
||||
const store=JSON.parse(next.modelo_a_snapshot);delete store.listedServices;assert.deepEqual(store,JSON.parse(frozen.modelo_a_snapshot));
|
||||
assert.throws(()=>recordListedServices(next,{rows:[rows[0],rows[0]]}));assert.throws(()=>listedServiceBook({...next,modelo_a_snapshot:JSON.stringify({...JSON.parse(next.modelo_a_snapshot),listedServices:[]})}));
|
||||
if(process.env.IVA_G9_FIXTURE)fs.writeFileSync(process.env.IVA_G9_FIXTURE,JSON.stringify(next,null,2)+'\n');
|
||||
});
|
||||
Reference in New Issue
Block a user