Files
Investidor-V2/tests/Feature/IvaTravelEventDraftTest.php
T

56 lines
4.1 KiB
PHP

<?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 IvaTravelEventDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_travel_margin_and_special_events_recover_without_changing_accepted_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-travel-events.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:360',$recovered['context_opportunity']);
$this->assertSame('Manica',$recovered['selection_labels']['province_id']);
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
$travel=$store['travelOperations']['opportunity:360'];$events=$store['travelSpecialEvents']['opportunity:360'];
$this->assertCount(10,$travel['rows']);$this->assertCount(5,$travel['periods']);$this->assertCount(12,$events['rows']);
$this->assertSame('0.00',$travel['result']['periods'][0]['baseAmount']);
$this->assertSame('1160.00',$travel['result']['periods'][1]['carryForward']);
$this->assertSame('500.00',$travel['result']['periods'][2]['baseAmount']);
$this->assertSame('1160.00',$travel['result']['rows'][4]['generalGross']);
$this->assertSame('general',$travel['result']['rows'][5]['regime']);
$this->assertSame('outside',$travel['result']['rows'][9]['regime']);
$this->assertSame('2026-12-05',$events['result']['rows'][0]['eventDate']);
$this->assertSame('2026-12-10',$events['result']['rows'][1]['eventDate']);
$this->assertNull($events['result']['rows'][3]['eventDate']);
$this->assertSame('232.00',$events['result']['rows'][4]['dueEvents'][0]['amount']);
$this->assertSame('928.00',$events['result']['rows'][4]['dueEvents'][1]['amount']);
$this->assertSame('2026-12-08',$events['result']['rows'][4]['dueEvents'][1]['date']);
$this->assertSame('deferred',$events['result']['rows'][11]['status']);
foreach($events['result']['rows'] as $row){$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['deduction']);}
$this->assertCount(1,$travel['history']);$this->assertCount(1,$events['history']);
$this->assertSame($travel['rows'],$travel['result']['inputs']);$this->assertSame($events['rows'],$events['result']['inputs']);
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-travel-events-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,['travelOperations'=>true,'travelSpecialEvents'=>true]));
$this->assertSame('regulation_pending',$store['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);
$this->assertNull($store['digitalOperations']['opportunity:359']['result']['rows'][0]['vat']);
$this->assertSame('potential',$store['foreignOperations']['opportunity:358']['result']['rows'][0]['relation19']);
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
file_put_contents(base_path('outputs/iva-l1-travel-events-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
}