feat(iva): prepare distinct P084 P085 offer drafts without applying benefits
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 IvaOfferPreparationsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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-offer-preparations.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:334', $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['offerPreparations']['opportunity:334'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['P084','P085'], array_column($book['rows'], 'branch'));
|
||||
$this->assertSame(['import','acquisition'], array_column($book['rows'], 'operation'));
|
||||
$this->assertArrayNotHasKey('result', $book);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('Edição posterior', $book['saved']['rows'][0]['purpose']);
|
||||
$this->assertSame('SYNTHETIC QA cheias', $book['rows'][1]['disaster']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g5c-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->assertSame($prior['importExemptions'], $store['importExemptions']);
|
||||
$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-g5d-offer-drafts-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,21 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { newOfferPreparation,offerPreparationBook,saveOfferPreparationBook,recordOfferPreparations,offerReusableData,reuseOfferData,offerPreparationReportRows } from '../../resources/js/lib/iva-offer-preparations.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
const frozen=JSON.parse(fs.readFileSync(new URL('./fixtures/iva-g5c-inputs.json',import.meta.url),'utf8'));
|
||||
const draft=()=>structuredClone(frozen);
|
||||
test('incomplete P084/P085 drafts save without authorizations,zeroVAT or a benefit result;prior26books remain exact',()=>{
|
||||
const d=draft(),before=JSON.parse(d.modelo_a_snapshot),rows=['P084','P085'].map(branch=>newOfferPreparation('gift-'+branch,branch,'MZN'));d.modelo_a_snapshot=saveOfferPreparationBook(d,{rows});const next=JSON.parse(d.modelo_a_snapshot);for(const key of Object.keys(before))assert.deepEqual(next[key],before[key]);assert.deepEqual(offerPreparationBook(JSON.parse(JSON.stringify(d))).rows,rows);assert.equal(rows[1].operation,'acquisition');assert.equal('result' in next.offerPreparations[d.context_opportunity],false);for(const row of offerPreparationReportRows(d))assert.match(row[2],/bénéfice|benefício não aplicado/);assert.equal(next.books['opportunity:329'].result.periods[0].fields['11'],null);
|
||||
});
|
||||
test('explicit reuse fills only empty fields,same opportunity;currency mismatch and P085 import rejected without mutation',()=>{
|
||||
const d=draft(),sources=offerReusableData(d);assert.equal(sources.length,6);const source=sources.find(x=>x.operation==='import'),original=structuredClone(source),row={...newOfferPreparation('gift','P084','MZN'),description:'Edição deliberada',beneficiary:'Instituição QA'};const next=reuseOfferData(row,source);assert.equal(next.description,row.description);assert.equal(next.beneficiary,row.beneficiary);assert.equal(next.documentRef,source.values.documentRef);assert.equal(next.operation,'import');assert.equal(next.reusedFrom.key,source.key);assert.deepEqual(source,original);assert.equal(row.documentRef,'');assert.throws(()=>reuseOfferData(newOfferPreparation('g','P085','MZN'),source),/P085/);assert.throws(()=>reuseOfferData({...row,currency:'USD'},source),/Moeda/);assert.equal(offerReusableData({...d,context_opportunity:'opportunity:does-not-exist'}).length,0);
|
||||
});
|
||||
test('versions preserve deliberate edits and own branch conditions;report from saved/recovered draft does not extend benefit or field11',()=>{
|
||||
const d=draft();let p84=reuseOfferData(newOfferPreparation('gift84','P084','MZN'),offerReusableData(d).find(x=>x.operation==='import'));p84={...p84,beneficiary:'SYNTHETIC QA instituição',nationalInstitution:'yes',publicSocialInstitution:'yes',goodsSuitable:'yes',publicInterestUse:'yes'};const p85={...newOfferPreparation('gift85','P085','MZN'),description:'SYNTHETIC QA bens para cheias',disaster:'SYNTHETIC QA cheias',disasterKind:'Cheias',mitigation:'yes'};let book=recordOfferPreparations({rows:[p84,p85]});book=recordOfferPreparations({...book,rows:[{...p84,purpose:'Edição posterior'},p85]});assert.equal(book.history.length,1);assert.equal(book.history[0].rows[0].purpose,'');d.modelo_a_snapshot=saveOfferPreparationBook(d,book);assert.deepEqual(offerPreparationBook(JSON.parse(JSON.stringify(d))),book);const report=JSON.stringify(createProjectDossierReport(d,{selectedSections:new Set(['finance']),version:'QA drafts'}));for(const token of ['P084','P085','benefício não aplicado','SYNTHETIC QA cheias','Edição posterior','14(2)(a/b)','opportunity:334'])assert.ok(report.includes(token),token);assert.equal(offerPreparationBook({...d,context_opportunity:'opportunity:333'}).rows.length,0);
|
||||
if(process.env.IVA_OFFERS_CALCULATED)fs.writeFileSync(process.env.IVA_OFFERS_CALCULATED,JSON.stringify(d));
|
||||
});
|
||||
test('corrupt draft data cannot be replaced with empty book and P085 never accepts imported operation',()=>{
|
||||
for(const offerPreparations of [[],null,{'opportunity:334':{rows:[{id:'broken'}]}}]){const d=draft(),s=JSON.parse(d.modelo_a_snapshot);s.offerPreparations=offerPreparations;d.modelo_a_snapshot=JSON.stringify(s);assert.throws(()=>saveOfferPreparationBook(d,{rows:[]}));}
|
||||
assert.throws(()=>saveOfferPreparationBook(draft(),{rows:[{...newOfferPreparation('x','P085','MZN'),operation:'import'}]}),/operação/);
|
||||
});
|
||||
Reference in New Issue
Block a user