fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -77,7 +77,7 @@ class AiGatewayTest extends TestCase
|
||||
$this->get('/management/ai')->assertRedirect('/login');
|
||||
$this->actingAs(User::factory()->create())->get('/management/ai')->assertForbidden();
|
||||
$this->manager();
|
||||
$this->get('/management/ai')->assertInertia(fn (AssertableInertia $page) => $page->component('ai/index'));
|
||||
$this->get('/management/ai')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->component('ai/index'));
|
||||
$this->postJson('/api/v1/ai/runs', ['capability' => 'assistant', 'purpose' => 'interest_triage', 'query' => 'formação', 'language' => 'pt'])->assertUnprocessable();
|
||||
config(['investmoz_ai.enabled' => false]);
|
||||
$this->get('/management/ai')->assertNotFound();
|
||||
|
||||
@@ -9,10 +9,12 @@ use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BusinessMarketplacePublicTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -57,6 +59,9 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
$key = (string) Str::uuid();
|
||||
$this->get('/negocios/'.$business['public_slug'].'/manifestar-interesse')->assertInertia(fn (Assert $p) => $p
|
||||
->component('investment/business-interest')->has('countries', 249)->where('record.id', $business['id']));
|
||||
$this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => $key])->assertUnauthorized();
|
||||
$this->assertDatabaseCount('interest_requests', 0);
|
||||
$this->actingAs(User::factory()->create());
|
||||
$this->postJson('/api/v1/interest-requests', [...$payload, 'country' => 'ZZ'], ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable();
|
||||
$this->assertDatabaseCount('interest_requests', 0);
|
||||
|
||||
@@ -71,7 +76,7 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
$this->assertDatabaseCount('outbox_events', 1);
|
||||
|
||||
$this->postJson('/api/v1/interest-requests', [...$payload, 'message' => 'Another valid message for this active interest.'])
|
||||
$this->postJson('/api/v1/interest-requests', [...$payload, 'message' => 'Another valid message for this active interest.'], ['Idempotency-Key' => (string) Str::uuid()])
|
||||
->assertStatus(409);
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
$interest = InterestRequest::firstOrFail();
|
||||
@@ -79,7 +84,7 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
$this->assertSame('ZA', $interest->metadata['declared_origin_country_code']);
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->get('/management/interests/'.$interest->id)->assertInertia(fn (Assert $p) => $p
|
||||
$this->actingAsWithMfa($manager)->get('/management/interests/'.$interest->id)->assertInertia(fn (Assert $p) => $p
|
||||
->where('interest.country', 'PT')->where('declaredOrigin.code', 'ZA'));
|
||||
$this->get('/management/interests?country=PT&origin=ZA')->assertInertia(fn (Assert $p) => $p
|
||||
->where('requests.total', 1)->where('originStatistics.interests.0.code', 'ZA')->where('originStatistics.interests.0.count', 1)
|
||||
@@ -123,13 +128,13 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-opportunity')
|
||||
->where('record.modality', 'land_right'));
|
||||
|
||||
$this->postJson('/api/v1/interest-requests', [
|
||||
$this->actingAs(User::factory()->create())->postJson('/api/v1/interest-requests', [
|
||||
'existingBusinessId' => $business['id'], 'modality' => 'real_estate',
|
||||
'fullName' => 'Synthetic investor', 'email' => 'portal-integration-test@gmail.com', 'phone' => '+258 840000000',
|
||||
'investorType' => 'empresa', 'country' => 'MZ', 'sectorInterest' => 'Imobiliário',
|
||||
'message' => 'Synthetic interest in the published real estate opportunity.',
|
||||
'privacyConsent' => true,
|
||||
])->assertCreated();
|
||||
], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->assertDatabaseHas('interest_requests', ['existing_business_id' => $business['id'], 'modality' => 'real_estate', 'status' => 'received']);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,98 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\OpportunityCorridorExplorer;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Support\ProactiveInvestmentFixture;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class CatalogueProvinceCoverageTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private const PROVINCE = 'bfde2651-2b46-5d9c-a500-733fa55a8c5c';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();\Tests\Support\ProactiveInvestmentFixture::guard();$this->withoutVite();
|
||||
parent::setUp();
|
||||
ProactiveInvestmentFixture::guard();
|
||||
$this->withoutVite();
|
||||
}
|
||||
|
||||
public function test_accepted_maputo_source_is_found_in_both_approved_provinces_without_becoming_a_district_site(): void
|
||||
{
|
||||
$c=app(InvestmentCatalogue::class);
|
||||
$expected=Opportunity::published()->where('workflow_context->corridor_agribusiness->source_sha256',CorridorAgribusinessOpportunities::SOURCE_HASH)
|
||||
->where('workflow_context->corridor_agribusiness->corridor','Corredor de Maputo')->pluck('id')->all();
|
||||
$this->assertCount(5,$expected);
|
||||
foreach([self::PROVINCE,'4aa31470-997e-5c63-8fe0-ff2f62586f56']as$province){
|
||||
foreach(['all','context']as$basis){
|
||||
$ids=$c->query(['sector'=>'agronegocio','province_id'=>$province,'territory_basis'=>$basis])->pluck('id')->all();
|
||||
foreach($expected as$id)$this->assertContains($id,$ids);
|
||||
$c = app(InvestmentCatalogue::class);
|
||||
$expected = Opportunity::published()->where('workflow_context->corridor_agribusiness->source_sha256', CorridorAgribusinessOpportunities::SOURCE_HASH)
|
||||
->where('workflow_context->corridor_agribusiness->corridor', 'Corredor de Maputo')->pluck('id')->all();
|
||||
$this->assertCount(5, $expected);
|
||||
foreach ([self::PROVINCE, '4aa31470-997e-5c63-8fe0-ff2f62586f56'] as $province) {
|
||||
foreach (['all', 'context'] as $basis) {
|
||||
$ids = $c->query(['sector' => 'agronegocio', 'province_id' => $province, 'territory_basis' => $basis])->pluck('id')->all();
|
||||
foreach ($expected as $id) {
|
||||
$this->assertContains($id, $ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($expected as$id)$this->assertNotContains($id,$c->query(['province_id'=>self::PROVINCE,'territory_basis'=>'direct'])->pluck('id')->all());
|
||||
$district=app(InvestmentGeography::class)->publicReferences()->where('parent_id',self::PROVINCE)->where('location_type','district')->first();
|
||||
foreach ($expected as $id) {
|
||||
$this->assertNotContains($id, $c->query(['province_id' => self::PROVINCE, 'territory_basis' => 'direct'])->pluck('id')->all());
|
||||
}
|
||||
$district = app(InvestmentGeography::class)->publicReferences()->where('parent_id', self::PROVINCE)->where('location_type', 'district')->first();
|
||||
$this->assertNotNull($district);
|
||||
foreach($expected as$id)$this->assertNotContains($id,$c->query(['province_id'=>self::PROVINCE,'district_id'=>$district->id])->pluck('id')->all());
|
||||
$label=$c->presentLocation(Opportunity::findOrFail($expected[0]))->territorial_summary;
|
||||
$this->assertStringContainsString('contexto provincial do corredor',$label);
|
||||
$this->assertStringContainsString('distrito e posto administrativo não indicados',$label);
|
||||
foreach($expected as$id)$this->assertContains($id,$c->query(['geo_location_id'=>self::PROVINCE])->pluck('id')->all());
|
||||
$this->assertSame([],array_intersect($expected,$c->query(['province_id'=>'059b02ca-7095-577a-8705-4d4c46896747'])->pluck('id')->all()));
|
||||
foreach ($expected as $id) {
|
||||
$this->assertNotContains($id, $c->query(['province_id' => self::PROVINCE, 'district_id' => $district->id])->pluck('id')->all());
|
||||
}
|
||||
$label = $c->presentLocation(Opportunity::findOrFail($expected[0]))->territorial_summary;
|
||||
$this->assertStringContainsString('contexto provincial do corredor', $label);
|
||||
$this->assertStringContainsString('distrito e posto administrativo não indicados', $label);
|
||||
foreach ($expected as $id) {
|
||||
$this->assertContains($id, $c->query(['geo_location_id' => self::PROVINCE])->pluck('id')->all());
|
||||
}
|
||||
$this->assertSame([], array_intersect($expected, $c->query(['province_id' => '059b02ca-7095-577a-8705-4d4c46896747'])->pluck('id')->all()));
|
||||
}
|
||||
|
||||
public function test_province_includes_its_descendants_with_full_location_and_excludes_private_and_other_provinces(): void
|
||||
{
|
||||
$geo=app(InvestmentGeography::class);$c=app(InvestmentCatalogue::class);
|
||||
$district=$geo->publicReferences()->where('parent_id',self::PROVINCE)->where('location_type','district')->first();
|
||||
$post=$geo->publicReferences()->where('parent_id',$district->id)->where('location_type','admin_post')->first();
|
||||
$geo = app(InvestmentGeography::class);
|
||||
$c = app(InvestmentCatalogue::class);
|
||||
$district = $geo->publicReferences()->where('parent_id', self::PROVINCE)->where('location_type', 'district')->first();
|
||||
$post = $geo->publicReferences()->where('parent_id', $district->id)->where('location_type', 'admin_post')->first();
|
||||
$this->assertNotNull($post);
|
||||
$make=fn($territory,$status='published')=>Opportunity::create(['sector_id'=>1,'reference'=>'SYNTHETIC-QA-'.Str::uuid(),'slug'=>'synthetic-'.Str::uuid(),'title'=>'SYNTHETIC QA province coverage','status'=>$status,'published_at'=>now()->subMinute(),'primary_territory_id'=>$territory,'geography_scope'=>'specific']);
|
||||
$record=$make($post->id);$private=$make($post->id,'draft');$other=$make('059b02ca-7095-577a-8705-4d4c46896747');
|
||||
$ids=$c->query(['province_id'=>self::PROVINCE,'sector'=>'agronegocio'])->pluck('id')->all();
|
||||
$this->assertContains($record->id,$ids);$this->assertNotContains($private->id,$ids);$this->assertNotContains($other->id,$ids);
|
||||
$label=$c->presentLocation($record)->territorial_summary;
|
||||
foreach(['Maputo Província',$district->name,$post->name]as$name)$this->assertStringContainsString($name,$label);
|
||||
$make = fn ($territory, $status = 'published') => Opportunity::create(['sector_id' => 1, 'reference' => 'SYNTHETIC-QA-'.Str::uuid(), 'slug' => 'synthetic-'.Str::uuid(), 'title' => 'SYNTHETIC QA province coverage', 'status' => $status, 'published_at' => now()->subMinute(), 'primary_territory_id' => $territory, 'geography_scope' => 'specific']);
|
||||
$record = $make($post->id);
|
||||
$private = $make($post->id, 'draft');
|
||||
$other = $make('059b02ca-7095-577a-8705-4d4c46896747');
|
||||
$ids = $c->query(['province_id' => self::PROVINCE, 'sector' => 'agronegocio'])->pluck('id')->all();
|
||||
$this->assertContains($record->id, $ids);
|
||||
$this->assertNotContains($private->id, $ids);
|
||||
$this->assertNotContains($other->id, $ids);
|
||||
$label = $c->presentLocation($record)->territorial_summary;
|
||||
foreach (['Maputo Província', $district->name, $post->name] as $name) {
|
||||
$this->assertStringContainsString($name, $label);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_actual_territory_and_publication_decisions_override_old_corridor_context(): void
|
||||
{
|
||||
$c=app(InvestmentCatalogue::class);
|
||||
$record=Opportunity::published()->where('workflow_context->corridor_agribusiness->corridor','Corredor de Maputo')->firstOrFail();
|
||||
$record->primary_territory_id='059b02ca-7095-577a-8705-4d4c46896747';$record->save();
|
||||
$this->assertNotContains($record->id,$c->query(['province_id'=>self::PROVINCE])->pluck('id')->all());
|
||||
$record->primary_territory_id=null;$record->status='draft';$record->save();
|
||||
$this->assertNotContains($record->id,$c->query(['province_id'=>self::PROVINCE])->pluck('id')->all());
|
||||
$c = app(InvestmentCatalogue::class);
|
||||
$record = Opportunity::published()->where('workflow_context->corridor_agribusiness->corridor', 'Corredor de Maputo')->firstOrFail();
|
||||
$record->primary_territory_id = '059b02ca-7095-577a-8705-4d4c46896747';
|
||||
$record->save();
|
||||
$this->assertNotContains($record->id, $c->query(['province_id' => self::PROVINCE])->pluck('id')->all());
|
||||
$record->primary_territory_id = null;
|
||||
$record->status = 'draft';
|
||||
$record->save();
|
||||
$this->assertNotContains($record->id, $c->query(['province_id' => self::PROVINCE])->pluck('id')->all());
|
||||
}
|
||||
|
||||
public function test_public_search_and_corridor_view_agree_without_inventing_map_coordinates(): void
|
||||
{
|
||||
$filters=['province_id'=>self::PROVINCE,'sector'=>'agronegocio'];
|
||||
$response=$this->getJson('/api/v1/investment/search?'.http_build_query($filters))->assertOk()->assertJsonPath('total',5);
|
||||
foreach($response->json('data')as$row)$this->assertStringContainsString('contexto provincial do corredor',$row['territorial_summary']);
|
||||
$groups=app(\App\Services\OpportunityCorridorExplorer::class)->groups($filters);
|
||||
$this->assertCount(1,$groups);$this->assertSame(5,$groups[0]['count']);
|
||||
foreach($groups[0]['opportunities']as$row){$this->assertContains('Maputo Província',$row['provinces']);$this->assertNull($row['district']);}
|
||||
$map=app(InvestmentCatalogue::class)->map($filters);
|
||||
$this->assertCount(5,$map['unlocated']);$this->assertSame([],$map['features']);
|
||||
$filters = ['province_id' => self::PROVINCE, 'sector' => 'agronegocio'];
|
||||
$response = $this->getJson('/api/v1/investment/search?'.http_build_query($filters))->assertOk()->assertJsonPath('total', 5);
|
||||
foreach ($response->json('data') as $row) {
|
||||
$this->assertStringContainsString('contexto provincial do corredor', $row['territorial_summary']);
|
||||
}
|
||||
$groups = app(OpportunityCorridorExplorer::class)->groups($filters);
|
||||
$this->assertCount(1, $groups);
|
||||
$this->assertSame(5, $groups[0]['count']);
|
||||
foreach ($groups[0]['opportunities'] as $row) {
|
||||
$this->assertContains('Maputo Província', $row['provinces']);
|
||||
$this->assertNull($row['district']);
|
||||
}
|
||||
$map = app(InvestmentCatalogue::class)->map($filters);
|
||||
$this->assertCount(5, $map['unlocated']);
|
||||
$this->assertSame([], $map['features']);
|
||||
}
|
||||
|
||||
public function test_all_approved_corridors_are_found_in_their_provinces_and_not_in_unrelated_provinces(): void
|
||||
{
|
||||
$catalogue=app(InvestmentCatalogue::class);
|
||||
$provinces=app(InvestmentGeography::class)->publicReferences()->where('location_type','province')->get();
|
||||
$this->assertCount(11,$provinces);
|
||||
foreach(config('investment_corridors')as$entry){
|
||||
$records=Opportunity::published()->whereNull('primary_territory_id')
|
||||
->where('workflow_context->corridor_agribusiness->source_sha256',CorridorAgribusinessOpportunities::SOURCE_HASH)
|
||||
->where('workflow_context->corridor_agribusiness->corridor',$entry['name'])->pluck('id')->all();
|
||||
$this->assertNotEmpty($records,$entry['name']);
|
||||
foreach($provinces as$province){
|
||||
$ids=$catalogue->query(['province_id'=>$province->id,'sector'=>'agronegocio'])->pluck('id')->all();
|
||||
foreach($records as$id){
|
||||
if(in_array($province->source_code,$entry['provinces'],true))$this->assertContains($id,$ids);
|
||||
else $this->assertNotContains($id,$ids);
|
||||
$catalogue = app(InvestmentCatalogue::class);
|
||||
$provinces = app(InvestmentGeography::class)->publicReferences()->where('location_type', 'province')->get();
|
||||
$this->assertCount(11, $provinces);
|
||||
foreach (config('investment_corridors') as $entry) {
|
||||
$records = Opportunity::published()->whereNull('primary_territory_id')
|
||||
->where('workflow_context->corridor_agribusiness->source_sha256', CorridorAgribusinessOpportunities::SOURCE_HASH)
|
||||
->where('workflow_context->corridor_agribusiness->corridor', $entry['name'])->pluck('id')->all();
|
||||
$this->assertNotEmpty($records, $entry['name']);
|
||||
foreach ($provinces as $province) {
|
||||
$ids = $catalogue->query(['province_id' => $province->id, 'sector' => 'agronegocio'])->pluck('id')->all();
|
||||
foreach ($records as $id) {
|
||||
if (in_array($province->source_code, $entry['provinces'], true)) {
|
||||
$this->assertContains($id, $ids);
|
||||
} else {
|
||||
$this->assertNotContains($id, $ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,26 +135,30 @@ final class CatalogueProvinceCoverageTest extends TestCase
|
||||
|
||||
public function test_descendant_coverage_is_national_and_shared_by_sectors_and_location_entry_points(): void
|
||||
{
|
||||
$geo=app(InvestmentGeography::class);$catalogue=app(InvestmentCatalogue::class);
|
||||
$provinces=$geo->publicReferences()->where('location_type','province')->get();
|
||||
$sectors=DB::table('sectors')->where('is_active',true)->whereNotNull('published_at')->whereNull('deleted_at')->orderBy('id')->limit(2)->get();
|
||||
$this->assertCount(2,$sectors);
|
||||
foreach($provinces as$province){
|
||||
$district=$geo->publicReferences()->where('parent_id',$province->id)->where('location_type','district')->first();
|
||||
$this->assertNotNull($district,$province->name);
|
||||
$post=$geo->publicReferences()->where('parent_id',$district->id)->where('location_type','admin_post')->first();
|
||||
$leaf=$post?:$district;
|
||||
foreach($sectors as$sector){
|
||||
$record=Opportunity::create(['sector_id'=>$sector->id,'reference'=>'SYNTHETIC-QA-'.Str::uuid(),'slug'=>'synthetic-'.Str::uuid(),
|
||||
'title'=>'SYNTHETIC QA national coverage','status'=>'published','published_at'=>now()->subMinute(),'primary_territory_id'=>$leaf->id,'geography_scope'=>'specific']);
|
||||
foreach([['province_id'=>$province->id],['geo_location_id'=>$province->id],['province_id'=>$province->id,'district_id'=>$district->id]]as$entry){
|
||||
$this->assertContains($record->id,$catalogue->query([...$entry,'sector'=>$sector->slug])->pluck('id')->all());
|
||||
$geo = app(InvestmentGeography::class);
|
||||
$catalogue = app(InvestmentCatalogue::class);
|
||||
$provinces = $geo->publicReferences()->where('location_type', 'province')->get();
|
||||
$sectors = DB::table('sectors')->where('is_active', true)->whereNotNull('published_at')->whereNull('deleted_at')->orderBy('id')->limit(2)->get();
|
||||
$this->assertCount(2, $sectors);
|
||||
foreach ($provinces as $province) {
|
||||
$district = $geo->publicReferences()->where('parent_id', $province->id)->where('location_type', 'district')->first();
|
||||
$this->assertNotNull($district, $province->name);
|
||||
$post = $geo->publicReferences()->where('parent_id', $district->id)->where('location_type', 'admin_post')->first();
|
||||
$leaf = $post ?: $district;
|
||||
foreach ($sectors as $sector) {
|
||||
$record = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'SYNTHETIC-QA-'.Str::uuid(), 'slug' => 'synthetic-'.Str::uuid(),
|
||||
'title' => 'SYNTHETIC QA national coverage', 'status' => 'published', 'published_at' => now()->subMinute(), 'primary_territory_id' => $leaf->id, 'geography_scope' => 'specific']);
|
||||
foreach ([['province_id' => $province->id], ['geo_location_id' => $province->id], ['province_id' => $province->id, 'district_id' => $district->id]] as $entry) {
|
||||
$this->assertContains($record->id, $catalogue->query([...$entry, 'sector' => $sector->slug])->pluck('id')->all());
|
||||
}
|
||||
$other = $sectors->firstWhere('id', '!=', $sector->id);
|
||||
$this->assertNotContains($record->id, $catalogue->query(['province_id' => $province->id, 'sector' => $other->slug])->pluck('id')->all());
|
||||
$label = $catalogue->presentLocation($record)->territorial_summary;
|
||||
$this->assertStringContainsString($province->name, $label);
|
||||
$this->assertStringContainsString($district->name, $label);
|
||||
if ($post) {
|
||||
$this->assertStringContainsString($post->name, $label);
|
||||
}
|
||||
$other=$sectors->firstWhere('id','!=',$sector->id);
|
||||
$this->assertNotContains($record->id,$catalogue->query(['province_id'=>$province->id,'sector'=>$other->slug])->pluck('id')->all());
|
||||
$label=$catalogue->presentLocation($record)->territorial_summary;
|
||||
$this->assertStringContainsString($province->name,$label);$this->assertStringContainsString($district->name,$label);
|
||||
if($post)$this->assertStringContainsString($post->name,$label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentZones;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -76,7 +77,7 @@ class CatalogueSelectorReferencesTest extends TestCase
|
||||
$corridor = (string) Str::uuid();
|
||||
DB::table('development_corridors')->insert(['id' => $corridor, 'code' => 'SINT-'.Str::random(12), 'name' => 'SINTÉTICO QA corredor',
|
||||
'status' => 'active', 'data_classification' => 'public', 'primary_territory_id' => $province]);
|
||||
$project = \App\Models\Project::factory()->create(['data_classification' => 'public', 'primary_territory_id' => $province]);
|
||||
$project = Project::factory()->create(['data_classification' => 'public', 'primary_territory_id' => $province]);
|
||||
$chain = (string) Str::uuid();
|
||||
DB::table('value_chains')->insert(['id' => $chain, 'cluster_id' => $clusters['public'], 'code' => 'SINT-'.Str::random(12),
|
||||
'name' => 'SINTÉTICO QA cadeia', 'stage' => 'production', 'data_classification' => 'public']);
|
||||
|
||||
@@ -4,21 +4,23 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\ContentManagement;
|
||||
use App\Services\PortalProfileAdministration;
|
||||
use App\Services\OpportunityManagement;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\DocumentManagementAccess;
|
||||
use App\Services\Malware\MalwareScanner;
|
||||
use App\Services\OpportunityManagement;
|
||||
use App\Services\PortalProfileAdministration;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ContentManagementEntryTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -119,6 +121,6 @@ class ContentManagementEntryTest extends TestCase
|
||||
$this->get('/management/portal-services')->assertForbidden();
|
||||
config(['homologation_editorial.accounts' => [$actor->email]]);
|
||||
$this->withSession(['portal.mfa_at' => time() - 901]);
|
||||
$this->assertFalse(app(\App\Services\DocumentManagementAccess::class)->editorial($actor));
|
||||
$this->assertFalse(app(DocumentManagementAccess::class)->editorial($actor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ final class CorridorAgribusinessBatchTest extends TestCase
|
||||
$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);
|
||||
$this->withoutVite(); config(['portal.profile_access_enabled' => true]);
|
||||
$this->withoutVite();
|
||||
config(['portal.profile_access_enabled' => true]);
|
||||
$entries = app(CorridorAgribusinessOpportunities::class)->entries();
|
||||
$keys = array_column($entries, 'key');
|
||||
$others = Opportunity::withTrashed()->whereNotIn('management_creation_key', $keys)->orWhereNull('management_creation_key')->orderBy('id')->get()->map(fn ($r) => $r->getRawOriginal())->all();
|
||||
@@ -35,7 +36,8 @@ final class CorridorAgribusinessBatchTest extends TestCase
|
||||
$this->assertCount(34, $previews);
|
||||
$input = ['confirm' => true, 'reason' => 'QA: divulgação das fichas expressamente seleccionadas no lote de Agronegócio.',
|
||||
'previews' => array_map(fn ($p) => ['id' => $p['id'], 'token' => $p['token'], 'operation_key' => (string) Str::uuid()], $previews)];
|
||||
$bad = $input; array_pop($bad['previews']);
|
||||
$bad = $input;
|
||||
array_pop($bad['previews']);
|
||||
$this->postJson($base.'/divulgar', $bad)->assertUnprocessable();
|
||||
$this->postJson($base.'/divulgar', $input)->assertOk();
|
||||
$this->postJson($base.'/divulgar', $input)->assertOk();
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestorContext;
|
||||
use App\Services\OpportunityManagement;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -51,7 +52,7 @@ final class CorridorAgribusinessInvestorPathTest extends TestCase
|
||||
$interestId = $this->postJson('/investidor/manifestacoes', ['opportunity_id' => $record->id])->assertCreated()->json('id');
|
||||
$this->getJson('/investidor/manifestacoes/'.$interestId)->assertOk();
|
||||
$this->assertSame(1, DB::table('desk_cases')->where('id', $id)->count());
|
||||
$this->assertSame('opportunity:'.$record->id, app(\App\Services\InvestorContext::class)->view($investor, $id)['context']['selection']['opportunity']['key']);
|
||||
$this->assertSame('opportunity:'.$record->id, app(InvestorContext::class)->view($investor, $id)['context']['selection']['opportunity']['key']);
|
||||
// All synthetic investor/path/disclosure writes roll back with this test.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ namespace Tests\Feature;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestorContext;
|
||||
use App\Services\OpportunityManagement;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
@@ -22,6 +24,8 @@ final class CorridorAgribusinessOpportunitiesTest extends TestCase
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
$this->withoutVite();
|
||||
// Establish the private baseline only inside this rolled-back QA transaction.
|
||||
Opportunity::whereIn('management_creation_key', array_column(app(CorridorAgribusinessOpportunities::class)->entries(), 'key'))->update(['status' => 'draft', 'published_at' => null]);
|
||||
config(['portal.profile_access_enabled' => true, 'portal.opportunity_specialized_drafts_enabled' => true, 'investor-path.enabled' => true]);
|
||||
$actor = User::findOrFail(295); // Existing designated QA operator; no new role or account.
|
||||
$this->actingAs($actor)->withSession(['portal.mfa_actor' => $actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $actor->portal_access_revision]);
|
||||
@@ -52,7 +56,7 @@ final class CorridorAgribusinessOpportunitiesTest extends TestCase
|
||||
$this->getJson('/api/v1/opportunities/'.$record->slug)->assertOk()->assertJsonPath('data.maturity_label', 'Em preparação');
|
||||
$this->get('/oportunidades/'.$record->slug)->assertOk();
|
||||
$this->get('/investimentos/iniciar?source=opportunity:'.$record->id)->assertOk();
|
||||
$this->assertSame($record->id, (int) app(\App\Services\InvestorContext::class)->reference('opportunity:'.$record->id)['id']);
|
||||
$this->assertSame($record->id, (int) app(InvestorContext::class)->reference('opportunity:'.$record->id)['id']);
|
||||
}
|
||||
$links = $service->articleLinks();
|
||||
$this->assertSame([5, 6, 6, 7, 5, 5], array_map('count', $links));
|
||||
@@ -73,7 +77,9 @@ final class CorridorAgribusinessOpportunitiesTest extends TestCase
|
||||
$input = $record->fresh()->workflow_context['promotional_summary']['input'];
|
||||
foreach (['disclose', 'disclose', 'withdraw'] as $index => $action) {
|
||||
$record->refresh();
|
||||
if ($index === 1) $input['summary'] .= ' Actualização pública QA.';
|
||||
if ($index === 1) {
|
||||
$input['summary'] .= ' Actualização pública QA.';
|
||||
}
|
||||
$preview = $this->postJson($base.'/divulgacao/previa', [...$input, 'action' => $action, 'etag' => app(OpportunityManagement::class)->etag($record)])->assertOk()->json();
|
||||
$this->postJson($base.'/divulgacao/confirmar', ['token' => $preview['token'], 'operation_key' => (string) Str::uuid(), 'confirm' => true,
|
||||
'reason' => 'QA: conferir actualização ou retirada sem perder a preparação.'])->assertOk();
|
||||
@@ -81,7 +87,7 @@ final class CorridorAgribusinessOpportunitiesTest extends TestCase
|
||||
$this->getJson('/api/v1/opportunities/'.$record->slug)->assertNotFound();
|
||||
$this->assertSame([], app(CorridorAgribusinessOpportunities::class)->articleLinks());
|
||||
$this->assertSame($canonical['executive_summary'], app(OpportunityManagement::class)->values($record->fresh())['canonical']['executive_summary']);
|
||||
$request = \Illuminate\Http\Request::create('/minhas-oportunidades/drafts', 'POST');
|
||||
$request = Request::create('/minhas-oportunidades/drafts', 'POST');
|
||||
app()->instance('request', $request);
|
||||
$repeat = app(CorridorAgribusinessOpportunities::class)->register(User::findOrFail(295), $record->organization_id);
|
||||
$this->assertCount(34, $repeat);
|
||||
|
||||
@@ -11,17 +11,19 @@ use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CrmIntakeTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
private function setupManager(): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAs($user);
|
||||
$this->actingAsWithMfa($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class DashboardTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$sector = Sector::create(['name' => 'Energia', 'slug' => 'energia', 'is_active' => true]);
|
||||
$sector = Sector::create(['name' => 'Energia', 'slug' => 'energia-especifica', 'is_active' => true, 'published_at' => now()]);
|
||||
foreach (['published', 'draft', 'archived'] as $status) {
|
||||
Opportunity::create(['sector_id' => $sector->id, 'reference' => $status, 'slug' => $status,
|
||||
'title' => $status, 'status' => $status, 'published_at' => now()->subMinute()]);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Sector;
|
||||
use App\Services\LegacyContent;
|
||||
use App\Services\SectorInvestment;
|
||||
use App\Models\Sector;
|
||||
use App\Support\IsolatedQaDatabase;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -20,7 +20,10 @@ class EducationalGuidesTest extends TestCase
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = parent::createApplication();
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges()) throw new \LogicException('Isolated QA required');
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges()) {
|
||||
throw new \LogicException('Isolated QA required');
|
||||
}
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExistingBusinessIntakeTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
private string $base = '/api/v1/existing-business/listings';
|
||||
@@ -56,20 +58,20 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$id = $this->postJson($this->base, $this->draft())->assertCreated()->json('id');
|
||||
$url = $this->base.'/'.$id;
|
||||
$this->getJson($url)->assertOk()->assertHeader('Cache-Control', 'no-store, private');
|
||||
$this->actingAs($reviewer)->getJson($url)->assertForbidden();
|
||||
$this->actingAsWithMfa($reviewer)->getJson($url)->assertForbidden();
|
||||
$this->actingAs($owner)->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic review requested'])->assertUnprocessable();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic review requested', 'review_consent' => true])->assertOk()->assertJsonPath('version_no', 2);
|
||||
$this->putJson($url, [...$this->draft(), 'version_no' => 2])->assertForbidden();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Attempted self review'])->assertForbidden();
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk()->assertJsonPath('version_no', 3);
|
||||
$this->actingAs($reviewer)->getJson('/api/v1/existing-business/reviews')->assertOk()->assertJsonPath('records.total', 1);
|
||||
$this->actingAsWithMfa($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk()->assertJsonPath('version_no', 3);
|
||||
$this->actingAsWithMfa($reviewer)->getJson('/api/v1/existing-business/reviews')->assertOk()->assertJsonPath('records.total', 1);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertConflict();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk()->assertJsonPath('version_no', 4);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'needs_information', 'note' => 'Please clarify synthetic source'])->assertOk();
|
||||
$this->actingAs($owner)->getJson($url)->assertOk()->assertJsonPath('history.0.note', 'Please clarify synthetic source');
|
||||
$this->postJson($url, [...$this->draft(), '_method' => 'PUT', 'version_no' => 5])->assertOk()->assertJsonPath('version_no', 6);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 6, 'action' => 'withdrawn', 'note' => 'Synthetic withdrawal requested'])->assertOk();
|
||||
$this->actingAs($reviewer)->getJson($url)->assertForbidden();
|
||||
$this->actingAsWithMfa($reviewer)->getJson($url)->assertForbidden();
|
||||
$this->getJson('/api/v1/existing-business/reviews')->assertJsonPath('records.total', 0);
|
||||
$this->assertDatabaseCount('existing_business_reviews', 5);
|
||||
$this->assertDatabaseCount('existing_business_revisions', 7);
|
||||
@@ -94,8 +96,8 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$this->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic review requested', 'review_consent' => true])->assertOk();
|
||||
$this->postJson($url.'/verifications', $finding)->assertForbidden();
|
||||
$triager = $this->designated('triagers');
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk();
|
||||
$this->actingAs($reviewer)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk();
|
||||
$this->actingAsWithMfa($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk();
|
||||
$this->actingAsWithMfa($reviewer)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk();
|
||||
$this->postJson($url.'/verifications', [...$finding, 'version_no' => 3])->assertConflict();
|
||||
$finding['version_no'] = 4;
|
||||
$this->postJson($url.'/verifications', [...$finding, 'valid_until' => null])->assertUnprocessable();
|
||||
@@ -118,7 +120,7 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
{
|
||||
$this->getJson($this->base)->assertUnauthorized();
|
||||
$reviewer = $this->reviewer();
|
||||
$this->actingAs($reviewer)->getJson('/api/v1/existing-business/reviews')->assertOk();
|
||||
$this->actingAsWithMfa($reviewer)->getJson('/api/v1/existing-business/reviews')->assertOk();
|
||||
config(['existing-business.reviewers' => []]);
|
||||
$this->getJson('/api/v1/existing-business/reviews')->assertForbidden();
|
||||
config(['existing-business.reviewers' => [$reviewer->email]]);
|
||||
@@ -159,15 +161,15 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'submitted', 'note' => 'Synthetic submission for staged approval', 'review_consent' => true])->assertOk();
|
||||
$this->assertDatabaseHas('tasks', ['existing_business_id' => $id, 'task_type' => 'triage', 'status' => 'open']);
|
||||
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'triage', 'note' => 'Synthetic initial triage completed'])->assertOk();
|
||||
$this->actingAs($reviewer)->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'in_review', 'note' => 'Synthetic independent review started'])->assertOk();
|
||||
$this->actingAsWithMfa($triager)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'triage', 'note' => 'Synthetic initial triage completed'])->assertOk();
|
||||
$this->actingAsWithMfa($reviewer)->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'in_review', 'note' => 'Synthetic independent review started'])->assertOk();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 5, 'action' => 'approval_l1', 'note' => 'Synthetic review checks completed'])->assertOk();
|
||||
$this->actingAs($levelOne)->postJson($url.'/transitions', ['version_no' => 6, 'action' => 'approval_l2', 'note' => 'Synthetic first level approval'])->assertOk();
|
||||
$this->actingAsWithMfa($levelOne)->postJson($url.'/transitions', ['version_no' => 6, 'action' => 'approval_l2', 'note' => 'Synthetic first level approval'])->assertOk();
|
||||
|
||||
config(['existing-business.approvers_l2' => [...config('existing-business.approvers_l2'), strtolower($levelOne->email)]]);
|
||||
$this->actingAs($levelOne)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic second level approval attempt'])->assertForbidden();
|
||||
$this->actingAs($levelTwo)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic independent second level approval'])->assertOk();
|
||||
$this->actingAs($publisher)->postJson($url.'/transitions', ['version_no' => 8, 'action' => 'published', 'note' => 'Synthetic independent publication decision'])->assertOk()->assertJsonPath('published_at', fn ($value) => is_string($value));
|
||||
$this->actingAsWithMfa($levelOne)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic second level approval attempt'])->assertForbidden();
|
||||
$this->actingAsWithMfa($levelTwo)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic independent second level approval'])->assertOk();
|
||||
$this->actingAsWithMfa($publisher)->postJson($url.'/transitions', ['version_no' => 8, 'action' => 'published', 'note' => 'Synthetic independent publication decision'])->assertOk()->assertJsonPath('published_at', fn ($value) => is_string($value));
|
||||
|
||||
$this->assertDatabaseHas('business_workflow_transitions', ['existing_business_id' => $id, 'from_status' => 'approval_l2', 'to_status' => 'approved']);
|
||||
$this->assertDatabaseHas('existing_businesses', ['id' => $id, 'status' => 'published']);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\Support\ProactiveInvestmentFixture;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class FiscalFormEntryTest extends TestCase
|
||||
@@ -13,7 +14,7 @@ final class FiscalFormEntryTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
\Tests\Support\ProactiveInvestmentFixture::guard();
|
||||
ProactiveInvestmentFixture::guard();
|
||||
$this->withoutVite();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\InterestRequest;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -14,6 +15,12 @@ class InterestSubmissionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->actingAs(User::factory()->create());
|
||||
}
|
||||
|
||||
private function payload(): array
|
||||
{
|
||||
return ['fullName' => 'Pessoa de teste', 'email' => 'portal-integration-test@gmail.com',
|
||||
@@ -29,6 +36,7 @@ class InterestSubmissionTest extends TestCase
|
||||
InterestRequest::firstOrFail()->update(['status' => 'closed']);
|
||||
$second = $this->postJson('/api/v1/interest-requests', $this->payload(), $headers)->assertCreated();
|
||||
$this->assertSame($first->json(), $second->json());
|
||||
$this->assertSame('closed', InterestRequest::firstOrFail()->status);
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
$this->assertDatabaseCount('interest_submission_receipts', 1);
|
||||
$this->assertDatabaseCount('outbox_events', 1);
|
||||
@@ -56,7 +64,7 @@ class InterestSubmissionTest extends TestCase
|
||||
|
||||
public function test_proponent_sharing_is_a_separate_optional_versioned_consent(): void
|
||||
{
|
||||
$this->postJson('/api/v1/interest-requests', [...$this->payload(), 'shareWithProponent' => true])->assertCreated();
|
||||
$this->postJson('/api/v1/interest-requests', [...$this->payload(), 'shareWithProponent' => true], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$interest = InterestRequest::firstOrFail();
|
||||
$this->assertDatabaseHas('consents', ['interest_request_id' => $interest->id,
|
||||
'purpose' => 'respond_to_interest', 'status' => 'granted']);
|
||||
@@ -65,14 +73,13 @@ class InterestSubmissionTest extends TestCase
|
||||
$this->assertSame(2, DB::table('consents')->where('interest_request_id', $interest->id)->count());
|
||||
}
|
||||
|
||||
public function test_old_clients_still_work_and_distinct_keys_create_distinct_submissions(): void
|
||||
public function test_missing_key_is_refused_and_distinct_general_requests_have_separate_identities(): void
|
||||
{
|
||||
$this->postJson('/api/v1/interest-requests', $this->payload())->assertCreated();
|
||||
foreach ([Str::uuid(), Str::uuid()] as $key) {
|
||||
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) $key])->assertCreated();
|
||||
}
|
||||
$this->assertDatabaseCount('interest_requests', 3);
|
||||
$this->assertDatabaseCount('outbox_events', 3);
|
||||
$this->postJson('/api/v1/interest-requests', $this->payload())->assertUnprocessable();
|
||||
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->assertDatabaseCount('interest_requests', 2);
|
||||
$this->assertDatabaseCount('outbox_events', 2);
|
||||
$this->assertDatabaseCount('interest_submission_receipts', 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Http\Controllers\InvestmentPortfolioController;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentComplements;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\OpportunityClassification;
|
||||
use App\Services\PartnershipExchange;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -52,29 +54,31 @@ final class InvestmentComplementsTest extends TestCase
|
||||
|
||||
public function test_complements_survive_draft_confirmation_and_consumer_snapshot_without_overwriting_title(): void
|
||||
{
|
||||
$actor = User::factory()->create(); $this->actingAs($actor);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$origin = $this->source();
|
||||
$option = collect(app(InvestmentComplements::class)->options($origin))->firstWhere('code', 'storage');
|
||||
$target = $option['opportunities'][0]['key'];
|
||||
$need = ['origin' => $origin, 'code' => 'spinning', 'target' => null];
|
||||
$offer = ['origin' => $origin, 'code' => 'storage', 'target' => $target];
|
||||
$query = http_build_query(['complement_origin' => $origin, 'complement_code' => 'storage', 'complement_target' => $target]);
|
||||
$this->get('/investimentos/iniciar?'.$query)->assertOk()->assertInertia(fn(Assert $p) => $p->where('entryComplements.0.target.key', $target)->where('opportunityChoices.0.opportunity.key', $target));
|
||||
$this->get('/investimentos/iniciar?'.$query)->assertOk()->assertInertia(fn (Assert $p) => $p->where('entryComplements.0.target.key', $target)->where('opportunityChoices.0.opportunity.key', $target));
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA título deliberado dos complementos', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$body = ['version' => $version, 'selection' => [], 'complements' => [$need, $offer], 'opportunity_choices' => [['source' => $target, 'portfolio_origins' => [substr($origin, 10)]]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 1])->assertOk();
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn(Assert $p) => $p->has('entryComplements', 2)->where('entryComplements.0.kind', 'need')->where('entryComplements.1.target.key', $target));
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn (Assert $p) => $p->has('entryComplements', 2)->where('entryComplements.0.kind', 'need')->where('entryComplements.1.target.key', $target));
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->assertSame('QA título deliberado dos complementos', $plan['fields']['project_title']);
|
||||
$control = [...$body, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', $control)->assertOk();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', $control)->assertOk()->assertJsonPath('replayed', true);
|
||||
$this->flushSession(); $this->actingAs($actor);
|
||||
$this->flushSession();
|
||||
$this->actingAs($actor);
|
||||
$view = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($plan['complements'], $view['context']['complements']);
|
||||
$this->assertSame($plan['complements'], json_decode($view['prefill']['simulator']['context_applicability_snapshot'], true)['complements']);
|
||||
$this->get('/investimentos/'.$id)->assertOk()->assertInertia(fn(Assert $p) => $p->has('investment_context.complements', 2));
|
||||
$this->get('/investimentos/'.$id)->assertOk()->assertInertia(fn (Assert $p) => $p->has('investment_context.complements', 2));
|
||||
$this->actingAs(User::factory()->create())->getJson('/investimentos/'.$id.'/contexto')->assertForbidden();
|
||||
}
|
||||
|
||||
@@ -95,7 +99,8 @@ final class InvestmentComplementsTest extends TestCase
|
||||
|
||||
public function test_concrete_training_and_finance_services_are_reused_only_for_their_documented_origin(): void
|
||||
{
|
||||
$actor = User::factory()->create(); $this->actingAs($actor);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$origin = $this->source();
|
||||
foreach (['training' => 'Formação e certificação', 'finance' => 'Financiamento'] as $type => $title) {
|
||||
$service = app(PartnershipExchange::class)->save($actor, ['client_key' => (string) Str::uuid(), 'title' => $title, 'kind' => 'offering', 'partnership_type' => $type,
|
||||
@@ -110,15 +115,18 @@ final class InvestmentComplementsTest extends TestCase
|
||||
$this->assertSame('service', $resolved[0]['kind']);
|
||||
}
|
||||
$other = InvestmentPortfolioController::visible()->where('content->code', 'COR-01')->firstOrFail();
|
||||
$this->assertSame([], collect(app(InvestmentComplements::class)->options('portfolio:'.$other->id))->flatMap(fn($r) => $r['services'])->all());
|
||||
$this->assertSame([], collect(app(InvestmentComplements::class)->options('portfolio:'.$other->id))->flatMap(fn ($r) => $r['services'])->all());
|
||||
}
|
||||
|
||||
public function test_explicit_complementary_project_relationship_and_geography_control_the_available_fiche(): void
|
||||
{
|
||||
$records = Opportunity::published()->orderBy('id')->take(2)->get();
|
||||
[$main, $target] = [$records[0], $records[1]];
|
||||
$main->summary = 'QA investimento principal'; $main->save();
|
||||
$target->title = 'Regadio QA relacionado'; $target->summary = 'Regadio para a cadeia de valor QA'; $target->save();
|
||||
$main->summary = 'QA investimento principal';
|
||||
$main->save();
|
||||
$target->title = 'Regadio QA relacionado';
|
||||
$target->summary = 'Regadio para a cadeia de valor QA';
|
||||
$target->save();
|
||||
$projects = InvestmentPortfolioController::visible()->whereNotNull('project_id')->take(2)->pluck('project_id');
|
||||
DB::table('opportunity_projects')->whereIn('opportunity_id', [$main->id, $target->id])->delete();
|
||||
DB::table('opportunity_projects')->insert([['opportunity_id' => $main->id, 'project_id' => $projects[0]], ['opportunity_id' => $target->id, 'project_id' => $projects[1]]]);
|
||||
@@ -127,9 +135,10 @@ final class InvestmentComplementsTest extends TestCase
|
||||
$service = app(InvestmentComplements::class);
|
||||
$options = $service->options('opportunity:'.$main->id);
|
||||
$this->assertSame('opportunity:'.$target->id, collect($options)->firstWhere('code', 'irrigation')['opportunities'][0]['key']);
|
||||
$sofala = collect(app(\App\Services\InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$gaza = app(\App\Services\InvestmentCorridorContext::class)->provinces('limpopo')[0]->id;
|
||||
$target->primary_territory_id = $gaza; $target->save();
|
||||
$sofala = collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$gaza = app(InvestmentCorridorContext::class)->provinces('limpopo')[0]->id;
|
||||
$target->primary_territory_id = $gaza;
|
||||
$target->save();
|
||||
$filtered = $service->options('opportunity:'.$main->id, $sofala);
|
||||
$this->assertSame([], collect($filtered)->firstWhere('code', 'irrigation')['opportunities']);
|
||||
$batch = $this->postJson('/complementos-investimento', ['contexts' => [['origin' => 'opportunity:'.$main->id, 'territory_id' => $sofala]]])->assertOk()->json();
|
||||
@@ -140,7 +149,8 @@ final class InvestmentComplementsTest extends TestCase
|
||||
|
||||
public function test_previous_relation_is_preserved_as_history_when_an_offer_is_withdrawn(): void
|
||||
{
|
||||
$service = app(InvestmentComplements::class); $origin = $this->source();
|
||||
$service = app(InvestmentComplements::class);
|
||||
$origin = $this->source();
|
||||
$target = collect($service->options($origin))->firstWhere('code', 'storage')['opportunities'][0]['key'];
|
||||
$input = [['origin' => $origin, 'code' => 'storage', 'target' => $target]];
|
||||
$previous = $service->resolve($input);
|
||||
@@ -159,28 +169,31 @@ final class InvestmentComplementsTest extends TestCase
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA retirada de complemento', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$origin = $this->source(); $selection = (string) Str::uuid();
|
||||
$origin = $this->source();
|
||||
$selection = (string) Str::uuid();
|
||||
$entry = app(InvestmentComplements::class)->resolve([['origin' => $origin, 'code' => 'spinning']])[0];
|
||||
$query = http_build_query(['complement_origin' => $origin, 'complement_code' => 'spinning', 'selection_key' => $selection]);
|
||||
$tag = 'complement:'.hash('sha256', $entry['key'].'@'.$selection);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn(Assert $p) => $p->where('entrySources.0', $tag)->has('entryComplements', 1));
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn (Assert $p) => $p->where('entrySources.0', $tag)->has('entryComplements', 1));
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'),
|
||||
'draft_sequence' => 1, 'selection' => [], 'complements' => [], 'entry_sources' => [$tag], 'declarations' => ['project_title' => 'QA edição a conservar']])->assertOk();
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn(Assert $p) => $p->has('entryComplements', 0)->where('draft.declarations.project_title', 'QA edição a conservar'));
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn (Assert $p) => $p->has('entryComplements', 0)->where('draft.declarations.project_title', 'QA edição a conservar'));
|
||||
$query = http_build_query(['complement_origin' => $origin, 'complement_code' => 'spinning', 'selection_key' => (string) Str::uuid()]);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn(Assert $p) => $p->has('entryComplements', 1)->where('draft.declarations.project_title', 'QA edição a conservar'));
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?'.$query)->assertOk()->assertInertia(fn (Assert $p) => $p->has('entryComplements', 1)->where('draft.declarations.project_title', 'QA edição a conservar'));
|
||||
}
|
||||
|
||||
public function test_public_chain_contract_preserves_both_documentary_references_in_the_selected_relation(): void
|
||||
{
|
||||
$records = Opportunity::published()->orderBy('id')->take(2)->get();
|
||||
[$main, $target] = [$records[0], $records[1]];
|
||||
$main->summary = 'QA produção e processamento'; $main->save();
|
||||
$target->summary = 'QA processamento da mesma cadeia'; $target->save();
|
||||
$main->summary = 'QA produção e processamento';
|
||||
$main->save();
|
||||
$target->summary = 'QA processamento da mesma cadeia';
|
||||
$target->save();
|
||||
$row = ['target_type' => 'chain', 'target_id' => (string) Str::uuid(), 'label' => 'Cadeia sintética QA', 'state' => 'preliminary', 'source_reference' => 'Referência documental sintética QA'];
|
||||
$classification = \Mockery::mock(\App\Services\OpportunityClassification::class);
|
||||
$classification->shouldReceive('publicRows')->andReturnUsing(fn($record) => in_array($record->id, [$main->id, $target->id], true) ? [$row] : []);
|
||||
$this->app->instance(\App\Services\OpportunityClassification::class, $classification);
|
||||
$classification = \Mockery::mock(OpportunityClassification::class);
|
||||
$classification->shouldReceive('publicRows')->andReturnUsing(fn ($record) => in_array($record->id, [$main->id, $target->id], true) ? [$row] : []);
|
||||
$this->app->instance(OpportunityClassification::class, $classification);
|
||||
$service = app(InvestmentComplements::class);
|
||||
$options = $service->options('opportunity:'.$main->id);
|
||||
$offer = collect(collect($options)->firstWhere('code', 'processing')['opportunities'])->firstWhere('key', 'opportunity:'.$target->id);
|
||||
|
||||
@@ -4,8 +4,13 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\{CorridorAgribusinessOpportunities, InvestmentCorridorContext, InvestmentConsumerScope, InvestorContext, InvestmentZones, VirtualDesk};
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\InvestmentZones;
|
||||
use App\Services\InvestorContext;
|
||||
use App\Services\VirtualDesk;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
@@ -13,122 +18,150 @@ use Tests\TestCase;
|
||||
final class InvestmentConsumerScopeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $actor;
|
||||
|
||||
private string $id;
|
||||
|
||||
private array $choices;
|
||||
|
||||
private array $parks;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();$this->withoutVite();
|
||||
$this->withoutMiddleware(\Illuminate\Routing\Middleware\ThrottleRequests::class);
|
||||
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name);$this->assertSame(55441,(int)$db->port);
|
||||
config(['investor-path.enabled'=>true,'investor-path.private_preparation'=>true,'suitecrm.enabled'=>false,'investmoz_ai.enabled'=>false]);
|
||||
$this->actor=User::factory()->create();$this->actingAs($this->actor);
|
||||
$this->id=$this->postJson('/investimentos',['title'=>'SYNTHETIC QA — âmbito específico','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$corridors=app(InvestmentCorridorContext::class);
|
||||
$records=[];foreach(['beira','limpopo'] as $corridor){
|
||||
$entry=collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor',config('investment_corridors.'.$corridor.'.name'));
|
||||
$records[]=Opportunity::where('management_creation_key',$entry['key'])->firstOrFail();
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$this->withoutMiddleware(ThrottleRequests::class);
|
||||
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
||||
$this->assertSame(55441, (int) $db->port);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->actor = User::factory()->create();
|
||||
$this->actingAs($this->actor);
|
||||
$this->id = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA — âmbito específico', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$corridors = app(InvestmentCorridorContext::class);
|
||||
$records = [];
|
||||
foreach (['beira', 'limpopo'] as $corridor) {
|
||||
$entry = collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor', config('investment_corridors.'.$corridor.'.name'));
|
||||
$records[] = Opportunity::where('management_creation_key', $entry['key'])->firstOrFail();
|
||||
}
|
||||
$sofala=collect($corridors->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$gaza=$corridors->provinces('limpopo')[0]->id;
|
||||
$manica=collect($corridors->provinces('beira'))->firstWhere('name','Manica')->id;
|
||||
$template=app(InvestmentZones::class)->visible()->whereIn('category',['industrial_park','zee','zfi'])->firstOrFail();
|
||||
foreach([$sofala,$gaza,$manica] as $territory){$p=$template->replicate();$p->code='SYNTHETIC-QA-'.Str::uuid();$p->name='SYNTHETIC QA — parque '.$territory;$p->primary_territory_id=$territory;$p->save();$this->parks[]=$p;}
|
||||
$this->choices=[['source'=>'opportunity:'.$records[0]->id,'corridor_key'=>'beira','territory'=>'territory:'.$sofala,'park'=>'park:'.$this->parks[0]->id,'activities'=>['production']],['source'=>'opportunity:'.$records[1]->id,'corridor_key'=>'limpopo','territory'=>'territory:'.$gaza,'park'=>'park:'.$this->parks[1]->id,'activities'=>['trade']]];
|
||||
$sofala = collect($corridors->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$gaza = $corridors->provinces('limpopo')[0]->id;
|
||||
$manica = collect($corridors->provinces('beira'))->firstWhere('name', 'Manica')->id;
|
||||
$template = app(InvestmentZones::class)->visible()->whereIn('category', ['industrial_park', 'zee', 'zfi'])->firstOrFail();
|
||||
foreach ([$sofala, $gaza, $manica] as $territory) {
|
||||
$p = $template->replicate();
|
||||
$p->code = 'SYNTHETIC-QA-'.Str::uuid();
|
||||
$p->name = 'SYNTHETIC QA — parque '.$territory;
|
||||
$p->primary_territory_id = $territory;
|
||||
$p->save();
|
||||
$this->parks[] = $p;
|
||||
}
|
||||
$this->choices = [['source' => 'opportunity:'.$records[0]->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$sofala, 'park' => 'park:'.$this->parks[0]->id, 'activities' => ['production']], ['source' => 'opportunity:'.$records[1]->id, 'corridor_key' => 'limpopo', 'territory' => 'territory:'.$gaza, 'park' => 'park:'.$this->parks[1]->id, 'activities' => ['trade']]];
|
||||
$this->confirm();
|
||||
}
|
||||
|
||||
private function confirm(): array
|
||||
{
|
||||
$v=$this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$body=['version'=>$v['case']['version'],'selection'=>[],'opportunity_choices'=>$this->choices];
|
||||
$plan=$this->postJson('/investimentos/'.$this->id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar',[...$body,'preview_hash'=>$plan['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$v = $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$body = ['version' => $v['case']['version'], 'selection' => [], 'opportunity_choices' => $this->choices];
|
||||
$plan = $this->postJson('/investimentos/'.$this->id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar', [...$body, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
|
||||
return $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
}
|
||||
|
||||
public function test_second_only_change_updates_its_parks_and_all_consumer_proposals_without_replacing_first(): void
|
||||
{
|
||||
$before=$this->getJson('/investimentos/'.$this->id.'/contexto')->json('context');
|
||||
$key=$this->choices[1]['source'];
|
||||
$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->assertOk()->assertJsonPath('prefill.land.parcels.0.province_id',$this->parks[1]->primary_territory_id);
|
||||
$pending=$this->choices;$pending[1]=[...$pending[1],'corridor_key'=>'beira','territory'=>null,'park'=>null];
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/rascunho',['version'=>$this->getJson('/investimentos/'.$this->id.'/contexto')->json('case.version'),'selection'=>[],'opportunity_choices'=>$pending,'draft_sequence'=>1000000])->assertOk();
|
||||
$this->get('/investimentos/'.$this->id.'/contexto/editar')->assertOk()->assertInertia(fn($p)=>$p->where('requestedChoices.1.territory',null));
|
||||
$this->choices[1]=[...$this->choices[1],'corridor_key'=>'beira','territory'=>'territory:'.$this->parks[2]->primary_territory_id,'park'=>'park:'.$this->parks[2]->id,'confirm_location_change'=>true,'location_reason'=>'Alteração expressa apenas da segunda oportunidade para comparação QA.'];
|
||||
$view=$this->confirm();
|
||||
$this->assertSame($before['opportunity_choices'][0],$view['context']['opportunity_choices'][0]);
|
||||
$this->assertSame($this->parks[2]->id,$view['context']['opportunity_choices'][1]['park']['id']);
|
||||
$scope=$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->assertOk();
|
||||
$scope->assertJsonPath('prefill.land.parcels.0.province_id',$this->parks[2]->primary_territory_id)->assertJsonPath('prefill.desk.territory_id',$this->parks[2]->primary_territory_id)->assertJsonPath('prefill.submission.location','Manica');
|
||||
$snapshot=json_decode($scope->json('prefill.simulator.context_applicability_snapshot'),true);
|
||||
$this->assertSame($this->parks[2]->id,$snapshot['zone']['id']);
|
||||
foreach($snapshot['requirements_assessment']['requirements'] as $r)$this->assertSame($key,$r['opportunity_key']);
|
||||
$this->assertCount(1,$snapshot['opportunity_choices']);
|
||||
$this->choices[1]['park']='park:'.$this->parks[1]->id;
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/previa',['version'=>$view['case']['version'],'selection'=>[],'opportunity_choices'=>$this->choices])->assertUnprocessable();
|
||||
$before = $this->getJson('/investimentos/'.$this->id.'/contexto')->json('context');
|
||||
$key = $this->choices[1]['source'];
|
||||
$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->assertOk()->assertJsonPath('prefill.land.parcels.0.province_id', $this->parks[1]->primary_territory_id);
|
||||
$pending = $this->choices;
|
||||
$pending[1] = [...$pending[1], 'corridor_key' => 'beira', 'territory' => null, 'park' => null];
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/rascunho', ['version' => $this->getJson('/investimentos/'.$this->id.'/contexto')->json('case.version'), 'selection' => [], 'opportunity_choices' => $pending, 'draft_sequence' => 1000000])->assertOk();
|
||||
$this->get('/investimentos/'.$this->id.'/contexto/editar')->assertOk()->assertInertia(fn ($p) => $p->where('requestedChoices.1.territory', null));
|
||||
$this->choices[1] = [...$this->choices[1], 'corridor_key' => 'beira', 'territory' => 'territory:'.$this->parks[2]->primary_territory_id, 'park' => 'park:'.$this->parks[2]->id, 'confirm_location_change' => true, 'location_reason' => 'Alteração expressa apenas da segunda oportunidade para comparação QA.'];
|
||||
$view = $this->confirm();
|
||||
$this->assertSame($before['opportunity_choices'][0], $view['context']['opportunity_choices'][0]);
|
||||
$this->assertSame($this->parks[2]->id, $view['context']['opportunity_choices'][1]['park']['id']);
|
||||
$scope = $this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->assertOk();
|
||||
$scope->assertJsonPath('prefill.land.parcels.0.province_id', $this->parks[2]->primary_territory_id)->assertJsonPath('prefill.desk.territory_id', $this->parks[2]->primary_territory_id)->assertJsonPath('prefill.submission.location', 'Manica');
|
||||
$snapshot = json_decode($scope->json('prefill.simulator.context_applicability_snapshot'), true);
|
||||
$this->assertSame($this->parks[2]->id, $snapshot['zone']['id']);
|
||||
foreach ($snapshot['requirements_assessment']['requirements'] as $r) {
|
||||
$this->assertSame($key, $r['opportunity_key']);
|
||||
}
|
||||
$this->assertCount(1, $snapshot['opportunity_choices']);
|
||||
$this->choices[1]['park'] = 'park:'.$this->parks[1]->id;
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/previa', ['version' => $view['case']['version'], 'selection' => [], 'opportunity_choices' => $this->choices])->assertUnprocessable();
|
||||
}
|
||||
|
||||
public function test_ambiguous_scope_proposes_only_common_data_and_rejects_foreign_identity(): void
|
||||
{
|
||||
$view=$this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame('SYNTHETIC QA — âmbito específico',$view['prefill']['land']['project_reference']);
|
||||
$view = $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame('SYNTHETIC QA — âmbito específico', $view['prefill']['land']['project_reference']);
|
||||
$this->assertEmpty($view['prefill']['land']['parcels'][0]);
|
||||
$this->assertArrayNotHasKey('territory_id',$view['prefill']['desk']);
|
||||
$this->assertArrayNotHasKey('location',$view['prefill']['submission']);
|
||||
$this->assertArrayNotHasKey('territory_id', $view['prefill']['desk']);
|
||||
$this->assertArrayNotHasKey('location', $view['prefill']['submission']);
|
||||
$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity=opportunity:99999999')->assertUnprocessable();
|
||||
$this->actingAs(User::factory()->create())->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($this->choices[1]['source']))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_land_desk_and_manifestation_save_and_recover_canonical_second_identity_and_preserve_deliberate_fields(): void
|
||||
{
|
||||
$first=$this->getJson('/investimentos/'.$this->id.'/contexto')->json('context.opportunity_choices.0');
|
||||
$this->choices[1]=[...$this->choices[1],'corridor_key'=>'beira','territory'=>'territory:'.$this->parks[2]->primary_territory_id,'park'=>'park:'.$this->parks[2]->id,'confirm_location_change'=>true,'location_reason'=>'Alteração expressa apenas da segunda oportunidade para comparação QA.'];
|
||||
$first = $this->getJson('/investimentos/'.$this->id.'/contexto')->json('context.opportunity_choices.0');
|
||||
$this->choices[1] = [...$this->choices[1], 'corridor_key' => 'beira', 'territory' => 'territory:'.$this->parks[2]->primary_territory_id, 'park' => 'park:'.$this->parks[2]->id, 'confirm_location_change' => true, 'location_reason' => 'Alteração expressa apenas da segunda oportunidade para comparação QA.'];
|
||||
$this->confirm();
|
||||
$key=$this->choices[1]['source'];
|
||||
$scope=app(InvestorContext::class)->prefill($this->getJson('/investimentos/'.$this->id.'/contexto')->json('context'),$key);
|
||||
$land=$this->postJson('/investidor/terra-duat',['payload'=>[...$scope['land'],'investor_path_case_id'=>$this->id,'context_opportunity'=>$key,'context_opportunity_snapshot'=>'forged','purpose'=>'Texto deliberado do requerente']])->assertCreated()->json('id');
|
||||
$landPayload=$this->getJson('/investidor/terra-duat/'.$land)->assertOk()->json('case.payload');
|
||||
$this->assertSame('Texto deliberado do requerente',$landPayload['purpose']);
|
||||
$this->assertSame($key,json_decode($landPayload['context_opportunity_snapshot'],true)['choice']['opportunity']['key']);
|
||||
$this->get('/investidor/terra-duat/'.$land.'/imprimir')->assertOk()->assertInertia(fn($p)=>$p->where('case.payload.context_opportunity',$key));
|
||||
$desk=app(VirtualDesk::class);$service=DB::table('desk_service_versions')->where('status','published')->firstOrFail();
|
||||
$request=$desk->createRequest($this->actor,$this->id,$service->id,(string)Str::uuid(),$key);
|
||||
$payload=$desk->decode($request->payload);$payload['context_opportunity_snapshot']='forged';
|
||||
if(isset($desk->definition($request)['fields']['description']))$payload['description']='Descrição deliberada de QA';
|
||||
$saved=$desk->save($this->actor,$request->id,['version'=>$request->version,'payload'=>$payload]);
|
||||
$recovered=$desk->decode($desk->request($this->actor,$saved->id)->payload);
|
||||
$this->assertSame($key,$recovered['context_opportunity']);
|
||||
$this->assertSame($this->parks[2]->id,json_decode($recovered['context_opportunity_snapshot'],true)['choice']['park']['id']);
|
||||
$rendered=view('desk.receipt',['record'=>(object)[...(array)$saved,'protocol'=>'SYNTHETIC-QA-SCOPE','submitted_at'=>now()->toDateTimeString()],'snapshot'=>['payload'=>$recovered],'definition'=>$desk->definition($saved)])->render();
|
||||
$this->assertStringContainsString('Manica',$rendered);$this->assertStringContainsString($key,$rendered);
|
||||
$submission=$this->postJson('/investidor/manifestacoes',['opportunity_id'=>(int)substr($key,12)])->assertCreated()->json('id');
|
||||
$v=$this->getJson('/investimentos/'.$this->id.'/contexto')->json('case.version');
|
||||
$bound=$this->postJson('/investidor/manifestacoes/'.$submission.'/contexto',['case_id'=>$this->id,'case_version'=>$v,'version'=>1])->assertOk()->json('version');
|
||||
$this->putJson('/investidor/manifestacoes/'.$submission,['version'=>$bound,'payload'=>[...$scope['submission'],'context_opportunity'=>$key,'context_opportunity_snapshot'=>'forged','objective'=>'Objectivo deliberado do investidor']])->assertOk();
|
||||
$p=$this->getJson('/investidor/manifestacoes/'.$submission)->assertOk()->json('submission.payload');
|
||||
$this->assertSame($key,$p['context_opportunity']);$this->assertSame('Objectivo deliberado do investidor',$p['objective']);
|
||||
$this->assertSame($key,json_decode($p['context_opportunity_snapshot'],true)['choice']['opportunity']['key']);
|
||||
$this->assertSame('Manica',json_decode($p['context_opportunity_snapshot'],true)['choice']['territory']['title']);
|
||||
$this->assertSame((int)substr($key,12),$this->getJson('/investidor/manifestacoes/'.$submission)->json('submission.opportunity_id'));
|
||||
$revision=$this->getJson('/investidor/manifestacoes/'.$submission.'/revisions/3')->assertOk()->json('snapshot.payload');
|
||||
$this->assertSame($key,$revision['context_opportunity']);
|
||||
$this->assertSame($first,$this->getJson('/investimentos/'.$this->id.'/contexto')->json('context.opportunity_choices.0'));
|
||||
$key = $this->choices[1]['source'];
|
||||
$scope = app(InvestorContext::class)->prefill($this->getJson('/investimentos/'.$this->id.'/contexto')->json('context'), $key);
|
||||
$land = $this->postJson('/investidor/terra-duat', ['payload' => [...$scope['land'], 'investor_path_case_id' => $this->id, 'context_opportunity' => $key, 'context_opportunity_snapshot' => 'forged', 'purpose' => 'Texto deliberado do requerente']])->assertCreated()->json('id');
|
||||
$landPayload = $this->getJson('/investidor/terra-duat/'.$land)->assertOk()->json('case.payload');
|
||||
$this->assertSame('Texto deliberado do requerente', $landPayload['purpose']);
|
||||
$this->assertSame($key, json_decode($landPayload['context_opportunity_snapshot'], true)['choice']['opportunity']['key']);
|
||||
$this->get('/investidor/terra-duat/'.$land.'/imprimir')->assertOk()->assertInertia(fn ($p) => $p->where('case.payload.context_opportunity', $key));
|
||||
$desk = app(VirtualDesk::class);
|
||||
$service = DB::table('desk_service_versions')->where('status', 'published')->firstOrFail();
|
||||
$request = $desk->createRequest($this->actor, $this->id, $service->id, (string) Str::uuid(), $key);
|
||||
$payload = $desk->decode($request->payload);
|
||||
$payload['context_opportunity_snapshot'] = 'forged';
|
||||
if (isset($desk->definition($request)['fields']['description'])) {
|
||||
$payload['description'] = 'Descrição deliberada de QA';
|
||||
}
|
||||
$saved = $desk->save($this->actor, $request->id, ['version' => $request->version, 'payload' => $payload]);
|
||||
$recovered = $desk->decode($desk->request($this->actor, $saved->id)->payload);
|
||||
$this->assertSame($key, $recovered['context_opportunity']);
|
||||
$this->assertSame($this->parks[2]->id, json_decode($recovered['context_opportunity_snapshot'], true)['choice']['park']['id']);
|
||||
$rendered = view('desk.receipt', ['record' => (object) [...(array) $saved, 'protocol' => 'SYNTHETIC-QA-SCOPE', 'submitted_at' => now()->toDateTimeString()], 'snapshot' => ['payload' => $recovered], 'definition' => $desk->definition($saved)])->render();
|
||||
$this->assertStringContainsString('Manica', $rendered);
|
||||
$this->assertStringContainsString($key, $rendered);
|
||||
$submission = $this->postJson('/investidor/manifestacoes', ['opportunity_id' => (int) substr($key, 12)])->assertCreated()->json('id');
|
||||
$v = $this->getJson('/investimentos/'.$this->id.'/contexto')->json('case.version');
|
||||
$bound = $this->postJson('/investidor/manifestacoes/'.$submission.'/contexto', ['case_id' => $this->id, 'case_version' => $v, 'version' => 1])->assertOk()->json('version');
|
||||
$this->putJson('/investidor/manifestacoes/'.$submission, ['version' => $bound, 'payload' => [...$scope['submission'], 'context_opportunity' => $key, 'context_opportunity_snapshot' => 'forged', 'objective' => 'Objectivo deliberado do investidor']])->assertOk();
|
||||
$p = $this->getJson('/investidor/manifestacoes/'.$submission)->assertOk()->json('submission.payload');
|
||||
$this->assertSame($key, $p['context_opportunity']);
|
||||
$this->assertSame('Objectivo deliberado do investidor', $p['objective']);
|
||||
$this->assertSame($key, json_decode($p['context_opportunity_snapshot'], true)['choice']['opportunity']['key']);
|
||||
$this->assertSame('Manica', json_decode($p['context_opportunity_snapshot'], true)['choice']['territory']['title']);
|
||||
$this->assertSame((int) substr($key, 12), $this->getJson('/investidor/manifestacoes/'.$submission)->json('submission.opportunity_id'));
|
||||
$revision = $this->getJson('/investidor/manifestacoes/'.$submission.'/revisions/3')->assertOk()->json('snapshot.payload');
|
||||
$this->assertSame($key, $revision['context_opportunity']);
|
||||
$this->assertSame($first, $this->getJson('/investimentos/'.$this->id.'/contexto')->json('context.opportunity_choices.0'));
|
||||
}
|
||||
|
||||
public function test_returned_request_keeps_its_locked_opportunity_snapshot_when_only_description_is_editable(): void
|
||||
{
|
||||
$desk=app(VirtualDesk::class);$service=DB::table('desk_service_versions')->where('status','published')->firstOrFail();
|
||||
$row=$desk->createRequest($this->actor,$this->id,$service->id,(string)Str::uuid(),$this->choices[1]['source']);
|
||||
$payload=$desk->decode($row->payload);$snapshot=$payload['context_opportunity_snapshot'];
|
||||
DB::table('desk_requests')->where('id',$row->id)->update(['status'=>'returned','editable_fields'=>json_encode(['description']),'protocol'=>'SYNTHETIC-QA-'.Str::uuid(),'submitted_at'=>now(),'submitted_snapshot'=>$desk->encode(['payload'=>$payload,'investment_context'=>['revision'=>1]])]);
|
||||
$this->choices[1]=[...$this->choices[1],'corridor_key'=>'beira','territory'=>'territory:'.$this->parks[2]->primary_territory_id,'park'=>'park:'.$this->parks[2]->id,'confirm_location_change'=>true,'location_reason'=>'Mudança apenas da segunda oportunidade após devolução do pedido QA.'];$this->confirm();
|
||||
$saved=$desk->save($this->actor,$row->id,['version'=>$row->version,'payload'=>[...$payload,'description'=>'Correcção deliberada apenas da descrição']]);
|
||||
$after=$desk->decode($saved->payload);
|
||||
$this->assertSame($snapshot,$after['context_opportunity_snapshot']);
|
||||
$this->assertSame($payload['context_opportunity'],$after['context_opportunity']);
|
||||
$desk = app(VirtualDesk::class);
|
||||
$service = DB::table('desk_service_versions')->where('status', 'published')->firstOrFail();
|
||||
$row = $desk->createRequest($this->actor, $this->id, $service->id, (string) Str::uuid(), $this->choices[1]['source']);
|
||||
$payload = $desk->decode($row->payload);
|
||||
$snapshot = $payload['context_opportunity_snapshot'];
|
||||
DB::table('desk_requests')->where('id', $row->id)->update(['status' => 'returned', 'editable_fields' => json_encode(['description']), 'protocol' => 'SYNTHETIC-QA-'.Str::uuid(), 'submitted_at' => now(), 'submitted_snapshot' => $desk->encode(['payload' => $payload, 'investment_context' => ['revision' => 1]])]);
|
||||
$this->choices[1] = [...$this->choices[1], 'corridor_key' => 'beira', 'territory' => 'territory:'.$this->parks[2]->primary_territory_id, 'park' => 'park:'.$this->parks[2]->id, 'confirm_location_change' => true, 'location_reason' => 'Mudança apenas da segunda oportunidade após devolução do pedido QA.'];
|
||||
$this->confirm();
|
||||
$saved = $desk->save($this->actor, $row->id, ['version' => $row->version, 'payload' => [...$payload, 'description' => 'Correcção deliberada apenas da descrição']]);
|
||||
$after = $desk->decode($saved->payload);
|
||||
$this->assertSame($snapshot, $after['context_opportunity_snapshot']);
|
||||
$this->assertSame($payload['context_opportunity'], $after['context_opportunity']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,85 +3,102 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\InvestmentOpportunityChoices;
|
||||
use App\Services\VirtualDesk;
|
||||
use App\Services\InvestmentZones;
|
||||
use App\Services\InvestorContext;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentCorridorContextTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $investor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); $this->withoutVite();
|
||||
$t=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test',$t->name);$this->assertSame(55441,(int)$t->port);
|
||||
config(['investor-path.enabled'=>true,'investor-path.private_preparation'=>true,'suitecrm.enabled'=>false,'investmoz_ai.enabled'=>false]);
|
||||
$this->investor=User::factory()->create();$this->actingAs($this->investor);
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$t = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $t->name);
|
||||
$this->assertSame(55441, (int) $t->port);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->investor = User::factory()->create();
|
||||
$this->actingAs($this->investor);
|
||||
}
|
||||
|
||||
private function record(string $corridor): Opportunity
|
||||
{
|
||||
$entry=collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor',config('investment_corridors.'.$corridor.'.name'));
|
||||
return Opportunity::where('management_creation_key',$entry['key'])->firstOrFail();
|
||||
$entry = collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor', config('investment_corridors.'.$corridor.'.name'));
|
||||
|
||||
return Opportunity::where('management_creation_key', $entry['key'])->firstOrFail();
|
||||
}
|
||||
|
||||
public function test_land_status_uses_the_real_decision_preserves_inactive_values_and_allows_incomplete_drafts(): void
|
||||
{
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA situação do terreno','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$setNeed=function(string $need) use($id): array {
|
||||
$version=$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$this->postJson('/investimentos/'.$id.'/aplicabilidade',['version'=>$version,'land_needed'=>$need,'external_funding'=>'unknown','viability'=>'unknown','reason'=>'Cenário QA '.$need])->assertOk();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA situação do terreno', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$setNeed = function (string $need) use ($id): array {
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$this->postJson('/investimentos/'.$id.'/aplicabilidade', ['version' => $version, 'land_needed' => $need, 'external_funding' => 'unknown', 'viability' => 'unknown', 'reason' => 'Cenário QA '.$need])->assertOk();
|
||||
|
||||
return $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
};
|
||||
$view=$setNeed('yes');
|
||||
$body=['context'=>$id,'personal_snapshot'=>[],'economic_snapshot'=>['purpose'=>'simulate_only','context_applicability_snapshot'=>$view['prefill']['simulator']['context_applicability_snapshot'],'land_status'=>'duat','selection_labels'=>['land_status'=>'DUAT']]];
|
||||
$created=$this->postJson('/api/v1/simulation-drafts',$body,['Idempotency-Key'=>(string)Str::uuid()])->assertCreated();
|
||||
$draft=$created->json('data.id');$etag=$created->headers->get('ETag');
|
||||
foreach(['no','unknown'] as $need){
|
||||
$view=$setNeed($need);
|
||||
$this->assertSame($need,json_decode($view['prefill']['simulator']['context_applicability_snapshot'],true)['land_preparation']['need']);
|
||||
$update=$this->putJson('/api/v1/simulation-drafts/'.$draft,['personal_snapshot'=>[],'economic_snapshot'=>['purpose'=>'simulate_only','context_applicability_snapshot'=>$body['economic_snapshot']['context_applicability_snapshot']]],['If-Match'=>$etag])->assertOk();
|
||||
$recovered=$this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk();
|
||||
$view = $setNeed('yes');
|
||||
$body = ['context' => $id, 'personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'context_applicability_snapshot' => $view['prefill']['simulator']['context_applicability_snapshot'], 'land_status' => 'duat', 'selection_labels' => ['land_status' => 'DUAT']]];
|
||||
$created = $this->postJson('/api/v1/simulation-drafts', $body, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$draft = $created->json('data.id');
|
||||
$etag = $created->headers->get('ETag');
|
||||
foreach (['no', 'unknown'] as $need) {
|
||||
$view = $setNeed($need);
|
||||
$this->assertSame($need, json_decode($view['prefill']['simulator']['context_applicability_snapshot'], true)['land_preparation']['need']);
|
||||
$update = $this->putJson('/api/v1/simulation-drafts/'.$draft, ['personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'context_applicability_snapshot' => $body['economic_snapshot']['context_applicability_snapshot']]], ['If-Match' => $etag])->assertOk();
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk();
|
||||
// Omitting context cannot bypass the real dossier decision. Hidden values are retained.
|
||||
$this->assertSame('duat',$recovered->json('data.economic_snapshot.land_status'));
|
||||
$this->assertSame('DUAT',$recovered->json('data.economic_snapshot.selection_labels.land_status'));
|
||||
$this->assertSame($need,json_decode($recovered->json('data.economic_snapshot.context_applicability_snapshot'),true)['land_preparation']['need']);
|
||||
$etag=$update->headers->get('ETag');
|
||||
$this->assertSame('duat', $recovered->json('data.economic_snapshot.land_status'));
|
||||
$this->assertSame('DUAT', $recovered->json('data.economic_snapshot.selection_labels.land_status'));
|
||||
$this->assertSame($need, json_decode($recovered->json('data.economic_snapshot.context_applicability_snapshot'), true)['land_preparation']['need']);
|
||||
$etag = $update->headers->get('ETag');
|
||||
}
|
||||
$setNeed('yes');
|
||||
$this->flushSession();$this->actingAs($this->investor);
|
||||
$this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.land_status','duat');
|
||||
$updated=$this->putJson('/api/v1/simulation-drafts/'.$draft,[...$body,'economic_snapshot'=>['purpose'=>'simulate_only','land_status'=>'leased']],['If-Match'=>$etag])->assertOk();
|
||||
$recovered=$this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.land_status','leased');
|
||||
$this->assertSame('yes',json_decode($recovered->json('data.economic_snapshot.context_applicability_snapshot'),true)['land_preparation']['need']);
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$draft,[...$body,'economic_snapshot'=>['purpose'=>'simulate_only','land_status'=>'invalid']],['If-Match'=>$updated->headers->get('ETag')])->assertUnprocessable();
|
||||
$empty=app(\App\Services\InvestorContext::class)->prefill(['fields'=>['site_tenure'=>'lease'],'revision'=>0,'provenance'=>[],'land_preparation'=>['need'=>'yes','reason'=>'QA']]);
|
||||
$this->assertSame('leased',$empty['simulator']['land_status']);
|
||||
$this->flushSession();
|
||||
$this->actingAs($this->investor);
|
||||
$this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.land_status', 'duat');
|
||||
$updated = $this->putJson('/api/v1/simulation-drafts/'.$draft, [...$body, 'economic_snapshot' => ['purpose' => 'simulate_only', 'land_status' => 'leased']], ['If-Match' => $etag])->assertOk();
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.land_status', 'leased');
|
||||
$this->assertSame('yes', json_decode($recovered->json('data.economic_snapshot.context_applicability_snapshot'), true)['land_preparation']['need']);
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$draft, [...$body, 'economic_snapshot' => ['purpose' => 'simulate_only', 'land_status' => 'invalid']], ['If-Match' => $updated->headers->get('ETag')])->assertUnprocessable();
|
||||
$empty = app(InvestorContext::class)->prefill(['fields' => ['site_tenure' => 'lease'], 'revision' => 0, 'provenance' => [], 'land_preparation' => ['need' => 'yes', 'reason' => 'QA']]);
|
||||
$this->assertSame('leased', $empty['simulator']['land_status']);
|
||||
}
|
||||
|
||||
public function test_simulator_reuses_names_for_the_exact_chosen_territory_and_sector_without_creating_a_location(): void
|
||||
{
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA continuidade simulador','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$province=collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$district=app(\App\Services\InvestmentGeography::class)->publicReferences()->where('parent_id',$province)->where('location_type','district')->firstOrFail();
|
||||
$record=$this->record('beira');
|
||||
$plan=$this->postJson('/investimentos/'.$id.'/contexto/previa',['version'=>$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'),'selection'=>[],'opportunity_choices'=>[['source'=>'opportunity:'.$record->id,'corridor_key'=>'beira','territory'=>'territory:'.$district->id]]])->assertOk()->json();
|
||||
$sim=app(\App\Services\InvestorContext::class)->prefill($plan)['simulator'];
|
||||
$this->assertSame('investor',$sim['journey_type']);
|
||||
$this->assertSame('simulate_only',$sim['purpose']);
|
||||
$this->assertSame($province,$sim['province_id']);
|
||||
$this->assertSame('Sofala',$sim['province_id_label']);
|
||||
$this->assertSame($district->id,$sim['district_id']);
|
||||
$this->assertSame($district->name,$sim['district_id_label']);
|
||||
$this->assertSame((string)$record->sector_id,$sim['sector_id']);
|
||||
$this->assertSame(\App\Models\Sector::findOrFail($record->sector_id)->name,$sim['sector_id_label']);
|
||||
$this->assertArrayNotHasKey('locality_id_label',$sim);
|
||||
$this->assertArrayNotHasKey('admin_post_id_label',$sim);
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA continuidade simulador', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$province = collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$district = app(InvestmentGeography::class)->publicReferences()->where('parent_id', $province)->where('location_type', 'district')->firstOrFail();
|
||||
$record = $this->record('beira');
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => [], 'opportunity_choices' => [['source' => 'opportunity:'.$record->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$district->id]]])->assertOk()->json();
|
||||
$sim = app(InvestorContext::class)->prefill($plan)['simulator'];
|
||||
$this->assertSame('investor', $sim['journey_type']);
|
||||
$this->assertSame('simulate_only', $sim['purpose']);
|
||||
$this->assertSame($province, $sim['province_id']);
|
||||
$this->assertSame('Sofala', $sim['province_id_label']);
|
||||
$this->assertSame($district->id, $sim['district_id']);
|
||||
$this->assertSame($district->name, $sim['district_id_label']);
|
||||
$this->assertSame((string) $record->sector_id, $sim['sector_id']);
|
||||
$this->assertSame(Sector::findOrFail($record->sector_id)->name, $sim['sector_id_label']);
|
||||
$this->assertArrayNotHasKey('locality_id_label', $sim);
|
||||
$this->assertArrayNotHasKey('admin_post_id_label', $sim);
|
||||
}
|
||||
|
||||
public function test_nonapplicable_land_hides_the_action_and_reopening_recovers_saved_evidence(): void
|
||||
{
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA adaptação sem perda', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
@@ -104,84 +121,104 @@ class InvestmentCorridorContextTest extends TestCase
|
||||
$this->assertSame('preparing', collect($view['steps'])->firstWhere('code', 'S10')['state']);
|
||||
$this->assertCount(19, $view['steps']);
|
||||
}
|
||||
|
||||
public function test_tempo_configuration_uses_existing_ids_and_maputo_includes_both_units(): void
|
||||
{
|
||||
foreach(config('investment_corridors') as $key=>$entry){
|
||||
$provinces=app(InvestmentCorridorContext::class)->provinces($key);
|
||||
$this->assertEqualsCanonicalizing($entry['provinces'],array_column($provinces,'source_code'));
|
||||
$response=$this->getJson('/api/v1/investment/territory-options?type=province&corridor='.$key)->assertOk();
|
||||
$this->assertEqualsCanonicalizing(array_column($provinces,'id'),array_column($response->json('data'),'id'));
|
||||
foreach (config('investment_corridors') as $key => $entry) {
|
||||
$provinces = app(InvestmentCorridorContext::class)->provinces($key);
|
||||
$this->assertEqualsCanonicalizing($entry['provinces'], array_column($provinces, 'source_code'));
|
||||
$response = $this->getJson('/api/v1/investment/territory-options?type=province&corridor='.$key)->assertOk();
|
||||
$this->assertEqualsCanonicalizing(array_column($provinces, 'id'), array_column($response->json('data'), 'id'));
|
||||
}
|
||||
$this->assertEqualsCanonicalizing(['Maputo Província','Maputo Cidade'],array_column(app(InvestmentCorridorContext::class)->provinces('maputo'),'name'));
|
||||
foreach(['nacala','limpopo'] as $key){
|
||||
$choice=app(InvestmentOpportunityChoices::class)->resolve([['source'=>'opportunity:'.$this->record($key)->id]])[0];
|
||||
$this->assertSame(app(InvestmentCorridorContext::class)->provinces($key)[0]->id,$choice['territory']['id']);
|
||||
$this->assertEqualsCanonicalizing(['Maputo Província', 'Maputo Cidade'], array_column(app(InvestmentCorridorContext::class)->provinces('maputo'), 'name'));
|
||||
foreach (['nacala', 'limpopo'] as $key) {
|
||||
$choice = app(InvestmentOpportunityChoices::class)->resolve([['source' => 'opportunity:'.$this->record($key)->id]])[0];
|
||||
$this->assertSame(app(InvestmentCorridorContext::class)->provinces($key)[0]->id, $choice['territory']['id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_server_refuses_incompatible_location_in_draft_and_confirmation_preview(): void
|
||||
{
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA corridor guard','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$version=$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$gaza=app(InvestmentCorridorContext::class)->provinces('limpopo')[0]->id;
|
||||
$body=['version'=>$version,'selection'=>[],'opportunity_choices'=>[['source'=>'opportunity:'.$this->record('beira')->id,'corridor_key'=>'beira','territory'=>'territory:'.$gaza]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>1])->assertUnprocessable();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA corridor guard', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$gaza = app(InvestmentCorridorContext::class)->provinces('limpopo')[0]->id;
|
||||
$body = ['version' => $version, 'selection' => [], 'opportunity_choices' => [['source' => 'opportunity:'.$this->record('beira')->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$gaza]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 1])->assertUnprocessable();
|
||||
$this->getJson('/api/v1/investment/territory-options?type=district&corridor=beira&parent_id='.$gaza)->assertUnprocessable();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.revision',0);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.revision', 0);
|
||||
}
|
||||
|
||||
public function test_encrypted_draft_survives_refresh_and_reauthentication_without_committing_context(): void
|
||||
{
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA recovery','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$before=$this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$record=$this->record('beira');$province=app(InvestmentCorridorContext::class)->provinces('beira')[0]->id;
|
||||
$body=['version'=>$before['case']['version'],'selection'=>[],'declarations'=>['currency'=>'MZN'],'opportunity_choices'=>[['source'=>'opportunity:'.$record->id,'corridor_key'=>'beira','territory'=>'territory:'.$province]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>10])->assertOk();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>9])->assertConflict();
|
||||
$encrypted=DB::table('desk_cases')->where('id',$id)->value('payload');$this->assertStringNotContainsString($province,$encrypted);
|
||||
$this->flushSession();$this->actingAs($this->investor);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn(\Inertia\Testing\AssertableInertia $page)=>$page
|
||||
->where('draft.declarations.currency','MZN')->where('requestedChoices.0.territory.id',$province)->where('requestedChoices.0.corridor_key','beira'));
|
||||
$after=$this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$this->assertSame($before['context'],$after['context']);$this->assertSame($before['case']['version'],$after['case']['version']);
|
||||
$empty=[...$body,'opportunity_choices'=>[],'entry_sources'=>['opportunity:'.$record->id],'draft_sequence'=>11];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',$empty)->assertOk();
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$record->id)->assertOk()->assertInertia(fn(\Inertia\Testing\AssertableInertia $page)=>$page->has('requestedChoices',0));
|
||||
$new=$this->record('nacala');
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$new->id)->assertOk()->assertInertia(fn(\Inertia\Testing\AssertableInertia $page)=>$page->where('requestedChoices.0.opportunity.key','opportunity:'.$new->id));
|
||||
$this->actingAs(User::factory()->create());$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>12])->assertForbidden();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA recovery', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$before = $this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$record = $this->record('beira');
|
||||
$province = app(InvestmentCorridorContext::class)->provinces('beira')[0]->id;
|
||||
$body = ['version' => $before['case']['version'], 'selection' => [], 'declarations' => ['currency' => 'MZN'], 'opportunity_choices' => [['source' => 'opportunity:'.$record->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$province]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 10])->assertOk();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 9])->assertConflict();
|
||||
$encrypted = DB::table('desk_cases')->where('id', $id)->value('payload');
|
||||
$this->assertStringNotContainsString($province, $encrypted);
|
||||
$this->flushSession();
|
||||
$this->actingAs($this->investor);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('draft.declarations.currency', 'MZN')->where('requestedChoices.0.territory.id', $province)->where('requestedChoices.0.corridor_key', 'beira'));
|
||||
$after = $this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$this->assertSame($before['context'], $after['context']);
|
||||
$this->assertSame($before['case']['version'], $after['case']['version']);
|
||||
$empty = [...$body, 'opportunity_choices' => [], 'entry_sources' => ['opportunity:'.$record->id], 'draft_sequence' => 11];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', $empty)->assertOk();
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$record->id)->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->has('requestedChoices', 0));
|
||||
$new = $this->record('nacala');
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$new->id)->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->where('requestedChoices.0.opportunity.key', 'opportunity:'.$new->id));
|
||||
$this->actingAs(User::factory()->create());
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 12])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_zones_need_compatible_documented_territory_and_catalogue_presence_alone_is_insufficient(): void
|
||||
{
|
||||
$service=app(InvestmentCorridorContext::class);
|
||||
$sofala=collect($service->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$gaza=$service->provinces('limpopo')[0]->id;
|
||||
$base=app(\App\Services\InvestmentZones::class)->visible()->whereIn('category',['industrial_park','zee','zfi'])->firstOrFail();
|
||||
$clones=[];
|
||||
foreach([$sofala,$gaza,null] as $territory){$zone=$base->replicate();$zone->code='QA-'.Str::uuid();$zone->name='Synthetic corridor zone';$zone->primary_territory_id=$territory;$zone->save();$clones[]=$zone;}
|
||||
$available=array_column($service->parks('beira',$sofala),'id');
|
||||
$this->assertContains($clones[0]->id,$available);$this->assertNotContains($clones[1]->id,$available);$this->assertNotContains($clones[2]->id,$available);
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA zone guard','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$version=$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$body=['version'=>$version,'selection'=>['park'=>'park:'.$clones[1]->id],'opportunity_choices'=>[['source'=>'opportunity:'.$this->record('beira')->id,'corridor_key'=>'beira','territory'=>'territory:'.$sofala]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>1])->assertUnprocessable();
|
||||
$this->getJson('/investimentos/opcoes-corredor?corridor=beira&territory='.$sofala)->assertOk()->assertJsonFragment(['id'=>$clones[0]->id]);
|
||||
$service = app(InvestmentCorridorContext::class);
|
||||
$sofala = collect($service->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$gaza = $service->provinces('limpopo')[0]->id;
|
||||
$base = app(InvestmentZones::class)->visible()->whereIn('category', ['industrial_park', 'zee', 'zfi'])->firstOrFail();
|
||||
$clones = [];
|
||||
foreach ([$sofala, $gaza, null] as $territory) {
|
||||
$zone = $base->replicate();
|
||||
$zone->code = 'QA-'.Str::uuid();
|
||||
$zone->name = 'Synthetic corridor zone';
|
||||
$zone->primary_territory_id = $territory;
|
||||
$zone->save();
|
||||
$clones[] = $zone;
|
||||
}
|
||||
$available = array_column($service->parks('beira', $sofala), 'id');
|
||||
$this->assertContains($clones[0]->id, $available);
|
||||
$this->assertNotContains($clones[1]->id, $available);
|
||||
$this->assertNotContains($clones[2]->id, $available);
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA zone guard', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$body = ['version' => $version, 'selection' => ['park' => 'park:'.$clones[1]->id], 'opportunity_choices' => [['source' => 'opportunity:'.$this->record('beira')->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$sofala]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 1])->assertUnprocessable();
|
||||
$this->getJson('/investimentos/opcoes-corredor?corridor=beira&territory='.$sofala)->assertOk()->assertJsonFragment(['id' => $clones[0]->id]);
|
||||
}
|
||||
|
||||
public function test_corridor_change_keeps_compatible_paths_and_removes_only_incompatible_geography(): void
|
||||
{
|
||||
$service=app(InvestmentCorridorContext::class);$source='opportunity:'.$this->record('beira')->id;
|
||||
$sofala=collect($service->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$district=app(\App\Services\InvestmentGeography::class)->publicReferences()->where('parent_id',$sofala)->where('location_type','district')->firstOrFail();
|
||||
$resolver=app(InvestmentOpportunityChoices::class);
|
||||
$old=$resolver->resolve([['source'=>$source,'corridor_key'=>'beira','territory'=>'territory:'.$district->id]]);
|
||||
$same=$resolver->resolve([['source'=>$source,'corridor_key'=>'beira','territory'=>'territory:'.$district->id]],$old);
|
||||
$this->assertSame($old,$same);
|
||||
$changed=$resolver->resolve([['source'=>$source,'corridor_key'=>'limpopo']],$old);
|
||||
$this->assertSame($service->provinces('limpopo')[0]->id,$changed[0]['territory']['id']);
|
||||
$this->assertCount(1,$changed[0]['territory_path']);
|
||||
$service = app(InvestmentCorridorContext::class);
|
||||
$source = 'opportunity:'.$this->record('beira')->id;
|
||||
$sofala = collect($service->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$district = app(InvestmentGeography::class)->publicReferences()->where('parent_id', $sofala)->where('location_type', 'district')->firstOrFail();
|
||||
$resolver = app(InvestmentOpportunityChoices::class);
|
||||
$old = $resolver->resolve([['source' => $source, 'corridor_key' => 'beira', 'territory' => 'territory:'.$district->id]]);
|
||||
$same = $resolver->resolve([['source' => $source, 'corridor_key' => 'beira', 'territory' => 'territory:'.$district->id]], $old);
|
||||
$this->assertSame($old, $same);
|
||||
$changed = $resolver->resolve([['source' => $source, 'corridor_key' => 'limpopo']], $old);
|
||||
$this->assertSame($service->provinces('limpopo')[0]->id, $changed[0]['territory']['id']);
|
||||
$this->assertCount(1, $changed[0]['territory_path']);
|
||||
$this->assertNull($this->record('beira')->primary_territory_id);
|
||||
$this->getJson('/api/v1/investment/territory-options?type=locality')->assertOk()->assertJsonPath('data',[]);
|
||||
config(['investment_corridors.nacala.provinces'=>['03','99']]);
|
||||
$this->getJson('/api/v1/investment/territory-options?type=locality')->assertOk()->assertJsonPath('data', []);
|
||||
config(['investment_corridors.nacala.provinces' => ['03', '99']]);
|
||||
$this->getJson('/api/v1/investment/territory-options?type=province&corridor=nacala')->assertStatus(503);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,19 @@ namespace Tests\Feature;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestorContext;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\VirtualDesk;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $investor;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -25,7 +28,8 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->withoutVite();
|
||||
$this->investor = User::factory()->create(); $this->actingAs($this->investor);
|
||||
$this->investor = User::factory()->create();
|
||||
$this->actingAs($this->investor);
|
||||
}
|
||||
|
||||
private function dossier(): string
|
||||
@@ -39,7 +43,7 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$id = $this->dossier();
|
||||
$before = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json('context');
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$record->id)->assertOk()
|
||||
->assertInertia(fn (\Inertia\Testing\AssertableInertia $page) => $page->component('investor-path/context')
|
||||
->assertInertia(fn (AssertableInertia $page) => $page->component('investor-path/context')
|
||||
->where('source.key', 'opportunity:'.$record->id)
|
||||
->where('requestedChoices.0.opportunity.key', 'opportunity:'.$record->id)
|
||||
->where('requestedChoices.0.opportunity.title', $record->title));
|
||||
@@ -51,7 +55,7 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
{
|
||||
$entries = array_slice(app(CorridorAgribusinessOpportunities::class)->entries(), 0, 2);
|
||||
$records = Opportunity::whereIn('management_creation_key', array_column($entries, 'key'))->orderBy('id')->get();
|
||||
$sites = collect(app(\App\Services\InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$sites = collect(app(InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$this->get('/investimentos/iniciar?opportunities[]='.$records[0]->id.'&opportunities[]='.$records[1]->id)->assertOk();
|
||||
$id = $this->dossier();
|
||||
$before = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
@@ -76,12 +80,18 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertCount(2, $after['context']['opportunity_choices']);
|
||||
$snapshot = json_decode($after['prefill']['simulator']['context_applicability_snapshot'], true);
|
||||
$this->assertSame($after['context']['opportunity_choices'], $snapshot['opportunity_choices']);
|
||||
$this->assertSame('general', $snapshot['fields']['investment_regime']);
|
||||
// Multiple unselected opportunities must not supply a regime to the consumer.
|
||||
$this->assertArrayNotHasKey('investment_regime', $snapshot['fields']);
|
||||
foreach ($after['context']['opportunity_choices'] as $choice) {
|
||||
$this->getJson('/investimentos/'.$id.'/contexto?opportunity='.$choice['opportunity']['key'])->assertOk()->assertJsonPath('prefill.simulator.investment_regime', 'general');
|
||||
}
|
||||
$this->assertArrayNotHasKey('tax_benefit', $snapshot['fields']);
|
||||
$this->get('/investimentos/'.$id)->assertOk();
|
||||
|
||||
$desk = app(VirtualDesk::class); $case = $desk->case($this->investor, $id);
|
||||
$payload = $desk->decode($case->payload); $resultId = (string) Str::uuid();
|
||||
$desk = app(VirtualDesk::class);
|
||||
$case = $desk->case($this->investor, $id);
|
||||
$payload = $desk->decode($case->payload);
|
||||
$resultId = (string) Str::uuid();
|
||||
$payload['investor_path']['results'] = [['id' => $resultId, 'engine' => 'synthetic-qa-history', 'context_state' => 'current', 'value' => 'preserve']];
|
||||
DB::table('desk_cases')->where('id', $id)->update(['payload' => $desk->encode($payload)]);
|
||||
$next = ['version' => $after['case']['version'], 'selection' => [], 'opportunity_choices' => [
|
||||
@@ -98,9 +108,11 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
public function test_documented_location_cannot_change_silently_and_stale_source_cannot_be_confirmed(): void
|
||||
{
|
||||
$record = Opportunity::where('management_creation_key', app(CorridorAgribusinessOpportunities::class)->entries()[0]['key'])->firstOrFail();
|
||||
$sites = collect(app(\App\Services\InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$record->primary_territory_id = $sites[0]; $record->save();
|
||||
$id = $this->dossier(); $version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$sites = collect(app(InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$record->primary_territory_id = $sites[0];
|
||||
$record->save();
|
||||
$id = $this->dossier();
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$input = ['version' => $version, 'selection' => [], 'opportunity_choices' => [['source' => 'opportunity:'.$record->id, 'territory' => 'territory:'.$sites[1]]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', $input)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', ['version' => $version, 'selection' => ['opportunity' => 'opportunity:'.$record->id, 'territory' => 'territory:'.$sites[1]]])->assertUnprocessable();
|
||||
@@ -112,7 +124,8 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$input['version'] = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
unset($input['opportunity_choices'][0]['confirm_location_change']);
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', $input)->assertOk()->assertJsonPath('dependency_changed', false)->json();
|
||||
$record->title .= ' QA source changed'; $record->save();
|
||||
$record->title .= ' QA source changed';
|
||||
$record->save();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$input, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertConflict();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.revision', 1);
|
||||
}
|
||||
@@ -132,11 +145,15 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertLessThan(1000000, strlen($snapshot));
|
||||
// Mirror the existing browser partition: labels are persisted under selection_labels.
|
||||
$economic = [...$view['prefill']['simulator'], 'purpose' => 'simulate_only', 'currency' => 'MZN'];
|
||||
foreach (array_keys($economic) as $field) if (str_ends_with($field, '_label')) {
|
||||
$economic['selection_labels'][substr($field, 0, -6)] = $economic[$field]; unset($economic[$field]);
|
||||
foreach (array_keys($economic) as $field) {
|
||||
if (str_ends_with($field, '_label')) {
|
||||
$economic['selection_labels'][substr($field, 0, -6)] = $economic[$field];
|
||||
unset($economic[$field]);
|
||||
}
|
||||
}
|
||||
$draft = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => [],
|
||||
'economic_snapshot' => $economic], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json();
|
||||
$personalKeys = ['email', 'phone', 'person_type', 'investor_origin', 'tax_residency_country', 'fiscal_residency_country', 'entity_stage'];
|
||||
$draft = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => Arr::only($economic, $personalKeys),
|
||||
'economic_snapshot' => Arr::except($economic, $personalKeys)], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json();
|
||||
$this->assertNotEmpty($draft);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.opportunity_choices.33.opportunity.key', 'opportunity:'.$records[33]->id);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,19 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Http\Controllers\InvestmentPortfolioController;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\SimulationFormDraft;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\InvestmentOpportunityChoices;
|
||||
use App\Services\SimulationFormDrafts;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestmentPortfolioContinuityTest extends TestCase
|
||||
@@ -20,18 +25,24 @@ final class InvestmentPortfolioContinuityTest extends TestCase
|
||||
|
||||
public function test_draft_version_guard_still_rejects_a_real_stale_version(): void
|
||||
{
|
||||
$draft = new \App\Models\SimulationFormDraft;
|
||||
$draft->forceFill(['id'=>(string)Str::uuid(),'version_no'=>2]);
|
||||
$service=app(\App\Services\SimulationFormDrafts::class);
|
||||
$guard=new \ReflectionMethod($service,'requireMatch');
|
||||
$tag=$service->etag($draft);
|
||||
foreach (['W/'.$tag, str_replace('-v2','-v1',$tag)] as $invalid) {
|
||||
$request=\Illuminate\Http\Request::create('/','PUT'); $request->headers->set('If-Match',$invalid);
|
||||
try { $guard->invoke($service,$request,$draft); $this->fail('A mismatching version must be rejected'); }
|
||||
catch (\Symfony\Component\HttpKernel\Exception\HttpException $error) { $this->assertSame(412,$error->getStatusCode()); }
|
||||
$draft = new SimulationFormDraft;
|
||||
$draft->forceFill(['id' => (string) Str::uuid(), 'version_no' => 2]);
|
||||
$service = app(SimulationFormDrafts::class);
|
||||
$guard = new \ReflectionMethod($service, 'requireMatch');
|
||||
$tag = $service->etag($draft);
|
||||
foreach (['W/'.$tag, str_replace('-v2', '-v1', $tag)] as $invalid) {
|
||||
$request = Request::create('/', 'PUT');
|
||||
$request->headers->set('If-Match', $invalid);
|
||||
try {
|
||||
$guard->invoke($service, $request, $draft);
|
||||
$this->fail('A mismatching version must be rejected');
|
||||
} catch (HttpException $error) {
|
||||
$this->assertSame(412, $error->getStatusCode());
|
||||
}
|
||||
}
|
||||
$request=\Illuminate\Http\Request::create('/','PUT'); $request->headers->set('If-Match',$tag);
|
||||
$this->assertNull($guard->invoke($service,$request,$draft));
|
||||
$request = Request::create('/', 'PUT');
|
||||
$request->headers->set('If-Match', $tag);
|
||||
$this->assertNull($guard->invoke($service, $request, $draft));
|
||||
}
|
||||
|
||||
public function test_beira_documentary_membership_opens_the_same_published_opportunities_without_inferring_by_province(): void
|
||||
@@ -40,91 +51,107 @@ final class InvestmentPortfolioContinuityTest extends TestCase
|
||||
$service = app(CorridorAgribusinessOpportunities::class);
|
||||
$ids = $service->portfolioOpportunityIds($portfolio);
|
||||
$this->assertCount(7, $ids);
|
||||
$this->get('/carteira/'.$portfolio->id)->assertOk()->assertInertia(fn(Assert $page) => $page->has('opportunities', 7));
|
||||
$catalogueIds=app(\App\Services\InvestmentCatalogue::class)->query(['corridor_id'=>$portfolio->corridor_id])->pluck('opportunities.id')->all();
|
||||
$this->assertSame([], array_values(array_diff($ids,$catalogueIds)));
|
||||
$opportunity=Opportunity::findOrFail($ids[0]);
|
||||
$this->get('/carteira/'.$portfolio->id)->assertOk()->assertInertia(fn (Assert $page) => $page->has('opportunities', 7));
|
||||
$catalogueIds = app(InvestmentCatalogue::class)->query(['corridor_id' => $portfolio->corridor_id])->pluck('opportunities.id')->all();
|
||||
$this->assertSame([], array_values(array_diff($ids, $catalogueIds)));
|
||||
$opportunity = Opportunity::findOrFail($ids[0]);
|
||||
$this->get('/oportunidades/'.$opportunity->slug.'?from_dossier='.$portfolio->id)->assertOk();
|
||||
$origins=app(InvestmentOpportunityChoices::class)->portfolioOrigins([$portfolio->id],$opportunity->id);
|
||||
$this->assertSame($portfolio->id,$origins[0]['id']);
|
||||
$this->assertSame('corridor',$origins[0]['kind']);
|
||||
$other=Opportunity::published()->whereNotIn('id',$ids)->firstOrFail();
|
||||
$origins = app(InvestmentOpportunityChoices::class)->portfolioOrigins([$portfolio->id], $opportunity->id);
|
||||
$this->assertSame($portfolio->id, $origins[0]['id']);
|
||||
$this->assertSame('corridor', $origins[0]['kind']);
|
||||
$other = Opportunity::published()->whereNotIn('id', $ids)->firstOrFail();
|
||||
$this->get('/oportunidades/'.$other->slug.'?from_dossier='.$portfolio->id)->assertNotFound();
|
||||
$this->assertSame([], $service->portfolioOpportunityIds(InvestmentPortfolioController::visible()->whereNotNull('project_id')->firstOrFail()));
|
||||
}
|
||||
|
||||
private User $actor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); $this->withoutVite();
|
||||
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name); $this->assertSame(55441,(int)$db->port);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false,'investmoz_ai.enabled'=>false]);
|
||||
$this->actor=User::factory()->create(); $this->actingAs($this->actor);
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
||||
$this->assertSame(55441, (int) $db->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->actor = User::factory()->create();
|
||||
$this->actingAs($this->actor);
|
||||
}
|
||||
|
||||
private function records(): array
|
||||
{
|
||||
$entries=collect(app(CorridorAgribusinessOpportunities::class)->entries())->where('corridor',config('investment_corridors.beira.name'))->take(2);
|
||||
$opportunities=Opportunity::whereIn('management_creation_key',$entries->pluck('key'))->orderBy('id')->get();
|
||||
$project=InvestmentPortfolioController::visible()->whereNotNull('project_id')->firstOrFail();
|
||||
$cluster=InvestmentPortfolioController::visible()->whereNotNull('cluster_id')->firstOrFail();
|
||||
foreach($opportunities as $opportunity) {
|
||||
$entries = collect(app(CorridorAgribusinessOpportunities::class)->entries())->where('corridor', config('investment_corridors.beira.name'))->take(2);
|
||||
$opportunities = Opportunity::whereIn('management_creation_key', $entries->pluck('key'))->orderBy('id')->get();
|
||||
$project = InvestmentPortfolioController::visible()->whereNotNull('project_id')->firstOrFail();
|
||||
$cluster = InvestmentPortfolioController::visible()->whereNotNull('cluster_id')->firstOrFail();
|
||||
foreach ($opportunities as $opportunity) {
|
||||
// Synthetic links exist only inside this rolled-back QA transaction.
|
||||
DB::table('opportunity_projects')->insertOrIgnore(['opportunity_id'=>$opportunity->id,'project_id'=>$project->project_id]);
|
||||
DB::table('opportunity_clusters')->insertOrIgnore(['opportunity_id'=>$opportunity->id,'cluster_id'=>$cluster->cluster_id]);
|
||||
DB::table('opportunity_projects')->insertOrIgnore(['opportunity_id' => $opportunity->id, 'project_id' => $project->project_id]);
|
||||
DB::table('opportunity_clusters')->insertOrIgnore(['opportunity_id' => $opportunity->id, 'cluster_id' => $cluster->cluster_id]);
|
||||
}
|
||||
return [$opportunities,$project,$cluster];
|
||||
|
||||
return [$opportunities, $project, $cluster];
|
||||
}
|
||||
|
||||
public function test_origin_and_location_survive_entry_draft_confirmation_and_simulator_without_resetting_deliberate_values(): void
|
||||
{
|
||||
[$records,$origin,$cluster]=$this->records(); $opportunity=$records[0];
|
||||
$province=collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$query='?source=opportunity:'.$opportunity->id.'&from_dossier='.$origin->id.'&province_id='.$province;
|
||||
[$records,$origin,$cluster] = $this->records();
|
||||
$opportunity = $records[0];
|
||||
$province = collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$query = '?source=opportunity:'.$opportunity->id.'&from_dossier='.$origin->id.'&province_id='.$province;
|
||||
auth()->logout();
|
||||
$this->get('/investimentos/iniciar'.$query)->assertRedirect(route('login'));
|
||||
parse_str(parse_url(session('url.intended'),PHP_URL_QUERY),$intended);
|
||||
$this->assertSame($origin->id,$intended['from_dossier']);$this->assertSame($province,$intended['province_id']);
|
||||
parse_str(parse_url(session('url.intended'), PHP_URL_QUERY), $intended);
|
||||
$this->assertSame($origin->id, $intended['from_dossier']);
|
||||
$this->assertSame($province, $intended['province_id']);
|
||||
$this->actingAs($this->actor);
|
||||
$this->get('/investimentos/iniciar'.$query)->assertOk()->assertInertia(fn(Assert $p)=>$p->where('opportunityChoices.0.portfolio_origins.0.id',$origin->id)->where('opportunityChoices.0.territory.id',$province)->where('entryQuery.from_dossier',$origin->id));
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA título deliberado','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$body=['version'=>$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'),'selection'=>[],'opportunity_choices'=>[
|
||||
['source'=>'opportunity:'.$opportunity->id,'territory'=>'territory:'.$province,'portfolio_origins'=>[$origin->id],'activities'=>['trade']],
|
||||
['source'=>'opportunity:'.$records[1]->id,'territory'=>'territory:'.$province,'portfolio_origins'=>[$origin->id,$cluster->id]],
|
||||
$this->get('/investimentos/iniciar'.$query)->assertOk()->assertInertia(fn (Assert $p) => $p->where('opportunityChoices.0.portfolio_origins.0.id', $origin->id)->where('opportunityChoices.0.territory.id', $province)->where('entryQuery.from_dossier', $origin->id));
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA título deliberado', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$body = ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => [], 'opportunity_choices' => [
|
||||
['source' => 'opportunity:'.$opportunity->id, 'territory' => 'territory:'.$province, 'portfolio_origins' => [$origin->id], 'activities' => ['trade']],
|
||||
['source' => 'opportunity:'.$records[1]->id, 'territory' => 'territory:'.$province, 'portfolio_origins' => [$origin->id, $cluster->id]],
|
||||
]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>1])->assertOk();
|
||||
$this->flushSession();$this->actingAs($this->actor);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn(Assert $p)=>$p->where('requestedChoices.0.portfolio_origins.0.id',$origin->id)->where('requestedChoices.0.territory.id',$province));
|
||||
$preview=$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->assertGreaterThan(0,$preview['opportunity_choices'][0]['portfolio_origins'][0]['version']);
|
||||
$this->assertSame('QA título deliberado',$preview['fields']['project_title']);
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar',[...$body,'preview_hash'=>$preview['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$view=$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($view['context']['opportunity_choices'],json_decode($view['prefill']['simulator']['context_applicability_snapshot'],true)['opportunity_choices']);
|
||||
$this->assertSame($province,$view['prefill']['simulator']['province_id']);
|
||||
$this->assertSame('QA título deliberado',$view['prefill']['simulator']['project_title']);
|
||||
$created=$this->postJson('/api/v1/simulation-drafts',['context'=>$id,'personal_snapshot'=>[],'economic_snapshot'=>['purpose'=>'simulate_only','project_title'=>'QA edição deliberada no simulador','context_applicability_snapshot'=>$view['prefill']['simulator']['context_applicability_snapshot']]],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated();
|
||||
$this->flushSession();$this->actingAs($this->actor);
|
||||
$simulation=$this->getJson('/api/v1/simulation-drafts/'.$created->json('data.id').'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.project_title','QA edição deliberada no simulador')->json('data.economic_snapshot');
|
||||
$this->assertSame($view['context']['opportunity_choices'],json_decode($simulation['context_applicability_snapshot'],true)['opportunity_choices']);
|
||||
$manica=collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code','06')->id;
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 1])->assertOk();
|
||||
$this->flushSession();
|
||||
$this->actingAs($this->actor);
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar')->assertOk()->assertInertia(fn (Assert $p) => $p->where('requestedChoices.0.portfolio_origins.0.id', $origin->id)->where('requestedChoices.0.territory.id', $province));
|
||||
$preview = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->assertGreaterThan(0, $preview['opportunity_choices'][0]['portfolio_origins'][0]['version']);
|
||||
$this->assertSame('QA título deliberado', $preview['fields']['project_title']);
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$body, 'preview_hash' => $preview['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
$view = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($view['context']['opportunity_choices'], json_decode($view['prefill']['simulator']['context_applicability_snapshot'], true)['opportunity_choices']);
|
||||
$this->assertArrayNotHasKey('province_id', $view['prefill']['simulator']);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto?opportunity=opportunity:'.$opportunity->id)->assertOk()->assertJsonPath('prefill.simulator.province_id', $province);
|
||||
$this->assertSame('QA título deliberado', $view['prefill']['simulator']['project_title']);
|
||||
$created = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'project_title' => 'QA edição deliberada no simulador', 'context_applicability_snapshot' => $view['prefill']['simulator']['context_applicability_snapshot']]], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->flushSession();
|
||||
$this->actingAs($this->actor);
|
||||
$simulation = $this->getJson('/api/v1/simulation-drafts/'.$created->json('data.id').'?context='.$id)->assertOk()->assertJsonPath('data.economic_snapshot.project_title', 'QA edição deliberada no simulador')->json('data.economic_snapshot');
|
||||
$this->assertSame($view['context']['opportunity_choices'], json_decode($simulation['context_applicability_snapshot'], true)['opportunity_choices']);
|
||||
$manica = collect(app(InvestmentCorridorContext::class)->provinces('beira'))->firstWhere('source_code', '06')->id;
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$opportunity->id.'&from_dossier='.$cluster->id.'&province_id='.$manica)
|
||||
->assertOk()->assertInertia(fn(Assert $p)=>$p->where('requestedChoices.0.territory.id',$province)->where('requestedChoices.0.activities.0','trade')->has('requestedChoices',2)->has('requestedChoices.0.portfolio_origins',2)->has('entryLocationDifferences',1));
|
||||
$body['version']=$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$body['opportunity_choices'][0]['portfolio_origins'][]=$cluster->id;
|
||||
$associations=$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->assertFalse($associations['calculation_inputs_changed']);$this->assertSame([],$associations['review_steps']);
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar',[...$body,'preview_hash'=>$associations['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.dependency_hash',$view['context']['dependency_hash'])->assertJsonCount(2,'context.opportunity_choices.0.portfolio_origins');
|
||||
->assertOk()->assertInertia(fn (Assert $p) => $p->where('requestedChoices.0.territory.id', $province)->where('requestedChoices.0.activities.0', 'trade')->has('requestedChoices', 2)->has('requestedChoices.0.portfolio_origins', 2)->has('entryLocationDifferences', 1));
|
||||
$body['version'] = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$body['opportunity_choices'][0]['portfolio_origins'][] = $cluster->id;
|
||||
$associations = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->assertFalse($associations['calculation_inputs_changed']);
|
||||
$this->assertSame([], $associations['review_steps']);
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$body, 'preview_hash' => $associations['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.dependency_hash', $view['context']['dependency_hash'])->assertJsonCount(2, 'context.opportunity_choices.0.portfolio_origins');
|
||||
}
|
||||
|
||||
public function test_unrelated_or_private_origins_are_rejected_in_entry_draft_and_preview(): void
|
||||
{
|
||||
[$records,$origin]=$this->records();
|
||||
DB::table('opportunity_projects')->where('opportunity_id',$records[0]->id)->where('project_id',$origin->project_id)->delete();
|
||||
[$records,$origin] = $this->records();
|
||||
DB::table('opportunity_projects')->where('opportunity_id', $records[0]->id)->where('project_id', $origin->project_id)->delete();
|
||||
$this->get('/investimentos/iniciar?source=opportunity:'.$records[0]->id.'&from_dossier='.$origin->id)->assertUnprocessable();
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA origem inválida','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->json('id');
|
||||
$body=['version'=>$this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'),'selection'=>[],'opportunity_choices'=>[['source'=>'opportunity:'.$records[0]->id,'portfolio_origins'=>[$origin->id]]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho',[...$body,'draft_sequence'=>1])->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertUnprocessable();
|
||||
$origin->publication_status='draft';$origin->save();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA origem inválida', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->json('id');
|
||||
$body = ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => [], 'opportunity_choices' => [['source' => 'opportunity:'.$records[0]->id, 'portfolio_origins' => [$origin->id]]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/rascunho', [...$body, 'draft_sequence' => 1])->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertUnprocessable();
|
||||
$origin->publication_status = 'draft';
|
||||
$origin->save();
|
||||
$this->get('/investimentos/iniciar?source=opportunity:'.$records[1]->id.'&from_dossier='.$origin->id)->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentPortfolioTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_document_import_is_idempotent_preserves_edits_and_links_all_anchors(): void
|
||||
@@ -44,7 +46,7 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$dossier = InvestmentDossier::firstOrFail();
|
||||
$url = '/management/portfolio/'.$dossier->id;
|
||||
$payload = ['version_no' => $dossier->version_no, 'title' => 'Revisao mais recente', 'source' => $dossier->source, 'content' => $dossier->content];
|
||||
$this->actingAs($manager)->put($url, $payload)->assertRedirect()->assertSessionHasNoErrors();
|
||||
$this->actingAsWithMfa($manager)->put($url, $payload)->assertRedirect()->assertSessionHasNoErrors();
|
||||
$this->putJson($url, [...$payload, 'title' => 'Alteracao obsoleta'])->assertStatus(409);
|
||||
$approval = ['version_no' => $dossier->version_no, 'approval_evidence' => 'Aprovacao sintetica da versao revista'];
|
||||
$this->postJson($url.'/publish', $approval)->assertStatus(409);
|
||||
@@ -101,7 +103,7 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$dossier = InvestmentDossier::firstOrFail();
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->post('/management/portfolio/'.$dossier->id.'/publish', [
|
||||
$this->actingAsWithMfa($manager)->post('/management/portfolio/'.$dossier->id.'/publish', [
|
||||
'version_no' => $dossier->version_no, 'approval_evidence' => 'Synthetic owner approval is not an editor assignment',
|
||||
])->assertStatus(422);
|
||||
$this->get('/carteira/'.$dossier->id)->assertNotFound();
|
||||
@@ -157,6 +159,7 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$this->assertSame($journey->investor_id, $lead->investor_id);
|
||||
$this->assertDatabaseCount('investors', 1);
|
||||
config(['portal.managers' => [$owner->email]]);
|
||||
$this->actingAsWithMfa($owner);
|
||||
$this->get('/management/interests?origin=PT')->assertInertia(fn (Assert $page) => $page
|
||||
->where('requests.total', 1)->where('requests.data.0.declaredOrigin.code', 'PT')
|
||||
->where('originStatistics.interests.0.code', 'PT')->where('originStatistics.interests.0.count', 1));
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\OpportunityClassification;
|
||||
use App\Services\OpportunityManagement;
|
||||
use Database\Seeders\InvestmentAreaSeeder;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -17,10 +18,12 @@ use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_confirmed_coordinates_create_a_marker_without_hiding_missing_records(): void
|
||||
@@ -33,7 +36,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->get('/oportunidades')->assertInertia(fn (AssertableInertia $page) => $page->where('results.total', 1)->where('results.data.0.id', $record->id));
|
||||
$this->getJson('/api/v1/investment/map')->assertOk()->assertJsonPath('matched_count', 1)
|
||||
->assertJsonPath('georeferenced_count', 0)->assertJsonPath('complete', false)->assertJsonCount(1, 'unlocated');
|
||||
$this->actingAs($manager);
|
||||
$this->actingAsWithMfa($manager);
|
||||
$url = '/management/opportunities/'.$record->id.'/coordinates';
|
||||
$payload = ['version' => 0, 'latitude' => -25.9, 'longitude' => 32.5, 'source_reference' => 'Synthetic coordinates for automated tests only', 'confirmed_site' => true];
|
||||
$this->postJson($url, [...$payload, 'latitude' => 91])->assertUnprocessable();
|
||||
@@ -73,13 +76,15 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->getJson('/oportunidades?province_id='.$private)->assertUnprocessable();
|
||||
$this->get('/oportunidades?province_id='.$province)->assertOk();
|
||||
$this->assertCount(2, $service->context($opportunity->id)['primary_territory_path']);
|
||||
$this->assertEqualsCanonicalizing([$country, $province, $district, $other], app(OpportunityClassification::class)->targets('location')->pluck('id')->all());
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$created = $this->actingAs($manager)->postJson('/management/opportunities/drafts', ['sector_id' => $sector->id, 'creation_key' => (string) Str::uuid(), 'reason' => 'Cadastro territorial de rascunho apenas em QA', 'title' => 'Synthetic create',
|
||||
$created = $this->actingAsWithMfa($manager)->postJson('/management/opportunities/drafts', ['sector_id' => $sector->id, 'creation_key' => (string) Str::uuid(), 'reason' => 'Cadastro territorial de rascunho apenas em QA', 'title' => 'Synthetic create',
|
||||
'estimated_investment_currency' => 'USD', 'province_id' => $province, 'district_id' => $district])->assertCreated()->json();
|
||||
$this->assertDatabaseHas('opportunities', ['id' => $created['id'], 'primary_territory_id' => $district]);
|
||||
$this->post('/management/clusters', ['code' => 'GEO-CREATE', 'name' => 'Synthetic cluster', 'sector' => 'Synthetic', 'status' => 'planned', 'province_id' => $province, 'district_id' => $district])->assertRedirect();
|
||||
$this->assertDatabaseHas('economic_clusters', ['code' => 'GEO-CREATE', 'primary_territory_id' => $district]);
|
||||
$this->actingAsWithMfa($manager);
|
||||
$manager->forceFill(['two_factor_secret' => Crypt::encryptString('SYNTHETIC'), 'two_factor_confirmed_at' => now()])->save();
|
||||
$zone = $this->postJson('/api/v2/investment/admin/zones', ['code' => 'GEO-ZEE', 'name' => 'Synthetic ZEE', 'category' => 'zee', 'province_id' => $province, 'district_id' => $district])->assertCreated()->json('id');
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $zone, 'primary_territory_id' => $district]);
|
||||
@@ -250,6 +255,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$this->actingAs($user);
|
||||
$province = $this->location('province');
|
||||
$other = $this->location('province');
|
||||
@@ -284,9 +290,9 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$province = $this->location('province', $country);
|
||||
$sector = Sector::create(['name' => 'Synthetic edit', 'slug' => 'synthetic-edit', 'is_active' => true]);
|
||||
$record = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Synthetic edit', 'status' => 'draft']);
|
||||
$this->actingAs($manager)->putJson('/management/opportunities/'.$record->id.'/draft', [
|
||||
$this->actingAsWithMfa($manager)->putJson('/management/opportunities/'.$record->id.'/draft', [
|
||||
'sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Synthetic edit',
|
||||
'status' => 'draft', 'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'province_id' => $province, 'territory_version' => 0,
|
||||
'etag' => app(OpportunityManagement::class)->etag($record->fresh()), 'reason' => 'Atualização territorial do rascunho em QA',
|
||||
])->assertOk();
|
||||
@@ -299,7 +305,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$other = $this->location('province', $country);
|
||||
$district = $this->location('district', $other);
|
||||
$payload = ['sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Must not persist',
|
||||
'status' => 'draft', 'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'province_id' => $province, 'district_id' => $district, 'territory_version' => 1];
|
||||
$etag = app(OpportunityManagement::class)->etag($record->fresh());
|
||||
$this->putJson('/management/opportunities/'.$record->id.'/draft', [...$payload, 'etag' => $etag, 'reason' => 'Validação de hierarquia no rascunho QA'])->assertUnprocessable()->assertJsonValidationErrors('district_id');
|
||||
@@ -350,7 +356,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->from('/management/opportunities/create')
|
||||
$this->actingAsWithMfa($manager)->from('/management/opportunities/create')
|
||||
->post('/management/opportunities', [])->assertSessionHasErrors('status');
|
||||
$this->withCookie(config('session.cookie'), session()->getId())->withCredentials();
|
||||
$this->getJson('/management/territory-options?type=province')->assertOk()->assertSessionHasErrors('status');
|
||||
|
||||
@@ -4,8 +4,13 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\{CorridorAgribusinessOpportunities, InvestmentCorridorContext, InvestmentConsumerScope, InvestorContext, InvestmentZones, VirtualDesk};
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\InvestmentZones;
|
||||
use App\Services\VirtualDesk;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
@@ -13,40 +18,56 @@ use Tests\TestCase;
|
||||
final class InvestmentTreatmentScopeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $actor;
|
||||
|
||||
private string $id;
|
||||
|
||||
private array $choices;
|
||||
|
||||
private array $parks;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();$this->withoutVite();
|
||||
$this->withoutMiddleware(\Illuminate\Routing\Middleware\ThrottleRequests::class);
|
||||
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name);$this->assertSame(55441,(int)$db->port);
|
||||
config(['investor-path.enabled'=>true,'investor-path.private_preparation'=>true,'suitecrm.enabled'=>false,'investmoz_ai.enabled'=>false]);
|
||||
$this->actor=User::factory()->create();$this->actingAs($this->actor);
|
||||
$this->id=$this->postJson('/investimentos',['title'=>'SYNTHETIC QA — âmbito específico','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$corridors=app(InvestmentCorridorContext::class);
|
||||
$records=[];foreach(['beira','limpopo'] as $corridor){
|
||||
$entry=collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor',config('investment_corridors.'.$corridor.'.name'));
|
||||
$records[]=Opportunity::where('management_creation_key',$entry['key'])->firstOrFail();
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$this->withoutMiddleware(ThrottleRequests::class);
|
||||
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
||||
$this->assertSame(55441, (int) $db->port);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->actor = User::factory()->create();
|
||||
$this->actingAs($this->actor);
|
||||
$this->id = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA — âmbito específico', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$corridors = app(InvestmentCorridorContext::class);
|
||||
$records = [];
|
||||
foreach (['beira', 'limpopo'] as $corridor) {
|
||||
$entry = collect(app(CorridorAgribusinessOpportunities::class)->entries())->firstWhere('corridor', config('investment_corridors.'.$corridor.'.name'));
|
||||
$records[] = Opportunity::where('management_creation_key', $entry['key'])->firstOrFail();
|
||||
}
|
||||
$sofala=collect($corridors->provinces('beira'))->firstWhere('source_code','07')->id;
|
||||
$gaza=$corridors->provinces('limpopo')[0]->id;
|
||||
$manica=collect($corridors->provinces('beira'))->firstWhere('name','Manica')->id;
|
||||
$template=app(InvestmentZones::class)->visible()->whereIn('category',['industrial_park','zee','zfi'])->firstOrFail();
|
||||
foreach([$sofala,$gaza,$manica] as $territory){$p=$template->replicate();$p->code='SYNTHETIC-QA-'.Str::uuid();$p->name='SYNTHETIC QA — parque '.$territory;$p->primary_territory_id=$territory;$p->save();$this->parks[]=$p;}
|
||||
$this->choices=[['source'=>'opportunity:'.$records[0]->id,'corridor_key'=>'beira','territory'=>'territory:'.$sofala,'park'=>'park:'.$this->parks[0]->id,'activities'=>['production']],['source'=>'opportunity:'.$records[1]->id,'corridor_key'=>'limpopo','territory'=>'territory:'.$gaza,'park'=>'park:'.$this->parks[1]->id,'activities'=>['trade']]];
|
||||
$sofala = collect($corridors->provinces('beira'))->firstWhere('source_code', '07')->id;
|
||||
$gaza = $corridors->provinces('limpopo')[0]->id;
|
||||
$manica = collect($corridors->provinces('beira'))->firstWhere('name', 'Manica')->id;
|
||||
$template = app(InvestmentZones::class)->visible()->whereIn('category', ['industrial_park', 'zee', 'zfi'])->firstOrFail();
|
||||
foreach ([$sofala, $gaza, $manica] as $territory) {
|
||||
$p = $template->replicate();
|
||||
$p->code = 'SYNTHETIC-QA-'.Str::uuid();
|
||||
$p->name = 'SYNTHETIC QA — parque '.$territory;
|
||||
$p->primary_territory_id = $territory;
|
||||
$p->save();
|
||||
$this->parks[] = $p;
|
||||
}
|
||||
$this->choices = [['source' => 'opportunity:'.$records[0]->id, 'corridor_key' => 'beira', 'territory' => 'territory:'.$sofala, 'park' => 'park:'.$this->parks[0]->id, 'activities' => ['production']], ['source' => 'opportunity:'.$records[1]->id, 'corridor_key' => 'limpopo', 'territory' => 'territory:'.$gaza, 'park' => 'park:'.$this->parks[1]->id, 'activities' => ['trade']]];
|
||||
$this->confirm();
|
||||
}
|
||||
|
||||
private function confirm(): array
|
||||
{
|
||||
$v=$this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$body=['version'=>$v['case']['version'],'selection'=>[],'opportunity_choices'=>$this->choices];
|
||||
$plan=$this->postJson('/investimentos/'.$this->id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar',[...$body,'preview_hash'=>$plan['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$v = $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$body = ['version' => $v['case']['version'], 'selection' => [], 'opportunity_choices' => $this->choices];
|
||||
$plan = $this->postJson('/investimentos/'.$this->id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar', [...$body, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
|
||||
return $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
}
|
||||
|
||||
@@ -57,113 +78,126 @@ final class InvestmentTreatmentScopeTest extends TestCase
|
||||
|
||||
public function test_opportunity_decisions_steps_and_simulator_are_isolated_from_common_dossier(): void
|
||||
{
|
||||
$keys=array_column($this->choices,'source');
|
||||
foreach ($keys as $index=>$key) {
|
||||
$v=$this->treatment($key);
|
||||
$this->postJson('/investimentos/'.$this->id.'/aplicabilidade',['version'=>$v['case']['version'],'context_opportunity'=>$key,'land_needed'=>$index?'yes':'no','external_funding'=>'unknown','viability'=>'proceed','reason'=>'QA decisão específica por oportunidade'])->assertOk();
|
||||
$keys = array_column($this->choices, 'source');
|
||||
foreach ($keys as $index => $key) {
|
||||
$v = $this->treatment($key);
|
||||
$this->postJson('/investimentos/'.$this->id.'/aplicabilidade', ['version' => $v['case']['version'], 'context_opportunity' => $key, 'land_needed' => $index ? 'yes' : 'no', 'external_funding' => 'unknown', 'viability' => 'proceed', 'reason' => 'QA decisão específica por oportunidade'])->assertOk();
|
||||
}
|
||||
$a=$this->treatment($keys[0]);$b=$this->treatment($keys[1]);
|
||||
$this->assertSame('no',$a['facts']['land_needed']);$this->assertSame('yes',$b['facts']['land_needed']);
|
||||
$this->assertNull($a['tools']['land']);$this->assertNotNull($b['tools']['land']);
|
||||
$this->assertSame('not_needed_for_preparation',collect($a['steps'])->firstWhere('code','S10')['applicability']);
|
||||
$this->postJson('/investimentos/'.$this->id.'/etapas/S10',['version'=>$b['case']['version'],'context_opportunity'=>$keys[1],'state'=>'preparing','action'=>'prepare','reason'=>'Preparação apenas da segunda oportunidade'])->assertOk();
|
||||
$this->assertSame('preparing',collect($this->treatment($keys[1])['steps'])->firstWhere('code','S10')['saved_state']);
|
||||
$this->assertSame('not_started',collect($this->treatment($keys[0])['steps'])->firstWhere('code','S10')['saved_state']);
|
||||
$v=$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($keys[1]))->assertOk()->json();
|
||||
$sim=$v['prefill']['simulator'];$snap=json_decode($sim['context_applicability_snapshot'],true);
|
||||
$this->assertSame($keys[1],$snap['consumer_opportunity']);$this->assertSame('yes',$snap['land_preparation']['need']);
|
||||
$this->assertSame($this->parks[1]->primary_territory_id,$sim['province_id']);
|
||||
$a = $this->treatment($keys[0]);
|
||||
$b = $this->treatment($keys[1]);
|
||||
$this->assertSame('no', $a['facts']['land_needed']);
|
||||
$this->assertSame('yes', $b['facts']['land_needed']);
|
||||
$this->assertNull($a['tools']['land']);
|
||||
$this->assertNotNull($b['tools']['land']);
|
||||
$this->assertSame('not_needed_for_preparation', collect($a['steps'])->firstWhere('code', 'S10')['applicability']);
|
||||
$this->postJson('/investimentos/'.$this->id.'/etapas/S10', ['version' => $b['case']['version'], 'context_opportunity' => $keys[1], 'state' => 'preparing', 'action' => 'prepare', 'reason' => 'Preparação apenas da segunda oportunidade'])->assertOk();
|
||||
$this->assertSame('preparing', collect($this->treatment($keys[1])['steps'])->firstWhere('code', 'S10')['saved_state']);
|
||||
$this->assertSame('not_started', collect($this->treatment($keys[0])['steps'])->firstWhere('code', 'S10')['saved_state']);
|
||||
$v = $this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($keys[1]))->assertOk()->json();
|
||||
$sim = $v['prefill']['simulator'];
|
||||
$snap = json_decode($sim['context_applicability_snapshot'], true);
|
||||
$this->assertSame($keys[1], $snap['consumer_opportunity']);
|
||||
$this->assertSame('yes', $snap['land_preparation']['need']);
|
||||
$this->assertSame($this->parks[1]->primary_territory_id, $sim['province_id']);
|
||||
$this->assertStringContainsString('opportunity=', $b['tools']['simulator']);
|
||||
$this->assertArrayNotHasKey('province_id',$this->getJson('/investimentos/'.$this->id.'/contexto')->json('prefill.simulator'));
|
||||
$payload=app(VirtualDesk::class)->decode(DB::table('desk_cases')->where('id',$this->id)->value('payload'));
|
||||
$this->assertArrayNotHasKey('facts',$payload['investor_path']);
|
||||
$this->assertArrayNotHasKey('province_id', $this->getJson('/investimentos/'.$this->id.'/contexto')->json('prefill.simulator'));
|
||||
$payload = app(VirtualDesk::class)->decode(DB::table('desk_cases')->where('id', $this->id)->value('payload'));
|
||||
$this->assertArrayNotHasKey('facts', $payload['investor_path']);
|
||||
}
|
||||
|
||||
public function test_land_shortcut_recovers_associated_request_even_when_other_request_is_newer(): void
|
||||
{
|
||||
$ids=[];foreach(array_reverse($this->choices) as $choice) {
|
||||
$ids[$choice['source']]=$this->postJson('/investidor/terra-duat',['payload'=>['investor_path_case_id'=>$this->id,'context_opportunity'=>$choice['source'],'project_reference'=>'QA scope']])->assertCreated()->json('id');
|
||||
$ids = [];
|
||||
foreach (array_reverse($this->choices) as $choice) {
|
||||
$ids[$choice['source']] = $this->postJson('/investidor/terra-duat', ['payload' => ['investor_path_case_id' => $this->id, 'context_opportunity' => $choice['source'], 'project_reference' => 'QA scope']])->assertCreated()->json('id');
|
||||
}
|
||||
foreach ($ids as $key => $id) {
|
||||
$this->assertStringEndsWith($id, $this->treatment($key)['tools']['land']);
|
||||
}
|
||||
$unscoped = $this->getJson('/investimentos/'.$this->id)->assertOk()->json();
|
||||
foreach ($ids as $id) {
|
||||
$this->assertStringNotContainsString($id, $unscoped['tools']['land']);
|
||||
}
|
||||
foreach($ids as $key=>$id) $this->assertStringEndsWith($id,$this->treatment($key)['tools']['land']);
|
||||
$unscoped=$this->getJson('/investimentos/'.$this->id)->assertOk()->json();
|
||||
foreach($ids as $id) $this->assertStringNotContainsString($id,$unscoped['tools']['land']);
|
||||
$this->getJson('/investimentos/'.$this->id.'?opportunity=opportunity:99999999')->assertUnprocessable();
|
||||
}
|
||||
|
||||
public function test_simulator_saves_recovers_selected_scope_and_rejects_foreign_choice(): void
|
||||
{
|
||||
$key=$this->choices[1]['source'];
|
||||
$sim=$this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->json('prefill.simulator');
|
||||
$data=['context'=>$this->id,'personal_snapshot'=>[], 'economic_snapshot'=>['purpose'=>'simulate_only','project_title'=>'QA âmbito simulado','context_opportunity'=>$key,'context_applicability_snapshot'=>$sim['context_applicability_snapshot'],'financial_tools_snapshot'=>json_encode(['version'=>1,'data'=>[]])]];
|
||||
$this->postJson('/api/v1/simulation-drafts',$data,['Idempotency-Key'=>(string)Str::uuid()])->assertCreated();
|
||||
$this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->assertOk()->assertJsonPath('data.economic_snapshot.context_opportunity',$key);
|
||||
$key = $this->choices[1]['source'];
|
||||
$sim = $this->getJson('/investimentos/'.$this->id.'/contexto?opportunity='.urlencode($key))->json('prefill.simulator');
|
||||
$data = ['context' => $this->id, 'personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'project_title' => 'QA âmbito simulado', 'context_opportunity' => $key, 'context_applicability_snapshot' => $sim['context_applicability_snapshot'], 'financial_tools_snapshot' => json_encode(['version' => 1, 'data' => []])]];
|
||||
$this->postJson('/api/v1/simulation-drafts', $data, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->assertOk()->assertJsonPath('data.economic_snapshot.context_opportunity', $key);
|
||||
$this->actingAs($this->actor->fresh());
|
||||
$saved=$this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($key,json_decode($saved['context_applicability_snapshot'],true)['consumer_opportunity']);
|
||||
$current=$this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->json('data');
|
||||
$case=$this->treatment($key);
|
||||
$this->postJson('/investimentos/'.$this->id.'/resultados',['version'=>$case['case']['version'],'draft_id'=>$current['id'],'draft_version'=>$current['version_no'],'context_revision'=>$case['investment_context']['revision'],'context_reviewed'=>true])->assertOk()->assertJsonPath('result.context_opportunity',$key);
|
||||
$other=$this->postJson('/investimentos',['title'=>'QA identidade alheia ao dossier','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$this->postJson('/api/v1/simulation-drafts',[...$data,'context'=>$other],['Idempotency-Key'=>(string)Str::uuid()])->assertUnprocessable();
|
||||
$saved = $this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($key, json_decode($saved['context_applicability_snapshot'], true)['consumer_opportunity']);
|
||||
$current = $this->getJson('/api/v1/simulation-drafts/current?context='.$this->id)->json('data');
|
||||
$case = $this->treatment($key);
|
||||
$this->postJson('/investimentos/'.$this->id.'/resultados', ['version' => $case['case']['version'], 'draft_id' => $current['id'], 'draft_version' => $current['version_no'], 'context_revision' => $case['investment_context']['revision'], 'context_reviewed' => true])->assertOk()->assertJsonPath('result.context_opportunity', $key);
|
||||
$other = $this->postJson('/investimentos', ['title' => 'QA identidade alheia ao dossier', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$this->postJson('/api/v1/simulation-drafts', [...$data, 'context' => $other], ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable();
|
||||
}
|
||||
|
||||
public function test_authorised_common_contacts_are_reused_without_inventing_company_or_tax_identity(): void
|
||||
{
|
||||
$this->putJson('/investidor/profile',['version'=>0,'payload'=>['phone'=>'+258840001234','country'=>'Portugal','sector'=>'Sector de preferência']])->assertOk();
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA contactos autorizados','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$v=$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json('prefill');
|
||||
foreach(['land','simulator'] as $tool) {
|
||||
$this->assertSame('+258840001234',$v[$tool]['phone']);$this->assertSame($this->actor->email,$v[$tool]['email']);
|
||||
$this->assertArrayNotHasKey('tax_residency_country',$v[$tool]);$this->assertArrayNotHasKey('sector',$v[$tool]);
|
||||
$this->putJson('/investidor/profile', ['version' => 0, 'payload' => ['phone' => '+258840001234', 'country' => 'Portugal', 'sector' => 'Sector de preferência']])->assertOk();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA contactos autorizados', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$v = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json('prefill');
|
||||
foreach (['land', 'simulator'] as $tool) {
|
||||
$this->assertSame('+258840001234', $v[$tool]['phone']);
|
||||
$this->assertSame($this->actor->email, $v[$tool]['email']);
|
||||
$this->assertArrayNotHasKey('tax_residency_country', $v[$tool]);
|
||||
$this->assertArrayNotHasKey('sector', $v[$tool]);
|
||||
}
|
||||
$this->assertSame($this->actor->name,$v['land']['full_name']);
|
||||
$this->assertSame($this->actor->name, $v['land']['full_name']);
|
||||
}
|
||||
|
||||
public function test_idea_sector_and_territory_entries_keep_explicit_source_through_recovery(): void
|
||||
{
|
||||
$id=$this->postJson('/investimentos',['title'=>'QA ideia livre','client_key'=>(string)Str::uuid(),'reuse_consent'=>true])->assertCreated()->json('id');
|
||||
$this->get('/investimentos/iniciar')->assertOk()->assertInertia(fn($p)=>$p->where('source',null));
|
||||
$sector=DB::table('sectors')->where('is_active',true)->first();
|
||||
foreach(['sector:'.$sector->id,'territory:'.$this->parks[1]->primary_territory_id] as $source) {
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source='.urlencode($source))->assertOk()->assertInertia(fn($p)=>$p->where('source.key',$source));
|
||||
$slot=str_starts_with($source,'sector:')?'sector':'territory';
|
||||
$v=$this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$body=['version'=>$v['case']['version'],'selection'=>[$slot=>$source]];
|
||||
$preview=$this->postJson('/investimentos/'.$id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar',[...$body,'preview_hash'=>$preview['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA ideia livre', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$this->get('/investimentos/iniciar')->assertOk()->assertInertia(fn ($p) => $p->where('source', null));
|
||||
$sector = DB::table('sectors')->where('is_active', true)->first();
|
||||
foreach (['sector:'.$sector->id, 'territory:'.$this->parks[1]->primary_territory_id] as $source) {
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source='.urlencode($source))->assertOk()->assertInertia(fn ($p) => $p->where('source.key', $source));
|
||||
$slot = str_starts_with($source, 'sector:') ? 'sector' : 'territory';
|
||||
$v = $this->getJson('/investimentos/'.$id.'/contexto')->json();
|
||||
$body = ['version' => $v['case']['version'], 'selection' => [$slot => $source]];
|
||||
$preview = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$body, 'preview_hash' => $preview['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
$this->actingAs($this->actor->fresh());
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.selection.'.$slot.'.key',$source);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.selection.'.$slot.'.key', $source);
|
||||
}
|
||||
$view=$this->getJson('/investimentos/'.$id.'/contexto')->json('prefill');
|
||||
$this->assertSame($this->parks[1]->primary_territory_id,$view['simulator']['province_id']);
|
||||
$this->assertSame($this->parks[1]->primary_territory_id,$view['land']['parcels'][0]['province_id']);
|
||||
$this->assertSame($id,$this->getJson('/investimentos/'.$id)->json('case.id'));
|
||||
$view = $this->getJson('/investimentos/'.$id.'/contexto')->json('prefill');
|
||||
$this->assertSame($this->parks[1]->primary_territory_id, $view['simulator']['province_id']);
|
||||
$this->assertSame($this->parks[1]->primary_territory_id, $view['land']['parcels'][0]['province_id']);
|
||||
$this->assertSame($id, $this->getJson('/investimentos/'.$id)->json('case.id'));
|
||||
}
|
||||
|
||||
public function test_sector_entry_survives_authentication_redirect_with_same_source(): void
|
||||
{
|
||||
$sector=DB::table('sectors')->where('is_active',true)->first();
|
||||
$url='/investimentos/iniciar?source='.urlencode('sector:'.$sector->id);
|
||||
\Illuminate\Support\Facades\Auth::logout();
|
||||
$this->get($url)->assertRedirect('/login')->assertSessionHas('url.intended',url($url));
|
||||
$this->post('/login',['email'=>$this->actor->email,'password'=>'password'])->assertRedirect(url($url));
|
||||
$this->get($url)->assertOk()->assertInertia(fn($p)=>$p->where('source.key','sector:'.$sector->id));
|
||||
$sector = DB::table('sectors')->where('is_active', true)->first();
|
||||
$url = '/investimentos/iniciar?source='.urlencode('sector:'.$sector->id);
|
||||
Auth::logout();
|
||||
$this->get($url)->assertRedirect('/login')->assertSessionHas('url.intended', url($url));
|
||||
$this->post('/login', ['email' => $this->actor->email, 'password' => 'password'])->assertRedirect(url($url));
|
||||
$this->get($url)->assertOk()->assertInertia(fn ($p) => $p->where('source.key', 'sector:'.$sector->id));
|
||||
}
|
||||
|
||||
public function test_removing_first_keeps_second_identity_common_edits_and_historical_requests(): void
|
||||
{
|
||||
$before=$this->confirm();$second=$before['context']['opportunity_choices'][1];
|
||||
$key=$this->choices[1]['source'];
|
||||
$land=$this->postJson('/investidor/terra-duat',['payload'=>['investor_path_case_id'=>$this->id,'context_opportunity'=>$this->choices[0]['source'],'project_reference'=>'QA histórico']])->assertCreated()->json('id');
|
||||
$this->choices=[$this->choices[1]];
|
||||
$v=$this->getJson('/investimentos/'.$this->id.'/contexto')->json();
|
||||
$body=['version'=>$v['case']['version'],'selection'=>[],'opportunity_choices'=>$this->choices,'declarations'=>['project_title'=>'Título deliberado comum']];
|
||||
$preview=$this->postJson('/investimentos/'.$this->id.'/contexto/previa',$body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar',[...$body,'preview_hash'=>$preview['preview_hash'],'operation_key'=>(string)Str::uuid(),'confirm'=>true])->assertOk();
|
||||
$after=$this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($second,$after['context']['opportunity_choices'][0]);
|
||||
$this->assertSame('Título deliberado comum',$after['context']['fields']['project_title']);
|
||||
$before = $this->confirm();
|
||||
$second = $before['context']['opportunity_choices'][1];
|
||||
$key = $this->choices[1]['source'];
|
||||
$land = $this->postJson('/investidor/terra-duat', ['payload' => ['investor_path_case_id' => $this->id, 'context_opportunity' => $this->choices[0]['source'], 'project_reference' => 'QA histórico']])->assertCreated()->json('id');
|
||||
$this->choices = [$this->choices[1]];
|
||||
$v = $this->getJson('/investimentos/'.$this->id.'/contexto')->json();
|
||||
$body = ['version' => $v['case']['version'], 'selection' => [], 'opportunity_choices' => $this->choices, 'declarations' => ['project_title' => 'Título deliberado comum']];
|
||||
$preview = $this->postJson('/investimentos/'.$this->id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$this->id.'/contexto/confirmar', [...$body, 'preview_hash' => $preview['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
$after = $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($second, $after['context']['opportunity_choices'][0]);
|
||||
$this->assertSame('Título deliberado comum', $after['context']['fields']['project_title']);
|
||||
$this->getJson('/investidor/terra-duat/'.$land)->assertOk();
|
||||
$this->assertStringNotContainsString($land,$this->treatment($key)['tools']['land']);
|
||||
$this->assertStringNotContainsString($land, $this->treatment($key)['tools']['land']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentWorkspaceTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
private function draft(User $user): string
|
||||
@@ -63,6 +65,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
$id = $this->draft($user);
|
||||
$this->postJson('/api/v1/investment/submissions/'.$id.'/submit', $this->payload())->assertOk();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$stats = app(DeclaredOriginStatistics::class)->forManager($user);
|
||||
$this->assertSame([['code' => null, 'name' => 'Não informado', 'count' => 1]], $stats['interests']);
|
||||
$this->assertSame([], $stats['desk']);
|
||||
@@ -83,6 +86,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
}
|
||||
$before = InterestRequest::orderBy('id')->get()->toArray();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$this->get('/management/crm/leads?origin=PT')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('filters.origin', 'PT')->has('originStatistics.interests', 1)
|
||||
->where('originStatistics.interests.0.code', 'PT')->where('originStatistics.interests.0.count', 1));
|
||||
@@ -120,6 +124,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
$this->assertDatabaseCount('memberships', 0);
|
||||
$this->assertDatabaseCount('organizations', 0);
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$this->get('/management/history')->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->has('events.data', 3)->where('events.data.0.after_data.values.version', 1));
|
||||
$this->actingAs(User::factory()->create())->getJson('/api/v1/investment/profile')->assertJsonCount(0, 'companies');
|
||||
@@ -144,7 +149,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
$this->postJson($url, [...$message, 'body' => 'Outro conteúdo com a mesma chave.'])->assertConflict();
|
||||
$this->assertDatabaseCount('investment_messages', 1);
|
||||
$this->assertStringNotContainsString('Mensagem privada', DB::table('investment_messages')->value('body'));
|
||||
$this->actingAs($manager)->getJson('/api/v1/investment/notifications')->assertJsonPath('unread', 1);
|
||||
$this->actingAsWithMfa($manager)->getJson('/api/v1/investment/notifications')->assertJsonPath('unread', 1);
|
||||
$this->postJson($url, ['client_key' => (string) Str::uuid(), 'body' => 'Resposta sintética da equipa.'])->assertOk();
|
||||
$this->actingAs($owner)->getJson('/api/v1/investment/notifications')->assertJsonPath('unread', 2);
|
||||
$this->getJson('/api/v1/investment/submissions/'.$id)->assertJsonCount(2, 'messages')->assertJsonPath('messages.1.sender_role', 'support');
|
||||
@@ -154,7 +159,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
$this->actingAs(User::factory()->create())->postJson($url, $message)->assertNotFound();
|
||||
$this->postJson('/api/v1/investment/notifications/'.$notification->id.'/read')->assertNotFound();
|
||||
config(['portal.managers' => []]);
|
||||
$this->actingAs($manager)->getJson('/api/v1/investment/notifications')->assertJsonCount(0, 'notifications.data');
|
||||
$this->actingAsWithMfa($manager)->getJson('/api/v1/investment/notifications')->assertJsonCount(0, 'notifications.data');
|
||||
$this->getJson('/api/v1/investment/submissions/'.$id)->assertNotFound();
|
||||
}
|
||||
|
||||
@@ -183,7 +188,7 @@ class InvestmentWorkspaceTest extends TestCase
|
||||
$id = $this->draft($owner);
|
||||
$this->postJson('/api/v1/investment/submissions/'.$id.'/submit', $this->payload())->assertOk();
|
||||
$interest = InterestRequest::firstOrFail();
|
||||
$this->actingAs($manager)->patch('/management/interests/'.$interest->id, ['status' => 'in_review'])->assertRedirect();
|
||||
$this->actingAsWithMfa($manager)->patch('/management/interests/'.$interest->id, ['status' => 'in_review'])->assertRedirect();
|
||||
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review'])->assertRedirect();
|
||||
$this->patchJson('/api/v1/investment/admin/interests/'.$interest->id.'/status', ['status' => 'in_review'])->assertOk()->assertJsonPath('status', 'in_review');
|
||||
$this->assertDatabaseCount('investment_notifications', 2);
|
||||
|
||||
@@ -14,10 +14,12 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestorGuidanceTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $investor;
|
||||
@@ -156,7 +158,7 @@ class InvestorGuidanceTest extends TestCase
|
||||
$this->putJson('/balcao-virtual/pedidos/'.$requestId, $submit)->assertOk();
|
||||
$this->get('/balcao-virtual/pedidos/'.$requestId.'/recibo')->assertOk();
|
||||
$this->postJson('/balcao-virtual/pedidos/'.$requestId.'/estado', ['version' => 3, 'status' => 'reviewing', 'reason' => 'Autodecisão indevida.'])->assertForbidden();
|
||||
$this->actingAs($this->manager)->postJson('/balcao-virtual/pedidos/'.$requestId.'/responsavel', ['version' => 3, 'analyst_id' => $this->manager->id, 'reason' => 'Atribuição real QA.'])->assertOk();
|
||||
$this->actingAsWithMfa($this->manager)->postJson('/balcao-virtual/pedidos/'.$requestId.'/responsavel', ['version' => 3, 'analyst_id' => $this->manager->id, 'reason' => 'Atribuição real QA.'])->assertOk();
|
||||
$this->postJson('/balcao-virtual/pedidos/'.$requestId.'/estado', ['version' => 4, 'status' => 'reviewing', 'reason' => 'Análise interna iniciada.'])->assertOk();
|
||||
$this->postJson('/balcao-virtual/pedidos/'.$requestId.'/mensagens', ['body' => 'Resposta humana QA: indique as evidências de mercado.', 'client_key' => (string) Str::uuid()])->assertOk();
|
||||
$this->actingAs($this->investor)->getJson('/balcao-virtual/pedidos/'.$requestId)->assertJsonPath('messages.0.kind', 'responsible_response');
|
||||
|
||||
@@ -1,57 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\InvestmentZones;
|
||||
use App\Services\SectorInvestment;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Support\ProactiveInvestmentFixture;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestorUsabilityScopeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
protected function setUp():void{parent::setUp();\Tests\Support\ProactiveInvestmentFixture::guard();$this->withoutVite();}
|
||||
|
||||
public function test_public_sector_is_consultable_by_guest_and_accounts_without_promoter_grants():void
|
||||
protected function setUp(): void
|
||||
{
|
||||
config(['portal.homologation_only'=>false,'portal.legacy_content_enabled'=>false,'portal.legacy_content_qa_enabled'=>false]);
|
||||
parent::setUp();
|
||||
ProactiveInvestmentFixture::guard();
|
||||
$this->withoutVite();
|
||||
}
|
||||
|
||||
public function test_public_sector_is_consultable_by_guest_and_accounts_without_promoter_grants(): void
|
||||
{
|
||||
config(['portal.homologation_only' => false, 'portal.legacy_content_enabled' => false, 'portal.legacy_content_qa_enabled' => false]);
|
||||
$this->get('/sectores/turismo')->assertOk();
|
||||
$actor=User::factory()->create();
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor)->get('/sectores/turismo')->assertOk();
|
||||
$this->assertSame(0,DB::table('portal_role_assignments')->where('user_id',$actor->id)->count());
|
||||
config(['portal.profile_access_enabled'=>true]);
|
||||
$entry=app(\App\Services\SectorInvestment::class)->publicView(\App\Models\Sector::where('slug','turismo')->firstOrFail());
|
||||
$this->assertSame('/perfil/promotor',$entry['register_href']);
|
||||
$this->assertSame('Pedir acesso para cadastrar oportunidades',$entry['register_label']);
|
||||
$this->assertSame(0, DB::table('portal_role_assignments')->where('user_id', $actor->id)->count());
|
||||
config(['portal.profile_access_enabled' => true]);
|
||||
$entry = app(SectorInvestment::class)->publicView(Sector::where('slug', 'turismo')->firstOrFail());
|
||||
$this->assertSame('/perfil/promotor', $entry['register_href']);
|
||||
$this->assertSame('Pedir acesso para cadastrar oportunidades', $entry['register_label']);
|
||||
}
|
||||
|
||||
public function test_zones_all_equals_visible_set_and_province_and_district_never_fall_back_to_all():void
|
||||
public function test_zones_all_equals_visible_set_and_province_and_district_never_fall_back_to_all(): void
|
||||
{
|
||||
$zones=app(InvestmentZones::class);$geo=app(InvestmentGeography::class);
|
||||
$province='059b02ca-7095-577a-8705-4d4c46896747';
|
||||
$district=$geo->publicReferences()->where('parent_id',$province)->where('location_type','district')->first();
|
||||
$template=$zones->visible()->firstOrFail();
|
||||
$make=function($territory,$published=true)use($template){$zone=$template->replicate();$zone->id=(string)Str::uuid();$zone->code='SYNTHETIC-'.Str::random(12);$zone->name='SYNTHETIC QA zone scope';$zone->primary_territory_id=$territory;$zone->publication_status=$published?'published':'draft';$zone->save();return$zone;};
|
||||
$inside=$make($district->id);$outside=$make('9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8');$private=$make($district->id,false);
|
||||
$all=$zones->search([])->orderBy('id')->pluck('id')->all();
|
||||
$this->assertSame($zones->visible()->orderBy('id')->pluck('id')->all(),$all);
|
||||
foreach([['province_id'=>$province],['province_id'=>$province,'district_id'=>$district->id]]as$selection){
|
||||
$ids=$zones->search($selection)->pluck('id')->all();
|
||||
$this->assertContains($inside->id,$ids);$this->assertNotContains($outside->id,$ids);$this->assertNotContains($private->id,$ids);
|
||||
$zones = app(InvestmentZones::class);
|
||||
$geo = app(InvestmentGeography::class);
|
||||
$province = '059b02ca-7095-577a-8705-4d4c46896747';
|
||||
$district = $geo->publicReferences()->where('parent_id', $province)->where('location_type', 'district')->first();
|
||||
$template = $zones->visible()->firstOrFail();
|
||||
$make = function ($territory, $published = true) use ($template) {
|
||||
$zone = $template->replicate();
|
||||
$zone->id = (string) Str::uuid();
|
||||
$zone->code = 'SYNTHETIC-'.Str::random(12);
|
||||
$zone->name = 'SYNTHETIC QA zone scope';
|
||||
$zone->primary_territory_id = $territory;
|
||||
$zone->publication_status = $published ? 'published' : 'draft';
|
||||
$zone->save();
|
||||
|
||||
return $zone;
|
||||
};
|
||||
$inside = $make($district->id);
|
||||
$outside = $make('9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8');
|
||||
$private = $make($district->id, false);
|
||||
$all = $zones->search([])->orderBy('id')->pluck('id')->all();
|
||||
$this->assertSame($zones->visible()->orderBy('id')->pluck('id')->all(), $all);
|
||||
foreach ([['province_id' => $province], ['province_id' => $province, 'district_id' => $district->id]] as $selection) {
|
||||
$ids = $zones->search($selection)->pluck('id')->all();
|
||||
$this->assertContains($inside->id, $ids);
|
||||
$this->assertNotContains($outside->id, $ids);
|
||||
$this->assertNotContains($private->id, $ids);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_documented_legal_scope_covers_child_area_but_influence_does_not_become_an_installation():void
|
||||
public function test_documented_legal_scope_covers_child_area_but_influence_does_not_become_an_installation(): void
|
||||
{
|
||||
$zones=app(InvestmentZones::class);$geo=app(InvestmentGeography::class);$province='059b02ca-7095-577a-8705-4d4c46896747';
|
||||
$district=$geo->publicReferences()->where('parent_id',$province)->where('location_type','district')->first();
|
||||
$editor=User::factory()->create();$reviewer=User::factory()->create();$template=$zones->visible()->firstOrFail();$ids=[];
|
||||
foreach(['legal_scope','influence']as$scope){
|
||||
$zone=$template->replicate();$zone->id=(string)Str::uuid();$zone->code='SYNTHETIC-'.Str::random(12);$zone->name='SYNTHETIC QA legal coverage';$zone->primary_territory_id='9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8';$zone->save();$ids[$scope]=$zone->id;
|
||||
DB::table('investment_zone_locations')->insert(['id'=>(string)Str::uuid(),'zone_id'=>$zone->id,'geo_location_id'=>$scope==='legal_scope'?$province:$district->id,'scope_type'=>$scope,'source_reference'=>'SYNTHETIC isolated QA scope fixture','validation_status'=>'validated','editor_id'=>$editor->id,'reviewer_id'=>$reviewer->id,'valid_from'=>now()->subDay(),'version_no'=>1,'created_at'=>now(),'updated_at'=>now()]);
|
||||
$zones = app(InvestmentZones::class);
|
||||
$geo = app(InvestmentGeography::class);
|
||||
$province = '059b02ca-7095-577a-8705-4d4c46896747';
|
||||
$district = $geo->publicReferences()->where('parent_id', $province)->where('location_type', 'district')->first();
|
||||
$editor = User::factory()->create();
|
||||
$reviewer = User::factory()->create();
|
||||
$template = $zones->visible()->firstOrFail();
|
||||
$ids = [];
|
||||
foreach (['legal_scope', 'influence'] as $scope) {
|
||||
$zone = $template->replicate();
|
||||
$zone->id = (string) Str::uuid();
|
||||
$zone->code = 'SYNTHETIC-'.Str::random(12);
|
||||
$zone->name = 'SYNTHETIC QA legal coverage';
|
||||
$zone->primary_territory_id = '9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8';
|
||||
$zone->save();
|
||||
$ids[$scope] = $zone->id;
|
||||
DB::table('investment_zone_locations')->insert(['id' => (string) Str::uuid(), 'zone_id' => $zone->id, 'geo_location_id' => $scope === 'legal_scope' ? $province : $district->id, 'scope_type' => $scope, 'source_reference' => 'SYNTHETIC isolated QA scope fixture', 'validation_status' => 'validated', 'editor_id' => $editor->id, 'reviewer_id' => $reviewer->id, 'valid_from' => now()->subDay(), 'version_no' => 1, 'created_at' => now(), 'updated_at' => now()]);
|
||||
}
|
||||
$matches=$zones->search(['province_id'=>$province,'district_id'=>$district->id])->pluck('id')->all();
|
||||
$this->assertContains($ids['legal_scope'],$matches);$this->assertNotContains($ids['influence'],$matches);
|
||||
$matches = $zones->search(['province_id' => $province, 'district_id' => $district->id])->pluck('id')->all();
|
||||
$this->assertContains($ids['legal_scope'], $matches);
|
||||
$this->assertNotContains($ids['influence'], $matches);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,44 +14,73 @@ final class IrpcAnnualSettlementDraftTest extends TestCase
|
||||
|
||||
public function test_annual_simulated_balances_round_trip_with_proofs_states_and_preserved_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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['payable','recoverable','balanced','absent','missing','duplicate','pec']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l8-settlement/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$before=json_decode($d['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$scope=$d['context_opportunity'];
|
||||
$b=$s['irpcAnnual'][$scope];$m=$b['result']['model'];
|
||||
foreach(['irpcNormal','irpcWithholdings','books','currencyEvents','ispcQuarters']as$map)$this->assertSame($before[$map],$s[$map]);
|
||||
$this->assertSame('IRPC-annual-settlement/1',$m['version']);
|
||||
$this->assertSame('123456789',$m['subjectNuit']);$this->assertSame('2026',$m['year']);
|
||||
$this->assertSame(['numerator'=>'1408','denominator'=>'1'],$m['assessment']['colecta']);
|
||||
$this->assertFalse($m['officialBalancesConsumed']);$this->assertFalse($m['submitted']);$this->assertFalse($m['refundReceived']);
|
||||
$this->assertSame('known',$m['input']['credits']['state']);$this->assertSame('0',$m['input']['credits']['amount']);
|
||||
if(in_array($case,['missing','duplicate','pec'],true)){
|
||||
$this->assertSame('indeterminate',$m['status']);$this->assertNotEmpty($m['pending']);
|
||||
$this->assertNull($m['arithmeticBalance']);$this->assertNull($m['payable']);$this->assertNull($m['recoverable']);
|
||||
if($case==='missing')$this->assertSame('',$m['input']['ppc']['rows'][0]['effective']);
|
||||
if($case==='pec')$this->assertSame('10',$m['input']['pec']['amount']);
|
||||
if($case==='duplicate')$this->assertCount(2,$m['input']['ppc']['rows']);
|
||||
}else{
|
||||
$this->assertEmpty($m['pending']);
|
||||
$this->assertSame(['payable'=>'payable','recoverable'=>'recoverable','balanced'=>'balanced','absent'=>'payable'][$case],$m['status']);
|
||||
$this->assertSame(['numerator'=>['payable'=>'608','recoverable'=>'-192','balanced'=>'0','absent'=>'1408'][$case],'denominator'=>'1'],$m['arithmeticBalance']);
|
||||
$this->assertSame(['numerator'=>$case==='recoverable'?'192':'0','denominator'=>'1'],$m['recoverable']);
|
||||
if($case==='absent'){$this->assertSame('absent',$m['input']['withholdings']['state']);$this->assertSame('absent',$m['input']['ppc']['state']);}
|
||||
else{$this->assertSame('yes',$m['input']['withholdings']['rows'][0]['incomeIncluded']);$this->assertSame('yes',$m['input']['ppc']['rows'][0]['effective']);}
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['payable', 'recoverable', 'balanced', 'absent', 'missing', 'duplicate', 'pec'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l8-settlement/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l8-settlement/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$before = json_decode($d['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$scope = $d['context_opportunity'];
|
||||
$b = $s['irpcAnnual'][$scope];
|
||||
$m = $b['result']['model'];
|
||||
foreach (['irpcNormal', 'irpcWithholdings', 'books', 'currencyEvents', 'ispcQuarters'] as $map) {
|
||||
$this->assertSame($before[$map], $s[$map]);
|
||||
}
|
||||
$this->assertSame('IRPC-annual-settlement/1', $m['version']);
|
||||
$this->assertSame('123456789', $m['subjectNuit']);
|
||||
$this->assertSame('2026', $m['year']);
|
||||
$this->assertSame(['numerator' => '1408', 'denominator' => '1'], $m['assessment']['colecta']);
|
||||
$this->assertFalse($m['officialBalancesConsumed']);
|
||||
$this->assertFalse($m['submitted']);
|
||||
$this->assertFalse($m['refundReceived']);
|
||||
$this->assertSame('known', $m['input']['credits']['state']);
|
||||
$this->assertSame('0', $m['input']['credits']['amount']);
|
||||
if (in_array($case, ['missing', 'duplicate', 'pec'], true)) {
|
||||
$this->assertSame('indeterminate', $m['status']);
|
||||
$this->assertNotEmpty($m['pending']);
|
||||
$this->assertNull($m['arithmeticBalance']);
|
||||
$this->assertNull($m['payable']);
|
||||
$this->assertNull($m['recoverable']);
|
||||
if ($case === 'missing') {
|
||||
$this->assertSame('', $m['input']['ppc']['rows'][0]['effective']);
|
||||
}
|
||||
if ($case === 'pec') {
|
||||
$this->assertSame('10', $m['input']['pec']['amount']);
|
||||
}
|
||||
if ($case === 'duplicate') {
|
||||
$this->assertCount(2, $m['input']['ppc']['rows']);
|
||||
}
|
||||
} else {
|
||||
$this->assertEmpty($m['pending']);
|
||||
$this->assertSame(['payable' => 'payable', 'recoverable' => 'recoverable', 'balanced' => 'balanced', 'absent' => 'payable'][$case], $m['status']);
|
||||
$this->assertSame(['numerator' => ['payable' => '608', 'recoverable' => '-192', 'balanced' => '0', 'absent' => '1408'][$case], 'denominator' => '1'], $m['arithmeticBalance']);
|
||||
$this->assertSame(['numerator' => $case === 'recoverable' ? '192' : '0', 'denominator' => '1'], $m['recoverable']);
|
||||
if ($case === 'absent') {
|
||||
$this->assertSame('absent', $m['input']['withholdings']['state']);
|
||||
$this->assertSame('absent', $m['input']['ppc']['state']);
|
||||
} else {
|
||||
$this->assertSame('yes', $m['input']['withholdings']['rows'][0]['incomeIncluded']);
|
||||
$this->assertSame('yes', $m['input']['ppc']['rows'][0]['effective']);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l8-settlement/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,67 @@
|
||||
<?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 IrpcGroupedDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_grouped_irpc_rates_and_existing_fx_recover_with_originals_and_accepted_history():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()]));
|
||||
$d=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-grouped-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcWithholdings'][$d['context_opportunity']];
|
||||
$foreign=$b['result']['rows'][2];$this->assertSame('calculated',$foreign['status']);$this->assertSame(20,$foreign['rate']);$this->assertSame(['numerator'=>'64000','denominator'=>'1'],$foreign['base']);$this->assertSame(['numerator'=>'12800','denominator'=>'1'],$foreign['tax']);$this->assertSame(['numerator'=>'7800','denominator'=>'1'],$foreign['outstanding']);$this->assertSame('1000',$foreign['conversion']['originalAmount']);$this->assertSame('USD',$foreign['conversion']['originalCurrency']);$this->assertSame('2026-10-20',$foreign['conversion']['date']);$this->assertSame('2026-10-02',$foreign['eventDate']);
|
||||
$this->assertSame(10,$b['result']['rows'][3]['rate']);$this->assertSame('on_account',$b['result']['rows'][4]['nature']);$this->assertSame(['numerator'=>'10000','denominator'=>'1'],$b['result']['rows'][4]['tax']);$this->assertSame(['numerator'=>'640','denominator'=>'1'],$b['result']['rows'][5]['settled']);$this->assertSame(['numerator'=>'640','denominator'=>'1'],$b['result']['rows'][5]['outstanding']);$this->assertSame('10',$b['result']['paymentConversions']['p4']['originalAmount']);$this->assertSame('USD',$b['result']['payments'][3]['currency']);
|
||||
$old=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$prior=json_decode($old['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);foreach($prior as$k=>$v){if(in_array($k,['irpcWithholdings','currencyEvents'],true))continue;$this->assertSame($v,$s[$k],$k);}
|
||||
$oldBook=$prior['irpcWithholdings'][$d['context_opportunity']];$this->assertSame($oldBook['result'],$b['history'][array_key_last($b['history'])]);$this->assertSame($oldBook['rows'],array_slice($b['rows'],0,count($oldBook['rows'])));$this->assertSame($oldBook['payments'],array_slice($b['payments'],0,count($oldBook['payments'])));foreach(($prior['currencyEvents']??[])as$ctx=>$value){if($ctx!==$d['context_opportunity'])$this->assertSame($value,$s['currencyEvents'][$ctx]);}
|
||||
if(is_dir(base_path('outputs/irpc-l5-grouped-20261025')))file_put_contents(base_path('outputs/irpc-l5-grouped-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_grouped_irpc_rates_and_existing_fx_recover_with_originals_and_accepted_history(): 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()]));
|
||||
$d = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-grouped-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcWithholdings'][$d['context_opportunity']];
|
||||
$foreign = $b['result']['rows'][2];
|
||||
$this->assertSame('calculated', $foreign['status']);
|
||||
$this->assertSame(20, $foreign['rate']);
|
||||
$this->assertSame(['numerator' => '64000', 'denominator' => '1'], $foreign['base']);
|
||||
$this->assertSame(['numerator' => '12800', 'denominator' => '1'], $foreign['tax']);
|
||||
$this->assertSame(['numerator' => '7800', 'denominator' => '1'], $foreign['outstanding']);
|
||||
$this->assertSame('1000', $foreign['conversion']['originalAmount']);
|
||||
$this->assertSame('USD', $foreign['conversion']['originalCurrency']);
|
||||
$this->assertSame('2026-10-20', $foreign['conversion']['date']);
|
||||
$this->assertSame('2026-10-02', $foreign['eventDate']);
|
||||
$this->assertSame(10, $b['result']['rows'][3]['rate']);
|
||||
$this->assertSame('on_account', $b['result']['rows'][4]['nature']);
|
||||
$this->assertSame(['numerator' => '10000', 'denominator' => '1'], $b['result']['rows'][4]['tax']);
|
||||
$this->assertSame(['numerator' => '640', 'denominator' => '1'], $b['result']['rows'][5]['settled']);
|
||||
$this->assertSame(['numerator' => '640', 'denominator' => '1'], $b['result']['rows'][5]['outstanding']);
|
||||
$this->assertSame('10', $b['result']['paymentConversions']['p4']['originalAmount']);
|
||||
$this->assertSame('USD', $b['result']['payments'][3]['currency']);
|
||||
$old = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($old['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach ($prior as $k => $v) {
|
||||
if (in_array($k, ['irpcWithholdings', 'currencyEvents'], true)) {
|
||||
continue;
|
||||
}$this->assertSame($v, $s[$k], $k);
|
||||
}
|
||||
$oldBook = $prior['irpcWithholdings'][$d['context_opportunity']];
|
||||
$this->assertSame($oldBook['result'], $b['history'][array_key_last($b['history'])]);
|
||||
$this->assertSame($oldBook['rows'], array_slice($b['rows'], 0, count($oldBook['rows'])));
|
||||
$this->assertSame($oldBook['payments'], array_slice($b['payments'], 0, count($oldBook['payments'])));
|
||||
foreach (($prior['currencyEvents'] ?? []) as $ctx => $value) {
|
||||
if ($ctx !== $d['context_opportunity']) {
|
||||
$this->assertSame($value, $s['currencyEvents'][$ctx]);
|
||||
}
|
||||
}
|
||||
if (is_dir(base_path('outputs/irpc-l5-grouped-20261025'))) {
|
||||
file_put_contents(base_path('outputs/irpc-l5-grouped-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,33 +14,34 @@ final class IrpcInterestCerDraftTest extends TestCase
|
||||
|
||||
public function test_documented_parameter_calculation_and_segmented_cases_recover_through_private_api(): 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('outputs/irpc-interest-cer/calculated.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$draft['person_type']];unset($draft['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'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']);
|
||||
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$model=$store['irpcWithholdings'][$draft['context_opportunity']]['mrftaResult']['model'];
|
||||
$this->assertSame('7300',$model['principal']['numerator']);
|
||||
$this->assertSame('3650',$model['paid']['numerator']);
|
||||
$this->assertSame('15',$model['interest']['numerator']);
|
||||
$this->assertSame('3665',$model['total']['numerator']);
|
||||
$this->assertSame('IRPC-interest/1',$model['automatic']['version']);
|
||||
$this->assertSame('',$model['input']['interest']['mode']);
|
||||
$this->assertSame('automatic',$model['input']['interest']['calculation']);
|
||||
$this->assertSame('10',$model['automatic']['rule']['annualRate']);
|
||||
$this->assertStringContainsString('fictício',$model['automatic']['rule']['rateSource']);
|
||||
$segments=$model['automatic']['rows'][0]['segments'];
|
||||
$this->assertCount(2,$segments);
|
||||
$this->assertSame(5,$segments[0]['days']);
|
||||
$this->assertSame('7300',$segments[0]['principal']['numerator']);
|
||||
$this->assertSame('3650',$segments[1]['principal']['numerator']);
|
||||
$this->assertSame('999',$model['lines'][0]['cer']);
|
||||
file_put_contents(base_path('outputs/irpc-interest-cer/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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('outputs/irpc-interest-cer/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $draft['person_type']];
|
||||
unset($draft['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$model = $store['irpcWithholdings'][$draft['context_opportunity']]['mrftaResult']['model'];
|
||||
$this->assertSame('7300', $model['principal']['numerator']);
|
||||
$this->assertSame('3650', $model['paid']['numerator']);
|
||||
$this->assertSame('15', $model['interest']['numerator']);
|
||||
$this->assertSame('3665', $model['total']['numerator']);
|
||||
$this->assertSame('IRPC-interest/1', $model['automatic']['version']);
|
||||
$this->assertSame('', $model['input']['interest']['mode']);
|
||||
$this->assertSame('automatic', $model['input']['interest']['calculation']);
|
||||
$this->assertSame('10', $model['automatic']['rule']['annualRate']);
|
||||
$this->assertStringContainsString('fictício', $model['automatic']['rule']['rateSource']);
|
||||
$segments = $model['automatic']['rows'][0]['segments'];
|
||||
$this->assertCount(2, $segments);
|
||||
$this->assertSame(5, $segments[0]['days']);
|
||||
$this->assertSame('7300', $segments[0]['principal']['numerator']);
|
||||
$this->assertSame('3650', $segments[1]['principal']['numerator']);
|
||||
$this->assertSame('999', $model['lines'][0]['cer']);
|
||||
file_put_contents(base_path('outputs/irpc-interest-cer/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,50 +14,91 @@ final class IrpcInternationalCreditDraftTest extends TestCase
|
||||
|
||||
public function test_international_credit_delta_round_trips_with_frozen_history_and_unchanged_existing_records(): void
|
||||
{
|
||||
$target=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test',$target->name);
|
||||
$this->assertSame(55441,(int)$target->port);
|
||||
$snapshot=static fn(string $table):array=>collect(DB::select('select id::text as id,md5(row_to_json(t)::text) as hash from public."'.$table.'" t order by id'))->pluck('hash','id')->all();
|
||||
$protected=[];
|
||||
foreach(['opportunities','documents','opportunity_documents','simulation_form_drafts','users','organizations','audit_events']as$table)$protected[$table]=$snapshot($table);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);
|
||||
$this->actingAs(User::findOrFail(1021)); // Existing synthetic QA actor, no new grants.
|
||||
$base=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-assessment-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$fixture=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-international-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$this->assertTrue($fixture['synthetic']);$this->assertFalse($fixture['actualConventionData']);
|
||||
$personal=['person_type'=>$base['person_type']];unset($base['person_type']);
|
||||
$id=null;$etag=null;$previous=null;
|
||||
foreach($fixture['cases']as$name=>$book){
|
||||
$draft=$base;$s=json_decode($draft['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
if($previous!==null)$book['history']=[$previous];
|
||||
$s['irpcAnnual'][$draft['context_opportunity']]=$book;
|
||||
$draft['modelo_a_snapshot']=json_encode($s,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE);
|
||||
$payload=['personal_snapshot'=>$personal,'economic_snapshot'=>$draft];
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',$payload,['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,$payload,['If-Match'=>$etag])->assertOk();
|
||||
$response=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$response->headers->get('ETag');$back=$response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($draft['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$recovered=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
foreach(['irpcNormal','irpcWithholdings','books','currencyEvents','ispcQuarters']as$map)$this->assertSame($s[$map],$recovered[$map]);
|
||||
$saved=$recovered['irpcAnnual'][$draft['context_opportunity']];$m=$saved['result']['model'];$credit=$m['internationalCredit'];
|
||||
$this->assertSame($book,$saved);$this->assertSame('IRPC-international-credit/1',$credit['version']);$this->assertFalse($credit['carryCreated']);$this->assertFalse($credit['officialBalancesConsumed']);$this->assertFalse($credit['countryAllocationCreated']);$this->assertFalse($m['submitted']);
|
||||
$this->assertSame(['numerator'=>'1408','denominator'=>'1'],$m['assessment']['colecta']);
|
||||
if(in_array($name,['missing','duplicate'],true)){
|
||||
$this->assertSame('indeterminate',$m['status']);$this->assertNull($m['arithmeticBalance']);$this->assertNull($credit['deducted']);$this->assertNull($m['pecDeduction']['deducted']);$this->assertNotEmpty($m['pending']);
|
||||
}else{
|
||||
$expected=['payable'=>['payable','700','8','1400','200'],'treaty'=>['payable','702','6','1402','200'],'limited-collecta'=>['recoverable','-500','1408','0','0'],'absent'=>['payable','708','0','1408','200'],'prior-use'=>['payable','703','5','1403','200']][$name];
|
||||
$this->assertSame($expected[0],$m['status']);$this->assertEmpty($m['pending']);
|
||||
$this->assertSame(['numerator'=>$expected[1],'denominator'=>'1'],$m['arithmeticBalance']);
|
||||
$this->assertSame(['numerator'=>$expected[2],'denominator'=>'1'],$credit['deducted']);
|
||||
$this->assertSame(['numerator'=>$expected[3],'denominator'=>'1'],$credit['afterCredit']);
|
||||
$this->assertSame(['numerator'=>$expected[4],'denominator'=>'1'],$m['pecDeduction']['deducted']);
|
||||
if($name==='limited-collecta'){$this->assertSame(['numerator'=>'592','denominator'=>'1'],$credit['insufficientCollecta']);$this->assertSame(['numerator'=>'200','denominator'=>'1'],$m['pecDeduction']['remaining']);}
|
||||
}
|
||||
if($previous!==null)$this->assertSame($previous,$saved['history'][0]);$previous=$saved['result'];
|
||||
if(getenv('INVESTMOZ_INTERNATIONAL_QA_OUTPUT')==='1')file_put_contents(base_path('outputs/irpc-l8-international-20261027/recovered-'.$name.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
$snapshot = static fn (string $table): array => collect(DB::select('select id::text as id,md5(row_to_json(t)::text) as hash from public."'.$table.'" t order by id'))->pluck('hash', 'id')->all();
|
||||
$protected = [];
|
||||
foreach (['opportunities', 'documents', 'opportunity_documents', 'simulation_form_drafts', 'users', 'organizations', 'audit_events'] as $table) {
|
||||
$protected[$table] = $snapshot($table);
|
||||
}
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021)); // Existing synthetic QA actor, no new grants.
|
||||
$base = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-assessment-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$fixture = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-international-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertTrue($fixture['synthetic']);
|
||||
$this->assertFalse($fixture['actualConventionData']);
|
||||
$personal = ['person_type' => $base['person_type']];
|
||||
unset($base['person_type']);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
$previous = null;
|
||||
foreach ($fixture['cases'] as $name => $book) {
|
||||
$draft = $base;
|
||||
$s = json_decode($draft['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
if ($previous !== null) {
|
||||
$book['history'] = [$previous];
|
||||
}
|
||||
$s['irpcAnnual'][$draft['context_opportunity']] = $book;
|
||||
$draft['modelo_a_snapshot'] = json_encode($s, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
|
||||
$payload = ['personal_snapshot' => $personal, 'economic_snapshot' => $draft];
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, $payload, ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$response = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $response->headers->get('ETag');
|
||||
$back = $response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$recovered = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (['irpcNormal', 'irpcWithholdings', 'books', 'currencyEvents', 'ispcQuarters'] as $map) {
|
||||
$this->assertSame($s[$map], $recovered[$map]);
|
||||
}
|
||||
$saved = $recovered['irpcAnnual'][$draft['context_opportunity']];
|
||||
$m = $saved['result']['model'];
|
||||
$credit = $m['internationalCredit'];
|
||||
$this->assertSame($book, $saved);
|
||||
$this->assertSame('IRPC-international-credit/1', $credit['version']);
|
||||
$this->assertFalse($credit['carryCreated']);
|
||||
$this->assertFalse($credit['officialBalancesConsumed']);
|
||||
$this->assertFalse($credit['countryAllocationCreated']);
|
||||
$this->assertFalse($m['submitted']);
|
||||
$this->assertSame(['numerator' => '1408', 'denominator' => '1'], $m['assessment']['colecta']);
|
||||
if (in_array($name, ['missing', 'duplicate'], true)) {
|
||||
$this->assertSame('indeterminate', $m['status']);
|
||||
$this->assertNull($m['arithmeticBalance']);
|
||||
$this->assertNull($credit['deducted']);
|
||||
$this->assertNull($m['pecDeduction']['deducted']);
|
||||
$this->assertNotEmpty($m['pending']);
|
||||
} else {
|
||||
$expected = ['payable' => ['payable', '700', '8', '1400', '200'], 'treaty' => ['payable', '702', '6', '1402', '200'], 'limited-collecta' => ['recoverable', '-500', '1408', '0', '0'], 'absent' => ['payable', '708', '0', '1408', '200'], 'prior-use' => ['payable', '703', '5', '1403', '200']][$name];
|
||||
$this->assertSame($expected[0], $m['status']);
|
||||
$this->assertEmpty($m['pending']);
|
||||
$this->assertSame(['numerator' => $expected[1], 'denominator' => '1'], $m['arithmeticBalance']);
|
||||
$this->assertSame(['numerator' => $expected[2], 'denominator' => '1'], $credit['deducted']);
|
||||
$this->assertSame(['numerator' => $expected[3], 'denominator' => '1'], $credit['afterCredit']);
|
||||
$this->assertSame(['numerator' => $expected[4], 'denominator' => '1'], $m['pecDeduction']['deducted']);
|
||||
if ($name === 'limited-collecta') {
|
||||
$this->assertSame(['numerator' => '592', 'denominator' => '1'], $credit['insufficientCollecta']);
|
||||
$this->assertSame(['numerator' => '200', 'denominator' => '1'], $m['pecDeduction']['remaining']);
|
||||
}
|
||||
}
|
||||
if ($previous !== null) {
|
||||
$this->assertSame($previous, $saved['history'][0]);
|
||||
}$previous = $saved['result'];
|
||||
if (getenv('INVESTMOZ_INTERNATIONAL_QA_OUTPUT') === '1') {
|
||||
file_put_contents(base_path('outputs/irpc-l8-international-20261027/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
$preserved = [];
|
||||
foreach ($protected as $table => $before) {
|
||||
$this->assertSame($before, array_intersect_key($snapshot($table), $before), 'Existing records changed: '.$table);
|
||||
$preserved[$table] = ['existing_rows' => count($before), 'unchanged' => true];
|
||||
}
|
||||
if (getenv('INVESTMOZ_INTERNATIONAL_QA_OUTPUT') === '1') {
|
||||
file_put_contents(base_path('outputs/irpc-l8-international-20261027/existing-records-preservation.json'), json_encode(['database' => $target->name, 'tables' => $preserved, 'transaction_rollback' => true], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
|
||||
}
|
||||
$preserved=[];
|
||||
foreach($protected as$table=>$before){$this->assertSame($before,array_intersect_key($snapshot($table),$before),'Existing records changed: '.$table);$preserved[$table]=['existing_rows'=>count($before),'unchanged'=>true];}
|
||||
if(getenv('INVESTMOZ_INTERNATIONAL_QA_OUTPUT')==='1')file_put_contents(base_path('outputs/irpc-l8-international-20261027/existing-records-preservation.json'),json_encode(['database'=>$target->name,'tables'=>$preserved,'transaction_rollback'=>true],JSON_THROW_ON_ERROR|JSON_PRETTY_PRINT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -16,12 +17,12 @@ final class IrpcMrftaDraftTest extends TestCase
|
||||
$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()]));
|
||||
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('outputs/irpc-mrfta/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type'=>$draft['person_type']];
|
||||
$personal = ['person_type' => $draft['person_type']];
|
||||
unset($draft['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot'=>$personal, 'economic_snapshot'=>$draft], ['Idempotency-Key'=>(string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
@@ -36,6 +37,6 @@ final class IrpcMrftaDraftTest extends TestCase
|
||||
$this->assertSame('999', $model['lines'][0]['cer']);
|
||||
$this->assertStringContainsString('fictício', $model['input']['codes'][0]['reference']);
|
||||
$this->assertNotEmpty($book['history']);
|
||||
file_put_contents(base_path('outputs/irpc-mrfta/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
file_put_contents(base_path('outputs/irpc-mrfta/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -9,26 +11,55 @@ use Tests\TestCase;
|
||||
final class IrpcNormalAssessmentDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_normal_colecta_and_missing_classification_recover_without_annual_settlement(): 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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['calculated','missing'] as $case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-colecta/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/4',$m['version']);$this->assertSame('6700',$m['taxableProfit']['numerator']);$this->assertSame('4400',$m['taxableBase']['numerator']);$this->assertNull($m['tax']);
|
||||
$this->assertSame('2026',$m['assessment']['period']['year']);$this->assertSame('2026-01-01',$m['assessment']['period']['from']);$this->assertSame('2026-12-31',$m['assessment']['period']['to']);
|
||||
$this->assertSame('L8',$m['assessment']['finalBalance']['scope']);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
$this->assertSame('IRPC-normal-adjustments/3',$b['history'][2]['model']['version']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if($case==='calculated'){$this->assertSame('32',$m['assessment']['rate']['numerator']);$this->assertSame('1408',$m['colecta']['numerator']);$this->assertSame('general_61_1',$m['assessment']['input']['treatment']);}
|
||||
else{$this->assertNull($m['colecta']);$this->assertNull($m['assessment']['rate']);$this->assertSame('',$m['assessment']['input']['treatment']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-colecta/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['calculated', 'missing'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-colecta/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$p = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/4', $m['version']);
|
||||
$this->assertSame('6700', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame('4400', $m['taxableBase']['numerator']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertSame('2026', $m['assessment']['period']['year']);
|
||||
$this->assertSame('2026-01-01', $m['assessment']['period']['from']);
|
||||
$this->assertSame('2026-12-31', $m['assessment']['period']['to']);
|
||||
$this->assertSame('L8', $m['assessment']['finalBalance']['scope']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
$this->assertSame('IRPC-normal-adjustments/3', $b['history'][2]['model']['version']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if ($case === 'calculated') {
|
||||
$this->assertSame('32', $m['assessment']['rate']['numerator']);
|
||||
$this->assertSame('1408', $m['colecta']['numerator']);
|
||||
$this->assertSame('general_61_1', $m['assessment']['input']['treatment']);
|
||||
} else {
|
||||
$this->assertNull($m['colecta']);
|
||||
$this->assertNull($m['assessment']['rate']);
|
||||
$this->assertSame('', $m['assessment']['input']['treatment']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-colecta/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -9,29 +11,57 @@ use Tests\TestCase;
|
||||
final class IrpcNormalBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_taxable_base_and_missing_deduction_information_recover_without_consuming_loss_balances(): 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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['calculated','missing'] as $case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-base/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];
|
||||
$this->assertSame('6700',$m['taxableProfit']['numerator']);$this->assertNull($m['tax']);$this->assertSame('IRPC-normal-adjustments/3',$m['version']);
|
||||
$this->assertSame('2300',$m['base']['requestedLosses']['numerator']);$this->assertSame('2021',$m['base']['losses'][0]['year']);$this->assertSame(2026,$m['base']['losses'][0]['lastOrdinaryYear']);
|
||||
$this->assertSame('800',$m['base']['losses'][0]['available']['numerator']);$this->assertSame('2500',$m['base']['losses'][1]['available']['numerator']);
|
||||
$this->assertSame('200',$b['base']['losses'][0]['previouslyUsed']);$this->assertSame('500',$b['base']['losses'][1]['previouslyUsed']);
|
||||
$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertSame('IRPC-normal-adjustments/2',$b['history'][1]['model']['version']);
|
||||
if($case==='calculated'){
|
||||
$this->assertSame('4400',$m['taxableBase']['numerator']);$this->assertSame('2300',$m['base']['deductedLosses']['numerator']);$this->assertSame('1000',$m['base']['losses'][1]['remaining']['numerator']);
|
||||
$this->assertSame('known',$m['base']['input']['benefits']['state']);$this->assertSame('0',$m['base']['input']['benefits']['amount']);
|
||||
}else{$this->assertNull($m['taxableBase']);$this->assertNull($m['base']['deductedLosses']);$this->assertSame('',$m['base']['input']['benefits']['state']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-base/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['calculated', 'missing'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-base/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$p = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('6700', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertSame('IRPC-normal-adjustments/3', $m['version']);
|
||||
$this->assertSame('2300', $m['base']['requestedLosses']['numerator']);
|
||||
$this->assertSame('2021', $m['base']['losses'][0]['year']);
|
||||
$this->assertSame(2026, $m['base']['losses'][0]['lastOrdinaryYear']);
|
||||
$this->assertSame('800', $m['base']['losses'][0]['available']['numerator']);
|
||||
$this->assertSame('2500', $m['base']['losses'][1]['available']['numerator']);
|
||||
$this->assertSame('200', $b['base']['losses'][0]['previouslyUsed']);
|
||||
$this->assertSame('500', $b['base']['losses'][1]['previouslyUsed']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertSame('IRPC-normal-adjustments/2', $b['history'][1]['model']['version']);
|
||||
if ($case === 'calculated') {
|
||||
$this->assertSame('4400', $m['taxableBase']['numerator']);
|
||||
$this->assertSame('2300', $m['base']['deductedLosses']['numerator']);
|
||||
$this->assertSame('1000', $m['base']['losses'][1]['remaining']['numerator']);
|
||||
$this->assertSame('known', $m['base']['input']['benefits']['state']);
|
||||
$this->assertSame('0', $m['base']['input']['benefits']['amount']);
|
||||
} else {
|
||||
$this->assertNull($m['taxableBase']);
|
||||
$this->assertNull($m['base']['deductedLosses']);
|
||||
$this->assertSame('', $m['base']['input']['benefits']['state']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-base/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -9,25 +11,56 @@ use Tests\TestCase;
|
||||
final class IrpcNormalCostsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_cost_limits_provisions_and_timing_recover_their_facts_results_and_original_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()]));
|
||||
$expected=['calculated'=>['6730','4430','7088'],'additional'=>['7050','4750','1520'],'limits'=>['7210','4910','7856'],'closing'=>['6530','4230','6768']];$id=null;$etag=null;
|
||||
foreach(['calculated','missing','additional','limits','closing']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-costs/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/6',$m['version']);$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertArrayHasKey('books',$s);
|
||||
$this->assertContains('IRPC-normal-adjustments/5',array_column(array_column($b['history'],'model'),'version'));$this->assertSame($b['costs'],$m['costs']['input']);
|
||||
$this->assertNull($m['tax']);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
if($case==='missing'){$this->assertNull($m['taxableProfit']);$this->assertNull($m['taxableBase']);$this->assertNull($m['colecta']);$this->assertSame('520',$m['schedules']['net']['numerator']);$this->assertSame('40',$m['costs']['rows'][1]['adjustment']['numerator']);}
|
||||
else{[$profit,$base,$tax]=$expected[$case];$this->assertSame($profit,$m['taxableProfit']['numerator']);$this->assertSame($base,$m['taxableBase']['numerator']);$this->assertSame(['numerator'=>$tax,'denominator'=>$case==='additional'?'1':'5'],$m['colecta']);$this->assertSame([],$m['costs']['pending']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-costs/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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()]));
|
||||
$expected = ['calculated' => ['6730', '4430', '7088'], 'additional' => ['7050', '4750', '1520'], 'limits' => ['7210', '4910', '7856'], 'closing' => ['6530', '4230', '6768']];
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['calculated', 'missing', 'additional', 'limits', 'closing'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-costs/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$p = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/6', $m['version']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertArrayHasKey('books', $s);
|
||||
$this->assertContains('IRPC-normal-adjustments/5', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame($b['costs'], $m['costs']['input']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
if ($case === 'missing') {
|
||||
$this->assertNull($m['taxableProfit']);
|
||||
$this->assertNull($m['taxableBase']);
|
||||
$this->assertNull($m['colecta']);
|
||||
$this->assertSame('520', $m['schedules']['net']['numerator']);
|
||||
$this->assertSame('40', $m['costs']['rows'][1]['adjustment']['numerator']);
|
||||
} else {
|
||||
[$profit,$base,$tax] = $expected[$case];
|
||||
$this->assertSame($profit, $m['taxableProfit']['numerator']);
|
||||
$this->assertSame($base, $m['taxableBase']['numerator']);
|
||||
$this->assertSame(['numerator' => $tax, 'denominator' => $case === 'additional' ? '1' : '5'], $m['colecta']);
|
||||
$this->assertSame([], $m['costs']['pending']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-costs/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,69 @@
|
||||
<?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 IrpcNormalDepreciationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_depreciation_parameters_quotas_prior_balances_and_results_recover_without_rewriting_legacy_assets():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()]));$id=null;$etag=null;
|
||||
$expected=['months'=>['6780','4480','7168'],'declining'=>['6630','4330','6928'],'prior'=>['6730','4430','7088'],'specific'=>['13535','8935','7148']];
|
||||
foreach(['months','declining','prior','specific','missing']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-depreciation/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');else$this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$this->assertSame('IRPC-normal-adjustments/7',$m['version']);$this->assertSame($b['depreciation'],$m['depreciation']['input']);$this->assertSame($b['schedules']['assets'],$m['schedules']['input']['assets']);$this->assertSame([],$m['schedules']['assets']);$this->assertContains('IRPC-normal-adjustments/6',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertNull($m['tax']);$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
if($case==='missing'){$this->assertNull($m['depreciation']['adjustment']);$this->assertNull($m['taxableProfit']);$this->assertNull($m['colecta']);$this->assertSame('40',$m['costs']['rows'][1]['adjustment']['numerator']);}
|
||||
else{[$profit,$base,$colecta]=$expected[$case];$this->assertSame($profit,$m['taxableProfit']['numerator']);$this->assertSame($base,$m['taxableBase']['numerator']);$this->assertSame(['numerator'=>$colecta,'denominator'=>'5'],$m['colecta']);$this->assertSame([],$m['depreciation']['pending']);if($case==='prior'){$this->assertSame('20',$m['depreciation']['assets'][0]['priorUsed']['numerator']);$this->assertSame('40',$b['depreciation']['assets'][0]['priorAvailable']);}}
|
||||
file_put_contents(base_path('outputs/irpc-l6-depreciation/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_depreciation_parameters_quotas_prior_balances_and_results_recover_without_rewriting_legacy_assets(): 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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
$expected = ['months' => ['6780', '4480', '7168'], 'declining' => ['6630', '4330', '6928'], 'prior' => ['6730', '4430', '7088'], 'specific' => ['13535', '8935', '7148']];
|
||||
foreach (['months', 'declining', 'prior', 'specific', 'missing'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-depreciation/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$p = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/7', $m['version']);
|
||||
$this->assertSame($b['depreciation'], $m['depreciation']['input']);
|
||||
$this->assertSame($b['schedules']['assets'], $m['schedules']['input']['assets']);
|
||||
$this->assertSame([], $m['schedules']['assets']);
|
||||
$this->assertContains('IRPC-normal-adjustments/6', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
if ($case === 'missing') {
|
||||
$this->assertNull($m['depreciation']['adjustment']);
|
||||
$this->assertNull($m['taxableProfit']);
|
||||
$this->assertNull($m['colecta']);
|
||||
$this->assertSame('40', $m['costs']['rows'][1]['adjustment']['numerator']);
|
||||
} else {
|
||||
[$profit,$base,$colecta] = $expected[$case];
|
||||
$this->assertSame($profit, $m['taxableProfit']['numerator']);
|
||||
$this->assertSame($base, $m['taxableBase']['numerator']);
|
||||
$this->assertSame(['numerator' => $colecta, 'denominator' => '5'], $m['colecta']);
|
||||
$this->assertSame([], $m['depreciation']['pending']);
|
||||
if ($case === 'prior') {
|
||||
$this->assertSame('20', $m['depreciation']['assets'][0]['priorUsed']['numerator']);
|
||||
$this->assertSame('40', $b['depreciation']['assets'][0]['priorAvailable']);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-depreciation/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,32 +14,34 @@ final class IrpcNormalDraftTest extends TestCase
|
||||
|
||||
public function test_partial_normal_irpc_adjustments_recover_without_overwriting_withholdings(): 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('outputs/irpc-l6/calculated.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$draft['person_type']];unset($draft['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'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($draft['business_plan_snapshot'],$recovered['business_plan_snapshot']);
|
||||
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$book=$store['irpcNormal'][$draft['context_opportunity']];$model=$book['result']['model'];
|
||||
$this->assertSame('6480',$model['accountingProfit']['numerator']);
|
||||
$this->assertSame('120',$model['additions']['numerator']);
|
||||
$this->assertSame('6600',$model['partialAdjustedResult']['numerator']);
|
||||
$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('outputs/irpc-l6/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $draft['person_type']];
|
||||
unset($draft['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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($draft['business_plan_snapshot'], $recovered['business_plan_snapshot']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['irpcNormal'][$draft['context_opportunity']];
|
||||
$model = $book['result']['model'];
|
||||
$this->assertSame('6480', $model['accountingProfit']['numerator']);
|
||||
$this->assertSame('120', $model['additions']['numerator']);
|
||||
$this->assertSame('6600', $model['partialAdjustedResult']['numerator']);
|
||||
$this->assertNull($model['taxableProfit']);
|
||||
$this->assertNull($model['taxableBase']);
|
||||
$this->assertNull($model['tax']);
|
||||
$this->assertSame('projected',$model['origin']);
|
||||
$this->assertSame('IRPC-normal-adjustments/1',$model['version']);
|
||||
$this->assertSame('2026',$model['year']);
|
||||
$this->assertCount(2,$model['rows']);
|
||||
$this->assertSame('compensatory_interest',$model['rows'][1]['rule']);
|
||||
$this->assertStringContainsString('L6 parcial',implode(' ',$model['pending']));
|
||||
$this->assertArrayHasKey('irpcWithholdings',$store);
|
||||
file_put_contents(base_path('outputs/irpc-l6/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$this->assertSame('projected', $model['origin']);
|
||||
$this->assertSame('IRPC-normal-adjustments/1', $model['version']);
|
||||
$this->assertSame('2026', $model['year']);
|
||||
$this->assertCount(2, $model['rows']);
|
||||
$this->assertSame('compensatory_interest', $model['rows'][1]['rule']);
|
||||
$this->assertStringContainsString('L6 parcial', implode(' ', $model['pending']));
|
||||
$this->assertArrayHasKey('irpcWithholdings', $store);
|
||||
file_put_contents(base_path('outputs/irpc-l6/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,80 @@
|
||||
<?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 IrpcNormalFormPreparationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_form_classification_exact_values_and_unmapped_fields_recover_without_changing_calculation_or_history():void
|
||||
{
|
||||
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name);$this->assertSame(55441,(int)$db->port);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));$id=null;$etag=null;
|
||||
foreach(['mapped','fractional','missing','unmapped','booktax']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-values-forms/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');else$this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$f=$m['formPreparation'];$fields=array_column($f['fields'],null,'code');$this->assertSame('IRPC-normal-adjustments/9',$m['version']);$this->assertSame($b['forms'],$f['input']);$this->assertContains('IRPC-normal-adjustments/8',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertSame($m['taxableProfit'],$m['taxableBase']);$this->assertSame(['numerator'=>'5008','denominator'=>'5'],$m['colecta']);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($fields['309–316']['value']);$this->assertFalse($f['transport']['ready']);$this->assertSame($m['colecta'],$fields['300']['value']);
|
||||
if($case==='missing'){$this->assertNull($f['netResult']);$this->assertNull($fields['200']['value']);$this->assertSame($m['taxableProfit'],$fields['260']['value']);}
|
||||
elseif($case==='unmapped'||$case==='booktax'){$this->assertNull($fields['258']['value']);$this->assertNotEmpty($f['unmapped']);$this->assertFalse($f['reconciliation']['matches']);}
|
||||
else{$this->assertSame('3120',$f['netResult']['numerator']);$this->assertTrue($f['reconciliation']['matches']);$this->assertSame('0',$fields['213']['value']['numerator']);}
|
||||
if($case==='booktax'){$this->assertSame('2800',$f['netResult']['numerator']);$this->assertSame('0',$fields['213']['value']['numerator']);}
|
||||
if($case==='fractional'){$parts=array_column($f['m20'],null,'account');$this->assertSame(['numerator'=>'601','denominator'=>'2'],$parts['6.3']['value']);$this->assertFalse($parts['6.3']['representation']['ready']);$this->assertNull($parts['6.3']['representation']['represented']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-values-forms/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_form_classification_exact_values_and_unmapped_fields_recover_without_changing_calculation_or_history(): void
|
||||
{
|
||||
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
||||
$this->assertSame(55441, (int) $db->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['mapped', 'fractional', 'missing', 'unmapped', 'booktax'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-values-forms/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$f = $m['formPreparation'];
|
||||
$fields = array_column($f['fields'], null, 'code');
|
||||
$this->assertSame('IRPC-normal-adjustments/9', $m['version']);
|
||||
$this->assertSame($b['forms'], $f['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/8', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame($m['taxableProfit'], $m['taxableBase']);
|
||||
$this->assertSame(['numerator' => '5008', 'denominator' => '5'], $m['colecta']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
$this->assertNull($fields['309–316']['value']);
|
||||
$this->assertFalse($f['transport']['ready']);
|
||||
$this->assertSame($m['colecta'], $fields['300']['value']);
|
||||
if ($case === 'missing') {
|
||||
$this->assertNull($f['netResult']);
|
||||
$this->assertNull($fields['200']['value']);
|
||||
$this->assertSame($m['taxableProfit'], $fields['260']['value']);
|
||||
} elseif ($case === 'unmapped' || $case === 'booktax') {
|
||||
$this->assertNull($fields['258']['value']);
|
||||
$this->assertNotEmpty($f['unmapped']);
|
||||
$this->assertFalse($f['reconciliation']['matches']);
|
||||
} else {
|
||||
$this->assertSame('3120', $f['netResult']['numerator']);
|
||||
$this->assertTrue($f['reconciliation']['matches']);
|
||||
$this->assertSame('0', $fields['213']['value']['numerator']);
|
||||
}
|
||||
if ($case === 'booktax') {
|
||||
$this->assertSame('2800', $f['netResult']['numerator']);
|
||||
$this->assertSame('0', $fields['213']['value']['numerator']);
|
||||
}
|
||||
if ($case === 'fractional') {
|
||||
$parts = array_column($f['m20'], null, 'account');
|
||||
$this->assertSame(['numerator' => '601', 'denominator' => '2'], $parts['6.3']['value']);
|
||||
$this->assertFalse($parts['6.3']['representation']['ready']);
|
||||
$this->assertNull($parts['6.3']['representation']['represented']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-values-forms/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,66 @@
|
||||
<?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 IrpcNormalPeriodFxDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_period_and_currency_source_evidence_recover_with_original_plan_and_histories():void
|
||||
{
|
||||
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name);$this->assertSame(55441,(int)$db->port);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));$id=null;$etag=null;
|
||||
foreach(['short','fx','missing','loss']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-periods-fx/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');else$this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$this->assertSame('IRPC-normal-adjustments/8',$m['version']);$this->assertSame($b['periodsFx'],$m['periodsFx']['input']);$this->assertContains('IRPC-normal-adjustments/7',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($m['tax']);
|
||||
if($case==='short'||$case==='fx'){$this->assertSame($case==='short'?'3130':'200320',$m['taxableProfit']['numerator']);$this->assertSame($m['taxableProfit'],$m['taxableBase']);$this->assertSame(['numerator'=>$case==='short'?'5008':'320512','denominator'=>'5'],$m['colecta']);$this->assertSame(6,$m['periodsFx']['months']);$this->assertSame([],$m['periodsFx']['pending']);}
|
||||
else{$this->assertNull($m['colecta']);if($case==='loss'){$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertNull($m['taxableBase']);}else{$this->assertNull($m['accountingProfit']);$this->assertNotEmpty($m['periodsFx']['pending']);}}
|
||||
file_put_contents(base_path('outputs/irpc-l6-periods-fx/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_period_and_currency_source_evidence_recover_with_original_plan_and_histories(): void
|
||||
{
|
||||
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
||||
$this->assertSame(55441, (int) $db->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['short', 'fx', 'missing', 'loss'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-periods-fx/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/8', $m['version']);
|
||||
$this->assertSame($b['periodsFx'], $m['periodsFx']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/7', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
$this->assertNull($m['tax']);
|
||||
if ($case === 'short' || $case === 'fx') {
|
||||
$this->assertSame($case === 'short' ? '3130' : '200320', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame($m['taxableProfit'], $m['taxableBase']);
|
||||
$this->assertSame(['numerator' => $case === 'short' ? '5008' : '320512', 'denominator' => '5'], $m['colecta']);
|
||||
$this->assertSame(6, $m['periodsFx']['months']);
|
||||
$this->assertSame([], $m['periodsFx']['pending']);
|
||||
} else {
|
||||
$this->assertNull($m['colecta']);
|
||||
if ($case === 'loss') {
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['taxableBase']);
|
||||
} else {
|
||||
$this->assertNull($m['accountingProfit']);
|
||||
$this->assertNotEmpty($m['periodsFx']['pending']);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-periods-fx/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,36 +14,50 @@ final class IrpcNormalProfitDraftTest extends TestCase
|
||||
|
||||
public function test_scoped_taxable_profit_and_missing_information_recover_with_all_prior_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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['calculated','missing'] as $case){
|
||||
$draft=json_decode(file_get_contents(base_path('outputs/irpc-l6-profit/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$draft['person_type']];unset($draft['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$draft],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$draft],['If-Match'=>$etag])->assertOk();
|
||||
$response=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$response->headers->get('ETag');$recovered=$response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['business_plan_snapshot'],$recovered['business_plan_snapshot']);
|
||||
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$book=$store['irpcNormal'][$draft['context_opportunity']];$m=$book['result']['model'];
|
||||
$this->assertSame('6480',$m['accountingProfit']['numerator']);
|
||||
$this->assertSame('220',$m['additions']['numerator']);
|
||||
$this->assertNull($m['taxableBase']);$this->assertNull($m['tax']);
|
||||
$this->assertSame('IRPC-normal-adjustments/2',$m['version']);
|
||||
$this->assertSame('projected',$m['origin']);
|
||||
$this->assertSame('absent',$m['profit']['input']['topics']['positivePatrimonial']['state']);
|
||||
$this->assertCount(6,$m['profit']['lines']);
|
||||
$this->assertSame('known',$m['profit']['input']['topics']['incomeCorrections']['state']);
|
||||
$this->assertSame('0',$m['profit']['input']['topics']['incomeCorrections']['amount']);
|
||||
$this->assertArrayHasKey('irpcWithholdings',$store);
|
||||
$this->assertSame('IRPC-normal-adjustments/1',$book['history'][0]['model']['version']);
|
||||
if($case==='calculated'){$this->assertSame('6700',$m['taxableProfit']['numerator']);$this->assertCount(0,$m['profit']['pending']);}
|
||||
else{$this->assertNull($m['taxableProfit']);$this->assertSame('',$m['profit']['input']['topics']['negativePatrimonial']['state']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-profit/recovered-'.$case.'.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['calculated', 'missing'] as $case) {
|
||||
$draft = json_decode(file_get_contents(base_path('outputs/irpc-l6-profit/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $draft['person_type']];
|
||||
unset($draft['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $draft], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$response = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $response->headers->get('ETag');
|
||||
$recovered = $response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['business_plan_snapshot'], $recovered['business_plan_snapshot']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['irpcNormal'][$draft['context_opportunity']];
|
||||
$m = $book['result']['model'];
|
||||
$this->assertSame('6480', $m['accountingProfit']['numerator']);
|
||||
$this->assertSame('220', $m['additions']['numerator']);
|
||||
$this->assertNull($m['taxableBase']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertSame('IRPC-normal-adjustments/2', $m['version']);
|
||||
$this->assertSame('projected', $m['origin']);
|
||||
$this->assertSame('absent', $m['profit']['input']['topics']['positivePatrimonial']['state']);
|
||||
$this->assertCount(6, $m['profit']['lines']);
|
||||
$this->assertSame('known', $m['profit']['input']['topics']['incomeCorrections']['state']);
|
||||
$this->assertSame('0', $m['profit']['input']['topics']['incomeCorrections']['amount']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $store);
|
||||
$this->assertSame('IRPC-normal-adjustments/1', $book['history'][0]['model']['version']);
|
||||
if ($case === 'calculated') {
|
||||
$this->assertSame('6700', $m['taxableProfit']['numerator']);
|
||||
$this->assertCount(0, $m['profit']['pending']);
|
||||
} else {
|
||||
$this->assertNull($m['taxableProfit']);
|
||||
$this->assertSame('', $m['profit']['input']['topics']['negativePatrimonial']['state']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-profit/recovered-'.$case.'.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -9,27 +11,61 @@ use Tests\TestCase;
|
||||
final class IrpcNormalSchedulesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_complementary_rules_recover_calculated_missing_and_current_loss_without_settlement(): 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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['calculated','missing','loss','ep'] as $case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-sets/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/5',$m['version']);$this->assertNull($m['tax']);
|
||||
$this->assertSame('2026',$m['assessment']['period']['year']);$this->assertSame($case==='ep'?'2025-07-01':'2026-01-01',$m['assessment']['period']['from']);$this->assertSame($case==='ep'?'2026-06-30':'2026-12-31',$m['assessment']['period']['to']);
|
||||
$this->assertSame('L8',$m['assessment']['finalBalance']['scope']);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
$this->assertContains('IRPC-normal-adjustments/4',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('schedules',$m);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if(in_array($case,['calculated','ep'],true)){$this->assertSame('6980',$m['taxableProfit']['numerator']);$this->assertSame('4680',$m['taxableBase']['numerator']);$this->assertSame(['numerator'=>'7488','denominator'=>'5'],$m['colecta']);$this->assertSame('120',$m['schedules']['interest']['numerator']);}
|
||||
elseif($case==='missing'){$this->assertNull($m['taxableProfit']);$this->assertNull($m['colecta']);$this->assertNull($m['schedules']['interest']);$this->assertSame('520',$m['schedules']['net']['numerator']);}
|
||||
else{$this->assertSame('3820',$m['currentLoss']['numerator']);$this->assertSame('0',$m['taxableBase']['numerator']);$this->assertSame('0',$m['colecta']['numerator']);$this->assertSame([],$b['base']['losses']);}
|
||||
file_put_contents(base_path('outputs/irpc-l6-sets/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['calculated', 'missing', 'loss', 'ep'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-sets/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$p = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$this->assertSame('IRPC-normal-adjustments/5', $m['version']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertSame('2026', $m['assessment']['period']['year']);
|
||||
$this->assertSame($case === 'ep' ? '2025-07-01' : '2026-01-01', $m['assessment']['period']['from']);
|
||||
$this->assertSame($case === 'ep' ? '2026-06-30' : '2026-12-31', $m['assessment']['period']['to']);
|
||||
$this->assertSame('L8', $m['assessment']['finalBalance']['scope']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
||||
$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
||||
$this->assertContains('IRPC-normal-adjustments/4', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertArrayHasKey('schedules', $m);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if (in_array($case, ['calculated', 'ep'], true)) {
|
||||
$this->assertSame('6980', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame('4680', $m['taxableBase']['numerator']);
|
||||
$this->assertSame(['numerator' => '7488', 'denominator' => '5'], $m['colecta']);
|
||||
$this->assertSame('120', $m['schedules']['interest']['numerator']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertNull($m['taxableProfit']);
|
||||
$this->assertNull($m['colecta']);
|
||||
$this->assertNull($m['schedules']['interest']);
|
||||
$this->assertSame('520', $m['schedules']['net']['numerator']);
|
||||
} else {
|
||||
$this->assertSame('3820', $m['currentLoss']['numerator']);
|
||||
$this->assertSame('0', $m['taxableBase']['numerator']);
|
||||
$this->assertSame('0', $m['colecta']['numerator']);
|
||||
$this->assertSame([], $b['base']['losses']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l6-sets/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,53 +14,82 @@ final class IrpcPecDraftTest extends TestCase
|
||||
|
||||
public function test_pec_delta_round_trips_without_consuming_balances_or_changing_existing_records(): void
|
||||
{
|
||||
$target=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test',$target->name);
|
||||
$this->assertSame(55441,(int)$target->port);
|
||||
$snapshot=static function(string $table): array {
|
||||
return collect(DB::select('select id::text as id,md5(row_to_json(t)::text) as hash from public."'.$table.'" t order by id'))->pluck('hash','id')->all();
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
$snapshot = static function (string $table): array {
|
||||
return collect(DB::select('select id::text as id,md5(row_to_json(t)::text) as hash from public."'.$table.'" t order by id'))->pluck('hash', 'id')->all();
|
||||
};
|
||||
$protected=[];
|
||||
foreach(['opportunities','documents','opportunity_documents','simulation_form_drafts','users','organizations','audit_events']as$table)$protected[$table]=$snapshot($table);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);
|
||||
$protected = [];
|
||||
foreach (['opportunities', 'documents', 'opportunity_documents', 'simulation_form_drafts', 'users', 'organizations', 'audit_events'] as $table) {
|
||||
$protected[$table] = $snapshot($table);
|
||||
}
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021)); // Existing synthetic QA operator; no new grants.
|
||||
$base=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-assessment-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$fixture=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-pec-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$base['person_type']];unset($base['person_type']);
|
||||
$id=null;$etag=null;$previous=null;
|
||||
foreach($fixture['cases']as$name=>$book){
|
||||
$draft=$base;$store=json_decode($draft['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
if($previous!==null)$book['history']=[$previous];
|
||||
$store['irpcAnnual'][$draft['context_opportunity']]=$book;
|
||||
$draft['modelo_a_snapshot']=json_encode($store,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE);
|
||||
$payload=['personal_snapshot'=>$personal,'economic_snapshot'=>$draft];
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',$payload,['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,$payload,['If-Match'=>$etag])->assertOk();
|
||||
$response=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$response->headers->get('ETag');$back=$response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'],$back['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$recovered=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
foreach(['irpcNormal','irpcWithholdings','books','currencyEvents','ispcQuarters']as$map)$this->assertSame($store[$map],$recovered[$map]);
|
||||
$saved=$recovered['irpcAnnual'][$draft['context_opportunity']];$m=$saved['result']['model'];
|
||||
$this->assertSame($book,$saved);$this->assertSame('IRPC-PEC/1',$m['pecDeduction']['version']);
|
||||
$this->assertFalse($m['officialBalancesConsumed']);$this->assertFalse($m['pecDeduction']['carryCreated']);
|
||||
$this->assertSame(['numerator'=>'1408','denominator'=>'1'],$m['assessment']['colecta']);
|
||||
if($name==='missing'){$this->assertSame('indeterminate',$m['status']);$this->assertNull($m['arithmeticBalance']);$this->assertNull($m['pecDeduction']['deducted']);}
|
||||
else{
|
||||
$expected=['payable'=>['payable','708','200','0'],'capped'=>['balanced','0','1408','592'],'recoverable'=>['recoverable','-500','1408','592'],'prior-use'=>['payable','1208','200','0']][$name];
|
||||
$this->assertSame($expected[0],$m['status']);
|
||||
foreach(['arithmeticBalance'=>1,'deducted'=>2,'remaining'=>3]as$field=>$index)$this->assertSame(['numerator'=>$expected[$index],'denominator'=>'1'],$field==='arithmeticBalance'?$m[$field]:$m['pecDeduction'][$field]);
|
||||
$base = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-assessment-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$fixture = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-pec-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $base['person_type']];
|
||||
unset($base['person_type']);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
$previous = null;
|
||||
foreach ($fixture['cases'] as $name => $book) {
|
||||
$draft = $base;
|
||||
$store = json_decode($draft['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
if ($previous !== null) {
|
||||
$book['history'] = [$previous];
|
||||
}
|
||||
$store['irpcAnnual'][$draft['context_opportunity']] = $book;
|
||||
$draft['modelo_a_snapshot'] = json_encode($store, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
|
||||
$payload = ['personal_snapshot' => $personal, 'economic_snapshot' => $draft];
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, $payload, ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
$response = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $response->headers->get('ETag');
|
||||
$back = $response->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$recovered = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (['irpcNormal', 'irpcWithholdings', 'books', 'currencyEvents', 'ispcQuarters'] as $map) {
|
||||
$this->assertSame($store[$map], $recovered[$map]);
|
||||
}
|
||||
$saved = $recovered['irpcAnnual'][$draft['context_opportunity']];
|
||||
$m = $saved['result']['model'];
|
||||
$this->assertSame($book, $saved);
|
||||
$this->assertSame('IRPC-PEC/1', $m['pecDeduction']['version']);
|
||||
$this->assertFalse($m['officialBalancesConsumed']);
|
||||
$this->assertFalse($m['pecDeduction']['carryCreated']);
|
||||
$this->assertSame(['numerator' => '1408', 'denominator' => '1'], $m['assessment']['colecta']);
|
||||
if ($name === 'missing') {
|
||||
$this->assertSame('indeterminate', $m['status']);
|
||||
$this->assertNull($m['arithmeticBalance']);
|
||||
$this->assertNull($m['pecDeduction']['deducted']);
|
||||
} else {
|
||||
$expected = ['payable' => ['payable', '708', '200', '0'], 'capped' => ['balanced', '0', '1408', '592'], 'recoverable' => ['recoverable', '-500', '1408', '592'], 'prior-use' => ['payable', '1208', '200', '0']][$name];
|
||||
$this->assertSame($expected[0], $m['status']);
|
||||
foreach (['arithmeticBalance' => 1, 'deducted' => 2, 'remaining' => 3] as $field => $index) {
|
||||
$this->assertSame(['numerator' => $expected[$index], 'denominator' => '1'], $field === 'arithmeticBalance' ? $m[$field] : $m['pecDeduction'][$field]);
|
||||
}
|
||||
}
|
||||
if ($previous !== null) {
|
||||
$this->assertSame($previous, $saved['history'][0]);
|
||||
}
|
||||
$previous = $saved['result'];
|
||||
if (getenv('INVESTMOZ_PEC_QA_OUTPUT') === '1') {
|
||||
file_put_contents(base_path('outputs/irpc-l8-pec-20261027/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if($previous!==null)$this->assertSame($previous,$saved['history'][0]);
|
||||
$previous=$saved['result'];
|
||||
if(getenv('INVESTMOZ_PEC_QA_OUTPUT')==='1')file_put_contents(base_path('outputs/irpc-l8-pec-20261027/recovered-'.$name.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$preserved=[];
|
||||
foreach($protected as$table=>$before){
|
||||
$after=$snapshot($table);
|
||||
$this->assertSame($before,array_intersect_key($after,$before),'Existing records changed: '.$table);
|
||||
$preserved[$table]=['existing_rows'=>count($before),'unchanged'=>true];
|
||||
$preserved = [];
|
||||
foreach ($protected as $table => $before) {
|
||||
$after = $snapshot($table);
|
||||
$this->assertSame($before, array_intersect_key($after, $before), 'Existing records changed: '.$table);
|
||||
$preserved[$table] = ['existing_rows' => count($before), 'unchanged' => true];
|
||||
}
|
||||
if (getenv('INVESTMOZ_PEC_QA_OUTPUT') === '1') {
|
||||
file_put_contents(base_path('outputs/irpc-l8-pec-20261027/existing-records-preservation.json'), json_encode(['database' => $target->name, 'tables' => $preserved, 'transaction_rollback' => true], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
|
||||
}
|
||||
if(getenv('INVESTMOZ_PEC_QA_OUTPUT')==='1')file_put_contents(base_path('outputs/irpc-l8-pec-20261027/existing-records-preservation.json'),json_encode(['database'=>$target->name,'tables'=>$preserved,'transaction_rollback'=>true],JSON_THROW_ON_ERROR|JSON_PRETTY_PRINT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -16,29 +17,29 @@ final class IrpcReliefsDraftTest extends TestCase
|
||||
$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()]));
|
||||
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('outputs/irpc-reliefs/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type'=>$draft['person_type']];
|
||||
$personal = ['person_type' => $draft['person_type']];
|
||||
unset($draft['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot'=>$personal, 'economic_snapshot'=>$draft], ['Idempotency-Key'=>(string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['irpcWithholdings'][$draft['context_opportunity']];
|
||||
[$dispensed, $rent, $treaty, $missing] = array_slice($book['result']['rows'], -4);
|
||||
$this->assertSame('dispensed', $dispensed['treatment']);
|
||||
$this->assertSame(['numerator'=>'0','denominator'=>'1'], $dispensed['tax']);
|
||||
$this->assertSame(['numerator' => '0', 'denominator' => '1'], $dispensed['tax']);
|
||||
$this->assertSame('dispensed', $rent['treatment']);
|
||||
$this->assertSame('cirpc68f', $rent['reliefRule']);
|
||||
$this->assertSame(['numerator'=>'0','denominator'=>'1'], $rent['tax']);
|
||||
$this->assertSame(['numerator' => '0', 'denominator' => '1'], $rent['tax']);
|
||||
$this->assertSame('treaty', $treaty['treatment']);
|
||||
$this->assertSame(10, $treaty['rate']);
|
||||
$this->assertSame(['numerator'=>'10000','denominator'=>'1'], $treaty['tax']);
|
||||
$this->assertSame(['numerator' => '10000', 'denominator' => '1'], $treaty['tax']);
|
||||
$this->assertSame('indeterminate', $missing['status']);
|
||||
$this->assertNull($missing['tax']);
|
||||
$this->assertSame('QA certificado fiscal Portugal 2026', $book['result']['inputs'][count($book['result']['inputs'])-2]['reliefPreparation']['residenceDocument']);
|
||||
$this->assertSame('QA certificado fiscal Portugal 2026', $book['result']['inputs'][count($book['result']['inputs']) - 2]['reliefPreparation']['residenceDocument']);
|
||||
$this->assertNotEmpty($book['history']);
|
||||
file_put_contents(base_path('outputs/irpc-reliefs/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
file_put_contents(base_path('outputs/irpc-reliefs/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,42 +14,78 @@ final class IrpcSpecialCessationPriorDraftTest extends TestCase
|
||||
|
||||
public function test_cbf16_cessation_and_prior_quotas_recover_without_consuming_declared_balances(): 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()]));$id=null;$etag=null;
|
||||
foreach(['cessation','prior','annual','exit','missing','negative','absent']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-cessation-prior/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$a=$m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/13',$m['version']);$this->assertSame($b['special']['acceleration']['monthly'],$a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/12',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertContains('IRPC-normal-adjustments/11',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertSame($b['depreciation'],$a['normal']['input']);$this->assertSame(['scope'=>'L8','payable'=>null,'recoverable'=>null],$m['special']['finalBalance']);
|
||||
$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if($case==='cessation'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(6,$v['months']);$this->assertSame('absent',$v['exit']['state']);$this->assertSame('10',$a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3120',$m['special']['taxableProfit']['numerator']);$this->assertSame(['numerator'=>'4992','denominator'=>'5'],$m['special']['colecta']);
|
||||
}elseif($case==='prior'||$case==='annual'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame('150',$b['depreciation']['assets'][0]['previousAccounting']);$this->assertSame('100',$b['depreciation']['assets'][0]['previousFiscal']);$this->assertSame('50',$b['depreciation']['assets'][0]['priorAvailable']);
|
||||
$this->assertSame($case==='prior'?'15':'30',$v['prior']['acceleratedUsed']['numerator']);$this->assertSame($case==='prior'?'35':'20',$v['prior']['acceleratedRemaining']['numerator']);
|
||||
$this->assertSame($case==='prior'?'25':'50',$a['additionalDeduction']['numerator']);$this->assertSame($case==='prior'?'3105':'6210',$m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame(['numerator'=>$case==='prior'?'4968':'9936','denominator'=>'5'],$m['special']['colecta']);$this->assertSame($b['depreciation'],$a['accelerated']['input']);
|
||||
}elseif($case==='exit'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(5,$v['months']);$this->assertSame('2026-06-20',$v['exit']['date']);
|
||||
$this->assertSame(['numerator'=>'125','denominator'=>'3'],$v['normalQuota']);$this->assertSame(['numerator'=>'125','denominator'=>'6'],$a['additionalDeduction']);
|
||||
}elseif($case==='missing'){
|
||||
$this->assertSame('indeterminate',$a['status']);$this->assertNull($a['additionalDeduction']);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertNull($m['special']['colecta']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$a['rows'][0]['status']);$this->assertFalse($a['monthly']['assets'][0]['applied']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
}else{
|
||||
$this->assertSame('absent',$a['status']);$this->assertSame([],$a['monthly']['assets']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['cessation', 'prior', 'annual', 'exit', 'missing', 'negative', 'absent'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-cessation-prior/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-cessation-prior/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$a = $m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/13', $m['version']);
|
||||
$this->assertSame($b['special']['acceleration']['monthly'], $a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/12', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertContains('IRPC-normal-adjustments/11', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame($b['depreciation'], $a['normal']['input']);
|
||||
$this->assertSame(['scope' => 'L8', 'payable' => null, 'recoverable' => null], $m['special']['finalBalance']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if ($case === 'cessation') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(6, $v['months']);
|
||||
$this->assertSame('absent', $v['exit']['state']);
|
||||
$this->assertSame('10', $a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3120', $m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame(['numerator' => '4992', 'denominator' => '5'], $m['special']['colecta']);
|
||||
} elseif ($case === 'prior' || $case === 'annual') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame('150', $b['depreciation']['assets'][0]['previousAccounting']);
|
||||
$this->assertSame('100', $b['depreciation']['assets'][0]['previousFiscal']);
|
||||
$this->assertSame('50', $b['depreciation']['assets'][0]['priorAvailable']);
|
||||
$this->assertSame($case === 'prior' ? '15' : '30', $v['prior']['acceleratedUsed']['numerator']);
|
||||
$this->assertSame($case === 'prior' ? '35' : '20', $v['prior']['acceleratedRemaining']['numerator']);
|
||||
$this->assertSame($case === 'prior' ? '25' : '50', $a['additionalDeduction']['numerator']);
|
||||
$this->assertSame($case === 'prior' ? '3105' : '6210', $m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame(['numerator' => $case === 'prior' ? '4968' : '9936', 'denominator' => '5'], $m['special']['colecta']);
|
||||
$this->assertSame($b['depreciation'], $a['accelerated']['input']);
|
||||
} elseif ($case === 'exit') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(5, $v['months']);
|
||||
$this->assertSame('2026-06-20', $v['exit']['date']);
|
||||
$this->assertSame(['numerator' => '125', 'denominator' => '3'], $v['normalQuota']);
|
||||
$this->assertSame(['numerator' => '125', 'denominator' => '6'], $a['additionalDeduction']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertSame('indeterminate', $a['status']);
|
||||
$this->assertNull($a['additionalDeduction']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['special']['colecta']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $a['rows'][0]['status']);
|
||||
$this->assertFalse($a['monthly']['assets'][0]['applied']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
} else {
|
||||
$this->assertSame('absent', $a['status']);
|
||||
$this->assertSame([], $a['monthly']['assets']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-cessation-prior/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -9,36 +11,71 @@ use Tests\TestCase;
|
||||
final class IrpcSpecialCombinationsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_qualified_combinations_and_incompatibilities_round_trip_without_rewriting_inputs(): 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()]));$id=null;$etag=null;
|
||||
foreach(['combined','autonomous','incompatible','missing','exception','negative','absent']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-combinations/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$v=$m['special'];$c=$v['combinations'];
|
||||
$this->assertSame('IRPC-normal-adjustments/14',$m['version']);$this->assertSame($b['special']['combinations'],$c['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/13',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertSame('150',$b['depreciation']['assets'][0]['previousAccounting']);$this->assertSame('100',$b['depreciation']['assets'][0]['previousFiscal']);$this->assertSame('50',$b['depreciation']['assets'][0]['priorAvailable']);
|
||||
$this->assertSame($b['depreciation'],$v['acceleration']['normal']['input']);$this->assertSame(['scope'=>'L8','payable'=>null,'recoverable'=>null],$v['finalBalance']);$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if(in_array($case,['combined','autonomous'],true)){
|
||||
$this->assertSame('compatible',$c['status']);$this->assertSame('25',$v['acceleration']['additionalDeduction']['numerator']);$this->assertSame('15',$c['assetClaims'][0]['priorRecoveredIncluded']['numerator']);$this->assertSame('75',$c['assetClaims'][0]['acceleratedDeduction']['numerator']);
|
||||
$this->assertSame('16',$v['cooperative']['rate']['numerator']);$this->assertSame($case==='combined'?'3105':'3205',$v['taxableBase']['numerator']);
|
||||
$this->assertSame(['numerator'=>$case==='combined'?'2484':'2739','denominator'=>'5'],$v['combinedColecta']);
|
||||
if($case==='autonomous'){$this->assertSame('35',$v['expenses']['autonomousTax']['numerator']);$this->assertSame('0',$v['expenses']['rows'][0]['additionalProfitAdjustment']['numerator']);}
|
||||
}elseif(in_array($case,['incompatible','missing','exception'],true)){
|
||||
$this->assertSame($case==='incompatible'?'incompatible':'indeterminate',$c['status']);$this->assertNull($v['taxableBase']);$this->assertNull($v['combinedColecta']);$this->assertSame('3130',$m['taxableProfit']['numerator']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$v['cooperative']['status']);$this->assertSame(['numerator'=>'4968','denominator'=>'5'],$v['colecta']);
|
||||
}else{
|
||||
$this->assertSame('absent',$v['acceleration']['status']);$this->assertSame('0',$v['acceleration']['additionalDeduction']['numerator']);$this->assertSame(['numerator'=>'2504','denominator'=>'5'],$v['colecta']);
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['combined', 'autonomous', 'incompatible', 'missing', 'exception', 'negative', 'absent'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-combinations/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-combinations/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$v = $m['special'];
|
||||
$c = $v['combinations'];
|
||||
$this->assertSame('IRPC-normal-adjustments/14', $m['version']);
|
||||
$this->assertSame($b['special']['combinations'], $c['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/13', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame('150', $b['depreciation']['assets'][0]['previousAccounting']);
|
||||
$this->assertSame('100', $b['depreciation']['assets'][0]['previousFiscal']);
|
||||
$this->assertSame('50', $b['depreciation']['assets'][0]['priorAvailable']);
|
||||
$this->assertSame($b['depreciation'], $v['acceleration']['normal']['input']);
|
||||
$this->assertSame(['scope' => 'L8', 'payable' => null, 'recoverable' => null], $v['finalBalance']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if (in_array($case, ['combined', 'autonomous'], true)) {
|
||||
$this->assertSame('compatible', $c['status']);
|
||||
$this->assertSame('25', $v['acceleration']['additionalDeduction']['numerator']);
|
||||
$this->assertSame('15', $c['assetClaims'][0]['priorRecoveredIncluded']['numerator']);
|
||||
$this->assertSame('75', $c['assetClaims'][0]['acceleratedDeduction']['numerator']);
|
||||
$this->assertSame('16', $v['cooperative']['rate']['numerator']);
|
||||
$this->assertSame($case === 'combined' ? '3105' : '3205', $v['taxableBase']['numerator']);
|
||||
$this->assertSame(['numerator' => $case === 'combined' ? '2484' : '2739', 'denominator' => '5'], $v['combinedColecta']);
|
||||
if ($case === 'autonomous') {
|
||||
$this->assertSame('35', $v['expenses']['autonomousTax']['numerator']);
|
||||
$this->assertSame('0', $v['expenses']['rows'][0]['additionalProfitAdjustment']['numerator']);
|
||||
}
|
||||
} elseif (in_array($case, ['incompatible', 'missing', 'exception'], true)) {
|
||||
$this->assertSame($case === 'incompatible' ? 'incompatible' : 'indeterminate', $c['status']);
|
||||
$this->assertNull($v['taxableBase']);
|
||||
$this->assertNull($v['combinedColecta']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $v['cooperative']['status']);
|
||||
$this->assertSame(['numerator' => '4968', 'denominator' => '5'], $v['colecta']);
|
||||
} else {
|
||||
$this->assertSame('absent', $v['acceleration']['status']);
|
||||
$this->assertSame('0', $v['acceleration']['additionalDeduction']['numerator']);
|
||||
$this->assertSame(['numerator' => '2504', 'denominator' => '5'], $v['colecta']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-combinations/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,52 +14,71 @@ final class IrpcSpecialDraftTest extends TestCase
|
||||
|
||||
public function test_special_treatments_recover_with_original_plan_history_and_indeterminate_cases(): 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()]));
|
||||
$id=null;$etag=null;
|
||||
foreach(['expense','missing','negative','absent','cooperative','acceleration'] as $case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-common/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$l7=$m['special'];
|
||||
$this->assertSame('IRPC-normal-adjustments/10',$m['version']);
|
||||
$this->assertSame($b['special'],$l7['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/9',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertArrayHasKey('books',$s);
|
||||
$this->assertNull($m['tax']);$this->assertNull($l7['finalBalance']['payable']);$this->assertNull($l7['finalBalance']['recoverable']);
|
||||
$this->assertSame('123456789',$l7['subjectNuit']);
|
||||
$this->assertStringContainsString('61(4)',$l7['expenses']['source']);
|
||||
if($case==='expense'){
|
||||
$this->assertSame('35',$l7['expenses']['autonomousTax']['numerator']);
|
||||
$this->assertSame('100',$l7['expenses']['rows'][0]['l6Adjustment']['numerator']);
|
||||
$this->assertSame('0',$l7['expenses']['rows'][0]['additionalProfitAdjustment']['numerator']);
|
||||
$this->assertSame($m['taxableProfit'],$l7['taxableProfit']);
|
||||
$this->assertSame(['numerator'=>'5343','denominator'=>'5'],$l7['combinedColecta']);
|
||||
}elseif($case==='missing'){
|
||||
$this->assertSame('indeterminate',$l7['expenses']['status']);$this->assertNull($l7['expenses']['autonomousTax']);$this->assertNull($l7['combinedColecta']);
|
||||
$this->assertSame('3230',$m['taxableProfit']['numerator']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$l7['expenses']['rows'][0]['status']);$this->assertSame('0',$l7['expenses']['autonomousTax']['numerator']);
|
||||
}elseif($case==='absent'){
|
||||
$this->assertSame('absent',$l7['expenses']['status']);$this->assertSame('0',$l7['expenses']['autonomousTax']['numerator']);
|
||||
}elseif($case==='cooperative'){
|
||||
$this->assertSame('16',$l7['cooperative']['rate']['numerator']);$this->assertSame(['numerator'=>'2504','denominator'=>'5'],$l7['colecta']);
|
||||
$this->assertSame(['numerator'=>'5008','denominator'=>'5'],$m['colecta']);
|
||||
}else{
|
||||
$this->assertSame('20',$l7['acceleration']['additionalDeduction']['numerator']);
|
||||
$this->assertSame('150',$l7['acceleration']['accelerated']['assets'][0]['quota']['numerator']);
|
||||
$this->assertSame('120',$l7['acceleration']['accelerated']['assets'][0]['deduction']['numerator']);
|
||||
$this->assertSame('6240',$l7['taxableProfit']['numerator']);$this->assertSame('6260',$m['taxableProfit']['numerator']);
|
||||
$this->assertSame($b['depreciation'],$l7['acceleration']['accelerated']['input']);
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['expense', 'missing', 'negative', 'absent', 'cooperative', 'acceleration'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-common/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-common/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$l7 = $m['special'];
|
||||
$this->assertSame('IRPC-normal-adjustments/10', $m['version']);
|
||||
$this->assertSame($b['special'], $l7['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/9', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
$this->assertArrayHasKey('books', $s);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertNull($l7['finalBalance']['payable']);
|
||||
$this->assertNull($l7['finalBalance']['recoverable']);
|
||||
$this->assertSame('123456789', $l7['subjectNuit']);
|
||||
$this->assertStringContainsString('61(4)', $l7['expenses']['source']);
|
||||
if ($case === 'expense') {
|
||||
$this->assertSame('35', $l7['expenses']['autonomousTax']['numerator']);
|
||||
$this->assertSame('100', $l7['expenses']['rows'][0]['l6Adjustment']['numerator']);
|
||||
$this->assertSame('0', $l7['expenses']['rows'][0]['additionalProfitAdjustment']['numerator']);
|
||||
$this->assertSame($m['taxableProfit'], $l7['taxableProfit']);
|
||||
$this->assertSame(['numerator' => '5343', 'denominator' => '5'], $l7['combinedColecta']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertSame('indeterminate', $l7['expenses']['status']);
|
||||
$this->assertNull($l7['expenses']['autonomousTax']);
|
||||
$this->assertNull($l7['combinedColecta']);
|
||||
$this->assertSame('3230', $m['taxableProfit']['numerator']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $l7['expenses']['rows'][0]['status']);
|
||||
$this->assertSame('0', $l7['expenses']['autonomousTax']['numerator']);
|
||||
} elseif ($case === 'absent') {
|
||||
$this->assertSame('absent', $l7['expenses']['status']);
|
||||
$this->assertSame('0', $l7['expenses']['autonomousTax']['numerator']);
|
||||
} elseif ($case === 'cooperative') {
|
||||
$this->assertSame('16', $l7['cooperative']['rate']['numerator']);
|
||||
$this->assertSame(['numerator' => '2504', 'denominator' => '5'], $l7['colecta']);
|
||||
$this->assertSame(['numerator' => '5008', 'denominator' => '5'], $m['colecta']);
|
||||
} else {
|
||||
$this->assertSame('20', $l7['acceleration']['additionalDeduction']['numerator']);
|
||||
$this->assertSame('150', $l7['acceleration']['accelerated']['assets'][0]['quota']['numerator']);
|
||||
$this->assertSame('120', $l7['acceleration']['accelerated']['assets'][0]['deduction']['numerator']);
|
||||
$this->assertSame('6240', $l7['taxableProfit']['numerator']);
|
||||
$this->assertSame('6260', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame($b['depreciation'], $l7['acceleration']['accelerated']['input']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-common/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,37 +14,71 @@ final class IrpcSpecialMonthlyDraftTest extends TestCase
|
||||
|
||||
public function test_monthly_cbf16_recovers_new_results_missing_cases_and_accepted_history(): 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()]));$id=null;$etag=null;
|
||||
foreach(['monthly','fraction','missing','negative','absent']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-months/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$a=$m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/11',$m['version']);$this->assertSame($b['special']['acceleration']['monthly'],$a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/10',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertSame($b['depreciation'],$a['normal']['input']);$this->assertSame('L8',$m['special']['finalBalance']['scope']);$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if($case==='monthly'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(6,$v['months']);$this->assertSame('50',$v['normalQuota']['numerator']);$this->assertSame('75',$v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60',$v['acceleratedDeduction']['numerator']);$this->assertSame('10',$a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('6310',$m['taxableProfit']['numerator']);$this->assertSame('6300',$m['special']['taxableProfit']['numerator']);$this->assertSame('2016',$m['special']['colecta']['numerator']);
|
||||
$this->assertSame($b['depreciation'],$a['accelerated']['input']);
|
||||
}elseif($case==='fraction'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(1,$v['months']);$this->assertSame(['numerator'=>'25','denominator'=>'3'],$v['normalQuota']);$this->assertSame(['numerator'=>'25','denominator'=>'6'],$a['additionalDeduction']);
|
||||
}elseif($case==='missing'){
|
||||
$this->assertSame('indeterminate',$a['status']);$this->assertNull($a['additionalDeduction']);$this->assertSame('6310',$m['taxableProfit']['numerator']);$this->assertNull($m['special']['colecta']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$a['rows'][0]['status']);$this->assertFalse($a['monthly']['assets'][0]['applied']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
}else{
|
||||
$this->assertSame('absent',$a['status']);$this->assertSame([],$a['monthly']['assets']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['monthly', 'fraction', 'missing', 'negative', 'absent'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-months/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-months/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$a = $m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/11', $m['version']);
|
||||
$this->assertSame($b['special']['acceleration']['monthly'], $a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/10', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame($b['depreciation'], $a['normal']['input']);
|
||||
$this->assertSame('L8', $m['special']['finalBalance']['scope']);
|
||||
$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if ($case === 'monthly') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(6, $v['months']);
|
||||
$this->assertSame('50', $v['normalQuota']['numerator']);
|
||||
$this->assertSame('75', $v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60', $v['acceleratedDeduction']['numerator']);
|
||||
$this->assertSame('10', $a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('6310', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame('6300', $m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame('2016', $m['special']['colecta']['numerator']);
|
||||
$this->assertSame($b['depreciation'], $a['accelerated']['input']);
|
||||
} elseif ($case === 'fraction') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(1, $v['months']);
|
||||
$this->assertSame(['numerator' => '25', 'denominator' => '3'], $v['normalQuota']);
|
||||
$this->assertSame(['numerator' => '25', 'denominator' => '6'], $a['additionalDeduction']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertSame('indeterminate', $a['status']);
|
||||
$this->assertNull($a['additionalDeduction']);
|
||||
$this->assertSame('6310', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['special']['colecta']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $a['rows'][0]['status']);
|
||||
$this->assertFalse($a['monthly']['assets'][0]['applied']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
} else {
|
||||
$this->assertSame('absent', $a['status']);
|
||||
$this->assertSame([], $a['monthly']['assets']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-months/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,37 +14,75 @@ final class IrpcSpecialStartPeriodDraftTest extends TestCase
|
||||
|
||||
public function test_start_period_cbf16_recovers_new_results_missing_cases_and_accepted_history(): 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()]));$id=null;$etag=null;
|
||||
foreach(['start','fraction','missing','negative','absent']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-start-period/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
|
||||
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
|
||||
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$a=$m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/12',$m['version']);$this->assertSame($b['special']['acceleration']['monthly'],$a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/11',array_column(array_column($b['history'],'model'),'version'));$this->assertContains('IRPC-normal-adjustments/10',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertSame($b['depreciation'],$a['normal']['input']);$this->assertSame('L8',$m['special']['finalBalance']['scope']);$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if($case==='start'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(6,$v['months']);$this->assertSame('50',$v['normalQuota']['numerator']);$this->assertSame('75',$v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60',$v['acceleratedDeduction']['numerator']);$this->assertSame('10',$a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertSame('3120',$m['special']['taxableProfit']['numerator']);$this->assertSame(['numerator'=>'4992','denominator'=>'5'],$m['special']['colecta']);$this->assertTrue($m['periodsFx']['short']);$this->assertSame('2026-07-01',$a['monthly']['period']['from']);$this->assertStringContainsString('início de actividade',$a['source']);
|
||||
$this->assertSame($b['depreciation'],$a['accelerated']['input']);
|
||||
}elseif($case==='fraction'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(1,$v['months']);$this->assertSame(['numerator'=>'25','denominator'=>'3'],$v['normalQuota']);$this->assertSame(['numerator'=>'5','denominator'=>'3'],$a['additionalDeduction']);
|
||||
}elseif($case==='missing'){
|
||||
$this->assertSame('indeterminate',$a['status']);$this->assertNull($a['additionalDeduction']);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertNull($m['special']['colecta']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$a['rows'][0]['status']);$this->assertFalse($a['monthly']['assets'][0]['applied']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
}else{
|
||||
$this->assertSame('absent',$a['status']);$this->assertSame([],$a['monthly']['assets']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
$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()]));
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['start', 'fraction', 'missing', 'negative', 'absent'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-start-period/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-start-period/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$etag = $r->headers->get('ETag');
|
||||
$back = $r->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['irpcNormal'][$d['context_opportunity']];
|
||||
$m = $b['result']['model'];
|
||||
$a = $m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/12', $m['version']);
|
||||
$this->assertSame($b['special']['acceleration']['monthly'], $a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/11', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertContains('IRPC-normal-adjustments/10', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame($b['depreciation'], $a['normal']['input']);
|
||||
$this->assertSame('L8', $m['special']['finalBalance']['scope']);
|
||||
$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if ($case === 'start') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(6, $v['months']);
|
||||
$this->assertSame('50', $v['normalQuota']['numerator']);
|
||||
$this->assertSame('75', $v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60', $v['acceleratedDeduction']['numerator']);
|
||||
$this->assertSame('10', $a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame('3120', $m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame(['numerator' => '4992', 'denominator' => '5'], $m['special']['colecta']);
|
||||
$this->assertTrue($m['periodsFx']['short']);
|
||||
$this->assertSame('2026-07-01', $a['monthly']['period']['from']);
|
||||
$this->assertStringContainsString('início de actividade', $a['source']);
|
||||
$this->assertSame($b['depreciation'], $a['accelerated']['input']);
|
||||
} elseif ($case === 'fraction') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(1, $v['months']);
|
||||
$this->assertSame(['numerator' => '25', 'denominator' => '3'], $v['normalQuota']);
|
||||
$this->assertSame(['numerator' => '5', 'denominator' => '3'], $a['additionalDeduction']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertSame('indeterminate', $a['status']);
|
||||
$this->assertNull($a['additionalDeduction']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['special']['colecta']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $a['rows'][0]['status']);
|
||||
$this->assertFalse($a['monthly']['assets'][0]['applied']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
} else {
|
||||
$this->assertSame('absent', $a['status']);
|
||||
$this->assertSame([], $a['monthly']['assets']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-start-period/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,47 @@
|
||||
<?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 IrpcWithholdingDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_irpc_recovers_private_retentions_payments_and_history_without_changing_installed_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()]));
|
||||
$d=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$key=$d['context_opportunity'];$b=$s['irpcWithholdings'][$key];$this->assertSame('calculated',$b['result']['rows'][0]['status']);$this->assertSame(['numerator'=>'10000','denominator'=>'1'],$b['result']['rows'][0]['tax']);$this->assertSame(['numerator'=>'6000','denominator'=>'1'],$b['result']['rows'][0]['settled']);$this->assertSame(['numerator'=>'4000','denominator'=>'1'],$b['result']['rows'][0]['outstanding']);$this->assertSame('2026-10',$b['result']['rows'][0]['period']);$this->assertSame('received',$b['result']['rows'][1]['direction']);$this->assertSame(['numerator'=>'2000','denominator'=>'1'],$b['result']['rows'][1]['tax']);$this->assertSame(['numerator'=>'500','denominator'=>'1'],$b['result']['rows'][1]['outstanding']);
|
||||
$old=json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-residual-preserved.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($old['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR)as$k=>$v)$this->assertSame($v,$s[$k],$k.' must be preserved');
|
||||
if(is_dir(base_path('outputs/irpc-l5-20261025')))file_put_contents(base_path('outputs/irpc-l5-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_irpc_recovers_private_retentions_payments_and_history_without_changing_installed_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()]));
|
||||
$d = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$key = $d['context_opportunity'];
|
||||
$b = $s['irpcWithholdings'][$key];
|
||||
$this->assertSame('calculated', $b['result']['rows'][0]['status']);
|
||||
$this->assertSame(['numerator' => '10000', 'denominator' => '1'], $b['result']['rows'][0]['tax']);
|
||||
$this->assertSame(['numerator' => '6000', 'denominator' => '1'], $b['result']['rows'][0]['settled']);
|
||||
$this->assertSame(['numerator' => '4000', 'denominator' => '1'], $b['result']['rows'][0]['outstanding']);
|
||||
$this->assertSame('2026-10', $b['result']['rows'][0]['period']);
|
||||
$this->assertSame('received', $b['result']['rows'][1]['direction']);
|
||||
$this->assertSame(['numerator' => '2000', 'denominator' => '1'], $b['result']['rows'][1]['tax']);
|
||||
$this->assertSame(['numerator' => '500', 'denominator' => '1'], $b['result']['rows'][1]['outstanding']);
|
||||
$old = json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-residual-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($old['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $k => $v) {
|
||||
$this->assertSame($v, $s[$k], $k.' must be preserved');
|
||||
}
|
||||
if (is_dir(base_path('outputs/irpc-l5-20261025'))) {
|
||||
file_put_contents(base_path('outputs/irpc-l5-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,51 @@
|
||||
<?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 IspcQuarterDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_quarter_and_option_recover_privately_without_changing_accepted_fiscal_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]);$actor=User::factory()->create(['email_verified_at'=>now()]);$this->actingAs($actor);
|
||||
$draft=json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-quarter-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>'collective'];unset($draft['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'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']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$r=$s['ispcQuarters']['opportunity:375']['result'];$this->assertSame('calculated',$r['status']);$this->assertSame(['numerator'=>'24000','denominator'=>'1'],$r['tax']);$this->assertSame($r['tax'],$r['payment']);$this->assertTrue($r['declaration']);$this->assertFalse($r['projected']);$this->assertSame('recorded',$r['eligibility']['optionStatus']);$this->assertSame('SYNTHETIC QA opção ISPC2026',$r['eligibility']['input']['optionReference']);$this->assertNotEmpty($s['ispcQuarters']['opportunity:375']['history']);
|
||||
$seed=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3e-preserved.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($seed['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR)as$key=>$value)$this->assertSame($value,$s[$key]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));$this->getJson('/api/v1/simulation-drafts/'.$id)->assertNotFound();$this->actingAs($actor);$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
if(is_dir(base_path('outputs/ispc-l4b-20261025')))file_put_contents(base_path('outputs/ispc-l4b-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_quarter_and_option_recover_privately_without_changing_accepted_fiscal_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]);
|
||||
$actor = User::factory()->create(['email_verified_at' => now()]);
|
||||
$this->actingAs($actor);
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-quarter-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => 'collective'];
|
||||
unset($draft['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$r = $s['ispcQuarters']['opportunity:375']['result'];
|
||||
$this->assertSame('calculated', $r['status']);
|
||||
$this->assertSame(['numerator' => '24000', 'denominator' => '1'], $r['tax']);
|
||||
$this->assertSame($r['tax'], $r['payment']);
|
||||
$this->assertTrue($r['declaration']);
|
||||
$this->assertFalse($r['projected']);
|
||||
$this->assertSame('recorded', $r['eligibility']['optionStatus']);
|
||||
$this->assertSame('SYNTHETIC QA opção ISPC2026', $r['eligibility']['input']['optionReference']);
|
||||
$this->assertNotEmpty($s['ispcQuarters']['opportunity:375']['history']);
|
||||
$seed = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3e-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($seed['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $value) {
|
||||
$this->assertSame($value, $s[$key]);
|
||||
}
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$this->getJson('/api/v1/simulation-drafts/'.$id)->assertNotFound();
|
||||
$this->actingAs($actor);
|
||||
$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
if (is_dir(base_path('outputs/ispc-l4b-20261025'))) {
|
||||
file_put_contents(base_path('outputs/ispc-l4b-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,56 @@
|
||||
<?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 IspcResidualDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_new_residual_books_recover_without_rewriting_installed_habitual_or_L3_results():void
|
||||
{
|
||||
$t=DB::selectOne('select current_database() as name,inet_server_port() as port');$this->assertSame('simulator_fiscal_delta_20261021_test',$t->name);$this->assertSame(55441,(int)$t->port);config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));
|
||||
$d=json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-residual-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$own=$s['ispcResiduals']['opportunity:376']['occasional']['result'];$this->assertSame('calculated',$own['status']);$this->assertSame(['numerator'=>'3000','denominator'=>'1'],$own['amounts']['tax']);$this->assertSame('singular',$own['input']['personType']);
|
||||
$a=$s['ispcResiduals']['opportunity:375']['acquisitions']['result'];$this->assertSame('calculated',$a['status']);$this->assertSame(['numerator'=>'5000','denominator'=>'1'],$a['amounts']['coveredTax']);$this->assertSame(['numerator'=>'20000','denominator'=>'1'],$a['amounts']['excessTax']);$this->assertSame(['numerator'=>'25000','denominator'=>'1'],$a['amounts']['total']);
|
||||
$this->assertSame('partial',$s['ispcResiduals']['opportunity:375']['formalities']['result']['status']);$this->assertStringContainsString('Indeterminado',$s['ispcResiduals']['opportunity:375']['formalities']['result']['details']['formPeriod']);
|
||||
$old=json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-quarter-preserved.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($old['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR)as$key=>$value){if($key==='ispcWithholdings')continue;if($key==='ispcEligibility'){foreach($value as$ctx=>$book)$this->assertSame($book,$s[$key][$ctx]);}else$this->assertSame($value,$s[$key]);}
|
||||
if(is_dir(base_path('outputs/ispc-residuals-20261025')))file_put_contents(base_path('outputs/ispc-residuals-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_new_residual_books_recover_without_rewriting_installed_habitual_or_l3_results(): void
|
||||
{
|
||||
$t = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $t->name);
|
||||
$this->assertSame(55441, (int) $t->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$d = json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-residual-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$own = $s['ispcResiduals']['opportunity:376']['occasional']['result'];
|
||||
$this->assertSame('calculated', $own['status']);
|
||||
$this->assertSame(['numerator' => '3000', 'denominator' => '1'], $own['amounts']['tax']);
|
||||
$this->assertSame('singular', $own['input']['personType']);
|
||||
$a = $s['ispcResiduals']['opportunity:375']['acquisitions']['result'];
|
||||
$this->assertSame('calculated', $a['status']);
|
||||
$this->assertSame(['numerator' => '5000', 'denominator' => '1'], $a['amounts']['coveredTax']);
|
||||
$this->assertSame(['numerator' => '20000', 'denominator' => '1'], $a['amounts']['excessTax']);
|
||||
$this->assertSame(['numerator' => '25000', 'denominator' => '1'], $a['amounts']['total']);
|
||||
$this->assertSame('partial', $s['ispcResiduals']['opportunity:375']['formalities']['result']['status']);
|
||||
$this->assertStringContainsString('Indeterminado', $s['ispcResiduals']['opportunity:375']['formalities']['result']['details']['formPeriod']);
|
||||
$old = json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-quarter-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($old['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $value) {
|
||||
if ($key === 'ispcWithholdings') {
|
||||
continue;
|
||||
}if ($key === 'ispcEligibility') {
|
||||
foreach ($value as $ctx => $book) {
|
||||
$this->assertSame($book, $s[$key][$ctx]);
|
||||
}
|
||||
} else {
|
||||
$this->assertSame($value, $s[$key]);
|
||||
}
|
||||
}
|
||||
if (is_dir(base_path('outputs/ispc-residuals-20261025'))) {
|
||||
file_put_contents(base_path('outputs/ispc-residuals-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -11,7 +12,7 @@ final class IvaAcquisitionAllocationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_allocation_recovers_with_exact_fractions_and_preserved_ABC(): void
|
||||
public function test_allocation_recovers_with_exact_fractions_and_preserved_abc(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
@@ -25,23 +26,27 @@ final class IvaAcquisitionAllocationDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['books']['opportunity:370'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['eligible','eligible','eligible','eligible'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame(['eligible', 'eligible', 'eligible', 'eligible'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame('24.16', $book['result']['periods'][0]['fields']['15']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('10.72', $book['result']['periods'][0]['fields']['11']);
|
||||
$this->assertSame('135.84', $book['result']['periods'][0]['fields']['17']);
|
||||
$this->assertSame('customs', $book['rows'][3]['documentType']);
|
||||
$this->assertSame('actual', $book['rows'][0]['d']['method']);
|
||||
$this->assertSame(['numerator'=>'16','denominator'=>'3'], $book['result']['rows'][0]['deductibleExact']);
|
||||
$this->assertSame(['numerator'=>'17','denominator'=>'50'], $book['result']['rows'][1]['allocationCalculation']['ratio']);
|
||||
$this->assertSame(['numerator' => '16', 'denominator' => '3'], $book['result']['rows'][0]['deductibleExact']);
|
||||
$this->assertSame(['numerator' => '17', 'denominator' => '50'], $book['result']['rows'][1]['allocationCalculation']['ratio']);
|
||||
$this->assertSame('yes', $book['rows'][0]['d']['facts']['communication']);
|
||||
$this->assertSame('6.40', $store['books']['opportunity:371']['result']['periods'][0]['fields']['15']);
|
||||
$this->assertNull($store['books']['opportunity:371']['result']['periods'][0]['fields']['16']);
|
||||
$this->assertSame('public_works', $store['books']['opportunity:371']['rows'][0]['d']['reducedId']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2d-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') continue;
|
||||
foreach ($map as $context => $original) $this->assertSame($original, $store[$key][$context]);
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}
|
||||
foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $store[$key][$context]);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-d-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -11,7 +12,7 @@ final class IvaAcquisitionBCDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_customs_exclusions_recover_with_sources_totals_history_and_preserved_A(): void
|
||||
public function test_customs_exclusions_recover_with_sources_totals_history_and_preserved_a(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
@@ -25,7 +26,7 @@ final class IvaAcquisitionBCDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['books']['opportunity:369'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['eligible','eligible','no_right','eligible'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame(['eligible', 'eligible', 'no_right', 'eligible'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame('40.00', $book['result']['periods'][0]['fields']['15']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('16.00', $book['result']['periods'][0]['fields']['11']);
|
||||
@@ -34,8 +35,12 @@ final class IvaAcquisitionBCDraftTest extends TestCase
|
||||
$this->assertSame('yes', $book['rows'][0]['bc']['belongs']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2bc-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') continue;
|
||||
foreach ($map as $context => $original) $this->assertSame($original, $store[$key][$context]);
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}
|
||||
foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $store[$key][$context]);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-bc-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -25,13 +26,17 @@ final class IvaAcquisitionRightDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['books']['opportunity:368'];
|
||||
$this->assertCount(5, $book['rows']);
|
||||
$this->assertSame(['eligible','eligible','eligible','no_right','no_right'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame(['eligible', 'eligible', 'eligible', 'no_right', 'no_right'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
||||
$this->assertSame('48.00', $book['result']['periods'][0]['fields']['15']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2a-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') continue;
|
||||
foreach ($map as $context => $original) $this->assertSame($original, $store[$key][$context]);
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}
|
||||
foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $store[$key][$context]);
|
||||
}
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-a-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,12 +28,12 @@ final class IvaActSaleBaseDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['actSaleBases']['opportunity:341'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['act_sale_amount','act_normal_value'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1500.25','2200.50'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['auction','settlement'], array_column($book['rows'], 'actKind'));
|
||||
$this->assertSame(['act_sale_amount', 'act_normal_value'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1500.25', '2200.50'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['auction', 'settlement'], array_column($book['rows'], 'actKind'));
|
||||
$this->assertSame('1500.25', $book['rows'][0]['actValue']);
|
||||
$this->assertSame('2200.50', $book['rows'][0]['normalValue']);
|
||||
$this->assertStringContainsString('acto A', $book['rows'][0]['actRef']);
|
||||
@@ -52,4 +53,3 @@ final class IvaActSaleBaseDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g7c-act-bases-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaAgroDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_agro_context_preserves_accepted_opportunities(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -27,7 +29,11 @@ final class IvaAgroDraftTest extends TestCase
|
||||
$this->assertSame('100.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2E_RECOVERED')) file_put_contents(getenv('IVA_G2E_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
if (getenv('IVA_G2E_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2E_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaAnnexIDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_annex_i_and_explicit_continuations_recover_in_their_selected_opportunity(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -39,6 +41,8 @@ final class IvaAnnexIDraftTest extends TestCase
|
||||
foreach (json_decode($original['modelo_a_snapshot'], true)['salesOperations'] as $key => $value) {
|
||||
$this->assertSame($value, $store['salesOperations'][$key]);
|
||||
}
|
||||
if (getenv('IVA_G2L_RECOVERED')) file_put_contents(getenv('IVA_G2L_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
if (getenv('IVA_G2L_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2L_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +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 IvaBaggageDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_baggage_recovers_without_vehicle_constraints_or_changes_to128_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-baggage.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:366',$recovered['context_opportunity']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['returneeImports']['opportunity:366'];$this->assertCount(11,$b['rows']);$this->assertCount(1,$b['history']);$this->assertSame($b['rows'],$b['result']['inputs']);
|
||||
foreach($b['result']['rows'] as $row){$this->assertSame('exempt',$row['status']);$this->assertSame('0.00',$row['importVat']);$this->assertNull($row['deduction']);$this->assertStringContainsString('57(2)c/d',$row['source']);}
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-baggage-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$prior=json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$this->assertSame(array_diff_key($prior,['returneeImports'=>true]),array_diff_key($s,['returneeImports'=>true]));foreach($prior['returneeImports'] as $key=>$value)$this->assertSame($value,$s['returneeImports'][$key]);
|
||||
$path=base_path('outputs/iva-l1-residuals-baggage-20261025');if(!is_dir($path))mkdir($path,0775,true);file_put_contents($path.'/recovered.json',json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_baggage_recovers_without_vehicle_constraints_or_changes_to128_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-baggage.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:366', $recovered['context_opportunity']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['returneeImports']['opportunity:366'];
|
||||
$this->assertCount(11, $b['rows']);
|
||||
$this->assertCount(1, $b['history']);
|
||||
$this->assertSame($b['rows'], $b['result']['inputs']);
|
||||
foreach ($b['result']['rows'] as $row) {
|
||||
$this->assertSame('exempt', $row['status']);
|
||||
$this->assertSame('0.00', $row['importVat']);
|
||||
$this->assertNull($row['deduction']);
|
||||
$this->assertStringContainsString('57(2)c/d', $row['source']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-baggage-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame(array_diff_key($prior, ['returneeImports' => true]), array_diff_key($s, ['returneeImports' => true]));
|
||||
foreach ($prior['returneeImports'] as $key => $value) {
|
||||
$this->assertSame($value, $s['returneeImports'][$key]);
|
||||
}
|
||||
$path = base_path('outputs/iva-l1-residuals-baggage-20261025');
|
||||
if (! is_dir($path)) {
|
||||
mkdir($path, 0775, true);
|
||||
}file_put_contents($path.'/recovered.json', json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,61 @@
|
||||
<?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 IvaBeveragePartitionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_partition_recovery_preserves_prior_effective_deduction_without_reusing_it_for_restitution(): 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('outputs/iva-l3-e-partitions-20261025/calculated.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']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$book=$s['ivaBeverageRestitutions']['opportunity:375'];
|
||||
$this->assertSame(['numerator'=>'10','denominator'=>'1'],$book['result']['rows'][0]['requested']);
|
||||
$this->assertSame('determined',$book['result']['rows'][0]['status']);
|
||||
$this->assertNull($book['result']['rows'][0]['approved']);$this->assertNull($book['result']['rows'][0]['received']);
|
||||
$allocation=$book['result']['inputs'][0]['allocation'];
|
||||
foreach(['from'=>'6','to'=>'16','deductionFrom'=>'0','deductionTo'=>'6']as$key=>$value)$this->assertSame($value,$allocation[$key]);
|
||||
$this->assertNotEmpty($allocation['reference']);$this->assertNotEmpty($allocation['deductionReference']);
|
||||
$originalDeductions=[];foreach($s['books']['opportunity:375']['history']as$calc)foreach($calc['rows']as$row)if($row['id']==='beverage-purchase')$originalDeductions[]=$row['deductibleExact']??null;
|
||||
$this->assertContains(['numerator'=>'6','denominator'=>'1'],$originalDeductions);
|
||||
foreach(['iva-l3e-preserved','iva-l3ab-preserved']as$fixture){$accepted=json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($accepted['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR)as$key=>$map){if($key==='version')continue;foreach($map as$context=>$original)$this->assertSame($original,$s[$key][$context]);}}
|
||||
$this->assertSame(['numerator'=>'72','denominator'=>'1'],$s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);
|
||||
$this->assertSame(['numerator'=>'450000','denominator'=>'1'],$s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
|
||||
file_put_contents(base_path('outputs/iva-l3-e-partitions-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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('outputs/iva-l3-e-partitions-20261025/calculated.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']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $s['ivaBeverageRestitutions']['opportunity:375'];
|
||||
$this->assertSame(['numerator' => '10', 'denominator' => '1'], $book['result']['rows'][0]['requested']);
|
||||
$this->assertSame('determined', $book['result']['rows'][0]['status']);
|
||||
$this->assertNull($book['result']['rows'][0]['approved']);
|
||||
$this->assertNull($book['result']['rows'][0]['received']);
|
||||
$allocation = $book['result']['inputs'][0]['allocation'];
|
||||
foreach (['from' => '6', 'to' => '16', 'deductionFrom' => '0', 'deductionTo' => '6'] as $key => $value) {
|
||||
$this->assertSame($value, $allocation[$key]);
|
||||
}
|
||||
$this->assertNotEmpty($allocation['reference']);
|
||||
$this->assertNotEmpty($allocation['deductionReference']);
|
||||
$originalDeductions = [];
|
||||
foreach ($s['books']['opportunity:375']['history'] as $calc) {
|
||||
foreach ($calc['rows'] as $row) {
|
||||
if ($row['id'] === 'beverage-purchase') {
|
||||
$originalDeductions[] = $row['deductibleExact'] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertContains(['numerator' => '6', 'denominator' => '1'], $originalDeductions);
|
||||
foreach (['iva-l3e-preserved', 'iva-l3ab-preserved'] as $fixture) {
|
||||
$accepted = json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($accepted['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $s[$key][$context]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertSame(['numerator' => '72', 'denominator' => '1'], $s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);
|
||||
$this->assertSame(['numerator' => '450000', 'denominator' => '1'], $s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
|
||||
file_put_contents(base_path('outputs/iva-l3-e-partitions-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,57 @@
|
||||
<?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 IvaBeverageRestitutionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_beverage_restitution_recovers_invoice_classification_exclusive_route_decision_receipt_and_all_previous_maps(): 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('outputs/iva-l3-e-20261025/calculated.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']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['ivaBeverageRestitutions']['opportunity:375'];$this->assertCount(1,$b['rows']);$this->assertCount(1,$b['history']);$r=$b['result']['rows'][0];$this->assertSame('determined',$r['status']);
|
||||
foreach(['requested'=>'16','approved'=>'12','received'=>'7','awaitingReceipt'=>'5','notGranted'=>'4']as $f=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$r[$f]);
|
||||
$i=$b['result']['inputs'][0];$this->assertSame('SYNTHETIC QA facturaBE1',$i['source']['documentRef']);$this->assertSame('1-bebidas',$i['source']['documentLine']);$this->assertSame('beverage-supply',$i['source']['operationId']);$this->assertSame('yes',$i['exclusive']);$this->assertSame('SYNTHETIC QA decisãoBE1',$i['decisionReference']);
|
||||
$this->assertSame('0.00',$s['books']['opportunity:375']['result']['rows'][0]['deductible']);$this->assertSame('refund',$s['books']['opportunity:375']['rows'][0]['bc']['beveragePath']);
|
||||
foreach(['iva-l3e-preserved','iva-l3ab-preserved']as $fixture){$accepted=json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($accepted['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR)as $key=>$map){if($key==='version')continue;foreach($map as $context=>$original)$this->assertSame($original,$s[$key][$context]);}}
|
||||
$this->assertSame(['numerator'=>'72','denominator'=>'1'],$s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);$this->assertSame(['numerator'=>'450000','denominator'=>'1'],$s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
|
||||
file_put_contents(base_path('outputs/iva-l3-e-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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('outputs/iva-l3-e-20261025/calculated.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']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['ivaBeverageRestitutions']['opportunity:375'];
|
||||
$this->assertCount(1, $b['rows']);
|
||||
$this->assertCount(1, $b['history']);
|
||||
$r = $b['result']['rows'][0];
|
||||
$this->assertSame('determined', $r['status']);
|
||||
foreach (['requested' => '16', 'approved' => '12', 'received' => '7', 'awaitingReceipt' => '5', 'notGranted' => '4'] as $f => $v) {
|
||||
$this->assertSame(['numerator' => $v, 'denominator' => '1'], $r[$f]);
|
||||
}
|
||||
$i = $b['result']['inputs'][0];
|
||||
$this->assertSame('SYNTHETIC QA facturaBE1', $i['source']['documentRef']);
|
||||
$this->assertSame('1-bebidas', $i['source']['documentLine']);
|
||||
$this->assertSame('beverage-supply', $i['source']['operationId']);
|
||||
$this->assertSame('yes', $i['exclusive']);
|
||||
$this->assertSame('SYNTHETIC QA decisãoBE1', $i['decisionReference']);
|
||||
$this->assertSame('0.00', $s['books']['opportunity:375']['result']['rows'][0]['deductible']);
|
||||
$this->assertSame('refund', $s['books']['opportunity:375']['rows'][0]['bc']['beveragePath']);
|
||||
foreach (['iva-l3e-preserved', 'iva-l3ab-preserved'] as $fixture) {
|
||||
$accepted = json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($accepted['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $s[$key][$context]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertSame(['numerator' => '72', 'denominator' => '1'], $s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);
|
||||
$this->assertSame(['numerator' => '450000', 'denominator' => '1'], $s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
|
||||
file_put_contents(base_path('outputs/iva-l3-e-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,55 @@
|
||||
<?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 IvaClosureDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_three_period_closure_recovers_exact_credits_payments_history_and_prior_L1_L2_maps(): void
|
||||
|
||||
public function test_three_period_closure_recovers_exact_credits_payments_history_and_prior_l1_l2_maps(): 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('outputs/iva-l3-ab-20261025/calculated.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']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['ivaClosures']['opportunity:373'];$this->assertCount(3,$b['rows']);$this->assertCount(2,$b['history']);
|
||||
$this->assertSame(['determined','determined','determined'],array_column($b['result']['rows'],'status'));
|
||||
foreach([0=>'150',1=>'70',2=>'0'] as $i=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$b['result']['rows'][$i]['fields']['26']);
|
||||
$r=$b['result']['rows'][2];foreach(['19'=>'70','20'=>'20','22'=>'70','23'=>'2','24'=>'72','25'=>'0'] as $field=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$r['fields'][(string)$field]);
|
||||
$this->assertSame(['numerator'=>'30','denominator'=>'1'],$r['paid']);$this->assertSame(['numerator'=>'42','denominator'=>'1'],$r['outstanding']);
|
||||
$this->assertSame('2025-12',$b['result']['inputs'][0]['credits'][0]['period']);$this->assertSame('SYNTHETIC QA saldoabertura',$b['result']['inputs'][0]['credits'][0]['reference']);
|
||||
$this->assertSame('2026-03-10',$b['result']['inputs'][2]['credits'][1]['date']);
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3ab-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
foreach(json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR) as $key=>$map){if($key==='version')continue;foreach($map as $context=>$original)$this->assertSame($original,$s[$key][$context]);}
|
||||
$this->assertSame('100.00',$s['books']['opportunity:373']['result']['periods'][0]['fields']['18']);
|
||||
$this->assertSame('160.00',$s['books']['opportunity:373']['result']['periods'][2]['fields']['17']);
|
||||
file_put_contents(base_path('outputs/iva-l3-ab-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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('outputs/iva-l3-ab-20261025/calculated.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']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['ivaClosures']['opportunity:373'];
|
||||
$this->assertCount(3, $b['rows']);
|
||||
$this->assertCount(2, $b['history']);
|
||||
$this->assertSame(['determined', 'determined', 'determined'], array_column($b['result']['rows'], 'status'));
|
||||
foreach ([0 => '150', 1 => '70', 2 => '0'] as $i => $v) {
|
||||
$this->assertSame(['numerator' => $v, 'denominator' => '1'], $b['result']['rows'][$i]['fields']['26']);
|
||||
}
|
||||
$r = $b['result']['rows'][2];
|
||||
foreach (['19' => '70', '20' => '20', '22' => '70', '23' => '2', '24' => '72', '25' => '0'] as $field => $v) {
|
||||
$this->assertSame(['numerator' => $v, 'denominator' => '1'], $r['fields'][(string) $field]);
|
||||
}
|
||||
$this->assertSame(['numerator' => '30', 'denominator' => '1'], $r['paid']);
|
||||
$this->assertSame(['numerator' => '42', 'denominator' => '1'], $r['outstanding']);
|
||||
$this->assertSame('2025-12', $b['result']['inputs'][0]['credits'][0]['period']);
|
||||
$this->assertSame('SYNTHETIC QA saldoabertura', $b['result']['inputs'][0]['credits'][0]['reference']);
|
||||
$this->assertSame('2026-03-10', $b['result']['inputs'][2]['credits'][1]['date']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3ab-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
||||
if ($key === 'version') {
|
||||
continue;
|
||||
}foreach ($map as $context => $original) {
|
||||
$this->assertSame($original, $s[$key][$context]);
|
||||
}
|
||||
}
|
||||
$this->assertSame('100.00', $s['books']['opportunity:373']['result']['periods'][0]['fields']['18']);
|
||||
$this->assertSame('160.00', $s['books']['opportunity:373']['result']['periods'][2]['fields']['17']);
|
||||
file_put_contents(base_path('outputs/iva-l3-ab-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,11 +28,11 @@ final class IvaCommissionBaseDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['commissionBases']['opportunity:340'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['commission_sale_transfer','commission_purchase_transfer'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['900.15','1100.35'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['commission_sale_transfer', 'commission_purchase_transfer'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['900.15', '1100.35'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame('SYNTHETIC QA comitente', $book['rows'][0]['principal']);
|
||||
$this->assertSame('SYNTHETIC QA comissário', $book['rows'][0]['agent']);
|
||||
$this->assertSame('1000.25', $book['rows'][0]['agreedPrice']);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -28,15 +29,15 @@ final class IvaCompositionBaseDraftTest extends TestCase
|
||||
$book = $store['considerationCompositions']['opportunity:344'];
|
||||
$this->assertCount(1, $book['rows']);
|
||||
$this->assertCount(2, $book['rows'][0]['parts']);
|
||||
$this->assertSame(['tax_component','accessory_component'], array_column($book['rows'][0]['parts'], 'treatment'));
|
||||
$this->assertSame(['tax_component', 'accessory_component'], array_column($book['rows'][0]['parts'], 'treatment'));
|
||||
$this->assertSame(['1150.60'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame('1000.25', $book['rows'][0]['initialAmount']);
|
||||
$this->assertSame(['100.10','50.25'], array_column($book['rows'][0]['parts'], 'amount'));
|
||||
$this->assertSame(['no','no'], array_column($book['rows'][0]['parts'], 'included'));
|
||||
$this->assertSame(['yes','yes'], array_column($book['rows'][0]['parts'], 'ownVatExcluded'));
|
||||
$this->assertSame(['100.10', '50.25'], array_column($book['rows'][0]['parts'], 'amount'));
|
||||
$this->assertSame(['no', 'no'], array_column($book['rows'][0]['parts'], 'included'));
|
||||
$this->assertSame(['yes', 'yes'], array_column($book['rows'][0]['parts'], 'ownVatExcluded'));
|
||||
$this->assertStringContainsString('operação A', $book['rows'][0]['operationRef']);
|
||||
$this->assertStringContainsString('próprioIVA', $book['rows'][0]['initialRef']);
|
||||
$this->assertStringContainsString('referência tax_component', $book['rows'][0]['parts'][0]['reference']);
|
||||
@@ -55,4 +56,3 @@ final class IvaCompositionBaseDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g7f-composition-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaConditionalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_conditional_context_preserves_accepted_opportunities(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -27,7 +29,11 @@ final class IvaConditionalDraftTest extends TestCase
|
||||
$this->assertSame('0.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2G_RECOVERED')) file_put_contents(getenv('IVA_G2G_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
if (getenv('IVA_G2G_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2G_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaCulturalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_cultural_context_preserves_accepted_opportunities(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -26,7 +28,11 @@ final class IvaCulturalDraftTest extends TestCase
|
||||
$this->assertSame('500.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2C_RECOVERED')) file_put_contents(getenv('IVA_G2C_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
if (getenv('IVA_G2C_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2C_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,16 +28,18 @@ final class IvaCurrencyEventDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['currencyEvents']['opportunity:357'];
|
||||
$this->assertCount(15, $book['rows']);
|
||||
$this->assertSame('conditional',$book['result']['rows'][0]['status']);
|
||||
$this->assertSame('64500.00',$book['result']['rows'][0]['scenarioAmount']);
|
||||
$this->assertSame('2026-12-10',$book['result']['rows'][13]['eventDate']);
|
||||
$this->assertSame(['200.00','800.00'],array_column($book['result']['rows'][14]['dueEvents'],'amount'));
|
||||
$this->assertSame('conditional', $book['result']['rows'][0]['status']);
|
||||
$this->assertSame('64500.00', $book['result']['rows'][0]['scenarioAmount']);
|
||||
$this->assertSame('2026-12-10', $book['result']['rows'][13]['eventDate']);
|
||||
$this->assertSame(['200.00', '800.00'], array_column($book['result']['rows'][14]['dueEvents'], 'amount'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$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->assertSame('64500.00',$book['history'][0]['rows'][0]['scenarioAmount']);
|
||||
$this->assertSame('64500.00', $book['history'][0]['rows'][0]['scenarioAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-currency-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, ['currencyEvents' => true]));
|
||||
@@ -47,4 +50,3 @@ final class IvaCurrencyEventDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-currency-events-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,21 +28,24 @@ final class IvaDigitalDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['digitalOperations']['opportunity:359'];
|
||||
$this->assertCount(46, $book['rows']);
|
||||
$this->assertSame('national',$book['result']['rows'][0]['territory']);
|
||||
$this->assertSame('acquirer',$book['result']['rows'][0]['responsible']);
|
||||
$this->assertSame('2027-01-10',$book['result']['rows'][0]['declarationReferenceDate']);
|
||||
$this->assertSame('outside',$book['result']['rows'][1]['territory']);
|
||||
$this->assertSame('provider',$book['result']['rows'][2]['responsible']);
|
||||
$this->assertSame('national',$book['result']['rows'][42]['territory']);
|
||||
$this->assertSame('indeterminate',$book['result']['rows'][42]['responsible']);
|
||||
$this->assertSame('representative',$book['result']['rows'][44]['responsible']);
|
||||
$this->assertSame('acquirer',$book['result']['rows'][45]['responsible']);
|
||||
$this->assertSame('national', $book['result']['rows'][0]['territory']);
|
||||
$this->assertSame('acquirer', $book['result']['rows'][0]['responsible']);
|
||||
$this->assertSame('2027-01-10', $book['result']['rows'][0]['declarationReferenceDate']);
|
||||
$this->assertSame('outside', $book['result']['rows'][1]['territory']);
|
||||
$this->assertSame('provider', $book['result']['rows'][2]['responsible']);
|
||||
$this->assertSame('national', $book['result']['rows'][42]['territory']);
|
||||
$this->assertSame('indeterminate', $book['result']['rows'][42]['responsible']);
|
||||
$this->assertSame('representative', $book['result']['rows'][44]['responsible']);
|
||||
$this->assertSame('acquirer', $book['result']['rows'][45]['responsible']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['deduction']);$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$this->assertNull($row['deduction']);
|
||||
$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->assertSame('national',$book['history'][0]['rows'][0]['territory']);
|
||||
$this->assertSame('national', $book['history'][0]['rows'][0]['territory']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-digital-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$preserved = array_diff_key($store, ['digitalOperations' => true]);
|
||||
@@ -53,4 +57,3 @@ final class IvaDigitalDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-digital-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -28,14 +29,14 @@ final class IvaExclusionBaseDraftTest extends TestCase
|
||||
$book = $store['considerationExclusions']['opportunity:345'];
|
||||
$this->assertCount(1, $book['rows']);
|
||||
$this->assertCount(4, $book['rows'][0]['parts']);
|
||||
$this->assertSame(['judicial_indemnity','granted_discount','third_party_payment','returnable_packaging'], array_column($book['rows'][0]['parts'], 'treatment'));
|
||||
$this->assertSame(['judicial_indemnity', 'granted_discount', 'third_party_payment', 'returnable_packaging'], array_column($book['rows'][0]['parts'], 'treatment'));
|
||||
$this->assertSame(['799.70'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame('1000.25', $book['rows'][0]['initialAmount']);
|
||||
$this->assertSame(['100.10','50.25','30.15','20.05'], array_column($book['rows'][0]['parts'], 'amount'));
|
||||
$this->assertSame(['yes','yes','yes','yes'], array_column($book['rows'][0]['parts'], 'included'));
|
||||
$this->assertSame(['100.10', '50.25', '30.15', '20.05'], array_column($book['rows'][0]['parts'], 'amount'));
|
||||
$this->assertSame(['yes', 'yes', 'yes', 'yes'], array_column($book['rows'][0]['parts'], 'included'));
|
||||
$this->assertSame('yes', $book['rows'][0]['parts'][0]['conditions']['judicialDeclaration']);
|
||||
$this->assertSame('yes', $book['rows'][0]['parts'][1]['conditions']['granted']);
|
||||
$this->assertSame('yes', $book['rows'][0]['parts'][2]['conditions']['thirdPartyAccounts']);
|
||||
@@ -58,4 +59,3 @@ final class IvaExclusionBaseDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g7g-exclusions-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -31,7 +32,7 @@ final class IvaExportBeneficiaryDraftTest extends TestCase
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('400.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['export_nonresident_buyer','export_diplomatic_mission','export_international_organisation','export_humanitarian_organisation'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['export_nonresident_buyer', 'export_diplomatic_mission', 'export_international_organisation', 'export_humanitarian_organisation'], array_column($book['rows'], 'treatment'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,19 +28,24 @@ final class IvaForeignOperationDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['foreignOperations']['opportunity:358'];
|
||||
$this->assertCount(7, $book['rows']);
|
||||
$this->assertSame(['potential','potential','potential','potential','indeterminate','not_demonstrated','excluded_19_2'],array_column($book['result']['rows'],'relation19'));
|
||||
$this->assertSame('outside_portion',$book['result']['rows'][3]['territory']);
|
||||
$this->assertSame('2026-12-10',$book['result']['rows'][0]['event']['eventDate']);
|
||||
$this->assertSame(['potential', 'potential', 'potential', 'potential', 'indeterminate', 'not_demonstrated', 'excluded_19_2'], array_column($book['result']['rows'], 'relation19'));
|
||||
$this->assertSame('outside_portion', $book['result']['rows'][3]['territory']);
|
||||
$this->assertSame('2026-12-10', $book['result']['rows'][0]['event']['eventDate']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['deduction']);$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$this->assertNull($row['deduction']);
|
||||
$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->assertSame('potential',$book['history'][0]['rows'][0]['relation19']);
|
||||
$this->assertSame('potential', $book['history'][0]['rows'][0]['relation19']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-foreign-operations-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$preserved = array_diff_key($store, ['foreignOperations' => true]);
|
||||
foreach (['goodsLocations','serviceLocations','listedServices','currencyEvents'] as $map) unset($preserved[$map]['opportunity:358']);
|
||||
foreach (['goodsLocations', 'serviceLocations', 'listedServices', 'currencyEvents'] as $map) {
|
||||
unset($preserved[$map]['opportunity:358']);
|
||||
}
|
||||
$this->assertSame($prior, $preserved);
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
@@ -48,4 +54,3 @@ final class IvaForeignOperationDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-foreign-operations-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,11 +28,11 @@ final class IvaFuelBaseDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['regulatedFuelBases']['opportunity:342'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['fuel_tax_included','fuel_tax_excluded'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1400.15','1500.25'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['fuel_tax_included', 'fuel_tax_excluded'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1400.15', '1500.25'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame('1500.25', $book['rows'][0]['consideration']);
|
||||
$this->assertSame('100.10', $book['rows'][0]['fuelTax']);
|
||||
$this->assertStringContainsString('TC desta operação', $book['rows'][0]['fuelTaxRef']);
|
||||
@@ -54,4 +55,3 @@ final class IvaFuelBaseDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g7d-fuel-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaFundraisingDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_fundraising_context_preserves_accepted_opportunities(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -27,6 +29,8 @@ final class IvaFundraisingDraftTest extends TestCase
|
||||
$this->assertSame('0.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309']);
|
||||
if (getenv('IVA_G2J_RECOVERED')) file_put_contents(getenv('IVA_G2J_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
if (getenv('IVA_G2J_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2J_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,15 +28,16 @@ final class IvaGoodsAllocationDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['regulatedGoodsAllocations']['opportunity:353'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['permanent_private_goods','free_goods_transfer','exempt_sector_goods','fixed_asset_20a'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['1000.25','800.15','1000.25','800.15'],array_column($book['result']['rows'],'baseAmount'));
|
||||
$this->assertSame(array_fill(0,4,'assimilated_goods'),array_column($book['result']['rows'],'classification'));
|
||||
$this->assertSame(['permanent_private_goods', 'free_goods_transfer', 'exempt_sector_goods', 'fixed_asset_20a'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1000.25', '800.15', '1000.25', '800.15'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(array_fill(0, 4, 'assimilated_goods'), array_column($book['result']['rows'], 'classification'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$this->assertNull($row['vat']);
|
||||
$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('1000.25',$book['history'][0]['rows'][0]['baseAmount']);
|
||||
$this->assertSame('1000.25', $book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-goods-allocation-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, ['regulatedGoodsAllocations' => true]));
|
||||
@@ -46,4 +48,3 @@ final class IvaGoodsAllocationDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-goods-allocation-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,13 +28,13 @@ final class IvaGoodsLocationDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['goodsLocations']['opportunity:348'];
|
||||
$this->assertCount(3, $book['rows']);
|
||||
$this->assertSame(['goods_with_transport','goods_without_transport','goods_before_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['national','outside','national'], array_column($book['result']['rows'], 'territory'));
|
||||
$this->assertSame(['determined','determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null,null], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame([null,null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['MZ','foreign','foreign'], array_column($book['rows'], 'placeCountry'));
|
||||
$this->assertSame(['goods_with_transport', 'goods_without_transport', 'goods_before_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['national', 'outside', 'national'], array_column($book['result']['rows'], 'territory'));
|
||||
$this->assertSame(['determined', 'determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null, null, null], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame([null, null, null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null, null, null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['MZ', 'foreign', 'foreign'], array_column($book['rows'], 'placeCountry'));
|
||||
$this->assertSame('2026-12-12', $book['rows'][0]['operationDate']);
|
||||
$this->assertSame('yes', $book['rows'][2]['conditions']['beforeImport']);
|
||||
$this->assertStringContainsString('importação nacional A', $book['rows'][2]['importRef']);
|
||||
@@ -54,4 +55,3 @@ final class IvaGoodsLocationDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g8a-goods-location-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,14 +28,16 @@ final class IvaGoodsPresumptionDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['goodsPresumptions']['opportunity:355'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['consignment_180','missing_goods','excess_consumption','found_goods'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['consignment_transmission','presumed_transmission','presumed_transmission','presumed_acquisition'],array_column($book['result']['rows'],'classification'));
|
||||
$this->assertSame(['consignment_180', 'missing_goods', 'excess_consumption', 'found_goods'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['consignment_transmission', 'presumed_transmission', 'presumed_transmission', 'presumed_acquisition'], array_column($book['result']['rows'], 'classification'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$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->assertSame('2026-11-28',$book['history'][0]['rows'][0]['deadline']);
|
||||
$this->assertSame('2026-11-28', $book['history'][0]['rows'][0]['deadline']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-goods-presumptions-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, ['goodsPresumptions' => true]));
|
||||
@@ -45,4 +48,3 @@ final class IvaGoodsPresumptionDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-goods-presumptions-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaHealthGoodsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_health_goods_round_trip_preserves_other_opportunity(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -25,7 +27,11 @@ final class IvaHealthGoodsDraftTest extends TestCase
|
||||
$this->assertCount(5, $book['result']['rows']);
|
||||
$this->assertSame('500.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2A_RECOVERED')) file_put_contents(getenv('IVA_G2A_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
if (getenv('IVA_G2A_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2A_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,12 +28,12 @@ final class IvaImportDevelopmentDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:338'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['un_development_exemption','un_development_reduction'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00','400.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt','reduced'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame(['un_development_exemption', 'un_development_reduction'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00', '400.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt', 'reduced'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
foreach (['developmentProject','developmentAgency','developmentDecisionRef','developmentListRef','developmentPlanRef','developmentScope','developmentRightsRef'] as $field) {
|
||||
foreach (['developmentProject', 'developmentAgency', 'developmentDecisionRef', 'developmentListRef', 'developmentPlanRef', 'developmentScope', 'developmentRightsRef'] as $field) {
|
||||
$this->assertStringContainsString('SYNTHETIC QA', $book['rows'][0][$field]);
|
||||
}
|
||||
$this->assertSame('50', $book['rows'][1]['developmentReductionPercent']);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,9 +28,9 @@ final class IvaImportServicesDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:336'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['service_in_customs_value','accessory_service_first_destination'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['service_in_customs_value', 'accessory_service_first_destination'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(array_fill(0, 2, '0.00'), array_column($book['result']['rows'], 'serviceVat'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame('SYNTHETIC QA importação DU-A,2026-12', $book['rows'][0]['serviceImportRef']);
|
||||
$this->assertSame('SYNTHETIC QA base DU-A,linha serviço5000MZN', $book['rows'][0]['serviceBaseRef']);
|
||||
$this->assertSame(array_fill(0, 2, 'exempt'), array_column($book['result']['rows'], 'status'));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -39,7 +40,7 @@ final class IvaImportSuppliesDraftTest extends TestCase
|
||||
$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(['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']);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaListedGoodsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_listed_context_preserves_accepted_opportunities(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -27,7 +29,11 @@ final class IvaListedGoodsDraftTest extends TestCase
|
||||
$this->assertSame('1800.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2H_RECOVERED')) file_put_contents(getenv('IVA_G2H_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
if (getenv('IVA_G2H_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2H_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,11 +28,13 @@ final class IvaListedServicesDraftTest extends TestCase
|
||||
$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'));
|
||||
$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->assertNull($row['baseAmount']);
|
||||
$this->assertNull($row['vat']);
|
||||
$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
@@ -46,4 +49,3 @@ final class IvaListedServicesDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g9-nondigital-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,50 @@
|
||||
<?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 IvaMinerDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_miner_imports_recover_with_P046_and_all_accepted_books_untouched(): 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-miners.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:362',$recovered['context_opportunity']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['minerImports']['opportunity:362'];$this->assertCount(9,$b['rows']);$this->assertCount(1,$b['history']);$this->assertSame($b['rows'],$b['result']['inputs']);
|
||||
foreach($b['result']['rows'] as $row){$this->assertContains($row['status'],['exempt','reduced']);$this->assertNull($row['deduction']);$this->assertStringContainsString('arts1–4PDF1',$row['source']);}
|
||||
$this->assertSame('80.061728',$b['result']['rows'][7]['importVat']);$this->assertSame('exempt',$b['result']['rows'][8]['status']);
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-miners-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($s,['minerImports'=>true]));$this->assertCount(28,$s['objectiveImports']['opportunity:361']['result']['rows']);$this->assertSame('regulation_pending',$s['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);foreach($s['travelOperations']['opportunity:360']['result']['periods'] as $period){$this->assertNull($period['vat']);$this->assertNull($period['deduction']);}
|
||||
file_put_contents(base_path('outputs/iva-l1-miners-returnees-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_miner_imports_recover_with_p046_and_all_accepted_books_untouched(): 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-miners.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:362', $recovered['context_opportunity']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['minerImports']['opportunity:362'];
|
||||
$this->assertCount(9, $b['rows']);
|
||||
$this->assertCount(1, $b['history']);
|
||||
$this->assertSame($b['rows'], $b['result']['inputs']);
|
||||
foreach ($b['result']['rows'] as $row) {
|
||||
$this->assertContains($row['status'], ['exempt', 'reduced']);
|
||||
$this->assertNull($row['deduction']);
|
||||
$this->assertStringContainsString('arts1–4PDF1', $row['source']);
|
||||
}
|
||||
$this->assertSame('80.061728', $b['result']['rows'][7]['importVat']);
|
||||
$this->assertSame('exempt', $b['result']['rows'][8]['status']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-miners-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($s, ['minerImports' => true]));
|
||||
$this->assertCount(28, $s['objectiveImports']['opportunity:361']['result']['rows']);
|
||||
$this->assertSame('regulation_pending', $s['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);
|
||||
foreach ($s['travelOperations']['opportunity:360']['result']['periods'] as $period) {
|
||||
$this->assertNull($period['vat']);
|
||||
$this->assertNull($period['deduction']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-miners-returnees-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,11 +28,11 @@ final class IvaNoncashBaseDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['noncashBases']['opportunity:343'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['noncash_only','cash_and_noncash'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['2200.50','2700.75'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame(['noncash_only', 'cash_and_noncash'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['2200.50', '2700.75'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null, null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertSame('500.25', $book['rows'][0]['cashAmount']);
|
||||
$this->assertSame('2200.50', $book['rows'][0]['normalValue']);
|
||||
$this->assertStringContainsString('parte monetária', $book['rows'][0]['cashRef']);
|
||||
@@ -53,4 +54,3 @@ final class IvaNoncashBaseDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g7e-noncash-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,47 @@
|
||||
<?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 IvaObjectiveImportDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_objective_imports_recover_without_altering_any_accepted_book(): 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-objective-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:361',$recovered['context_opportunity']);
|
||||
$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['objectiveImports']['opportunity:361'];$this->assertCount(28,$b['rows']);$this->assertCount(1,$b['history']);$this->assertSame($b['rows'],$b['result']['inputs']);
|
||||
foreach($b['result']['rows'] as $line){$this->assertSame('exempt',$line['status']);$this->assertSame('0.00',$line['importVat']);$this->assertNull($line['deduction']);}
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-objective-imports-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($s,['objectiveImports'=>true]));
|
||||
$this->assertSame('regulation_pending',$s['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);
|
||||
foreach($s['travelOperations']['opportunity:360']['result']['periods'] as $period){$this->assertNull($period['vat']);$this->assertNull($period['deduction']);}
|
||||
file_put_contents(base_path('outputs/iva-l1-import-source-review-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_objective_imports_recover_without_altering_any_accepted_book(): 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-objective-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:361', $recovered['context_opportunity']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['objectiveImports']['opportunity:361'];
|
||||
$this->assertCount(28, $b['rows']);
|
||||
$this->assertCount(1, $b['history']);
|
||||
$this->assertSame($b['rows'], $b['result']['inputs']);
|
||||
foreach ($b['result']['rows'] as $line) {
|
||||
$this->assertSame('exempt', $line['status']);
|
||||
$this->assertSame('0.00', $line['importVat']);
|
||||
$this->assertNull($line['deduction']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-objective-imports-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($s, ['objectiveImports' => true]));
|
||||
$this->assertSame('regulation_pending', $s['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);
|
||||
foreach ($s['travelOperations']['opportunity:360']['result']['periods'] as $period) {
|
||||
$this->assertNull($period['vat']);
|
||||
$this->assertNull($period['deduction']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-import-source-review-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,8 +28,8 @@ final class IvaOfferPathsDraftTest extends TestCase
|
||||
$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->assertSame(['P084', 'P085'], array_column($book['rows'], 'branch'));
|
||||
$this->assertSame(['import', 'acquisition'], array_column($book['rows'], 'operation'));
|
||||
$this->assertArrayNotHasKey('result', $book);
|
||||
$this->assertCount(3, $book['history']);
|
||||
$this->assertSame('SYNTHETIC QA finalidade editada deliberadamente', $book['saved']['rows'][0]['purpose']);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,8 +28,8 @@ final class IvaOfferPreparationsDraftTest extends TestCase
|
||||
$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->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']);
|
||||
|
||||
@@ -1,50 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Jobs\ScanDocumentForMalware;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaOfferWorkflowDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
protected function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
$output=base_path('outputs/iva-l1-returnees-20261025');if(!is_dir($output))mkdir($output,0775,true);
|
||||
}
|
||||
public function test_P104_operational_selection_recovers_without_recalculating_history():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-fx-selection.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']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['currencyEvents']['opportunity:365'];$this->assertCount(1,$b['history']);$this->assertSame('6406.9775',$b['history'][0]['rows'][0]['scenarioAmount']);$this->assertSame('12782.00',$b['result']['rows'][0]['scenarioAmount']);$this->assertSame('mean',$b['rows'][0]['fxSelection']['applied']['column']);$this->assertNull($b['result']['rows'][0]['baseAmount']);$this->assertNull($b['result']['rows'][0]['vat']);
|
||||
$prior=json_decode(json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-workflow.json')),true)['modelo_a_snapshot'],true);$this->assertSame(array_diff_key($prior,['currencyEvents'=>true]),array_diff_key($s,['currencyEvents'=>true]));foreach($prior['currencyEvents'] as $k=>$v)$this->assertSame($v,$s['currencyEvents'][$k]);
|
||||
file_put_contents(base_path('outputs/iva-l1-returnees-20261025/fx-recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
public function test_private_decision_attachment_and_recovery_preserve_prior_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]);Queue::fake();Storage::fake('local');$owner=User::factory()->create(['email_verified_at'=>now()]);$this->actingAs($owner);
|
||||
$draft=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-workflow.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');
|
||||
$file=UploadedFile::fake()->createWithContent('SYNTHETIC-QA-despacho.txt','SYNTHETIC QA despacho privado para teste de continuidade.');
|
||||
$url='/api/v1/simulation-drafts/'.$id.'/offer-documents';$doc=$this->post($url,['file'=>$file],['Accept'=>'application/json'])->assertCreated()->json('data');$this->assertSame(hash('sha256','SYNTHETIC QA despacho privado para teste de continuidade.'),$doc['sha256']);Queue::assertPushed(ScanDocumentForMalware::class);
|
||||
$this->post($url,['file'=>UploadedFile::fake()->createWithContent('copy.txt','SYNTHETIC QA despacho privado para teste de continuidade.')],['Accept'=>'application/json'])->assertOk()->assertJsonPath('data.id',$doc['id']);
|
||||
$this->getJson($doc['url'])->assertStatus(409);$this->getJson($url)->assertOk()->assertJsonCount(1,'data');
|
||||
$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));$this->getJson($doc['url'])->assertNotFound();$this->getJson($url)->assertNotFound();$this->post($url,['file'=>UploadedFile::fake()->createWithContent('other.txt','SYNTHETIC QA other')],['Accept'=>'application/json'])->assertNotFound();
|
||||
$this->actingAs($owner);DB::table('documents')->where('id',$doc['id'])->update(['status'=>'active','malware_scan_status'=>'clean','malware_scanned_sha256'=>$doc['sha256']]);$this->get($doc['url'])->assertOk()->assertHeader('X-Content-Type-Options','nosniff');
|
||||
$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');$this->assertSame($draft['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);$snapshot=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$this->assertCount(2,$snapshot['offerPreparations']['opportunity:364']['rows']);
|
||||
$prior=json_decode(json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-returnees.json')),true)['modelo_a_snapshot'],true);$this->assertSame(array_diff_key($prior,['offerPreparations'=>true]),array_diff_key($snapshot,['offerPreparations'=>true]));foreach($prior['offerPreparations'] as $k=>$v)$this->assertSame($v,$snapshot['offerPreparations'][$k]);
|
||||
// The UI seed contains the real uploaded private decision identity, not a synthetic URL passed as an upload.
|
||||
foreach($snapshot['offerPreparations']['opportunity:364']['rows'] as &$row){$row['workflow']['decisionAttachment']=$doc;}
|
||||
unset($row);$recovered['modelo_a_snapshot']=json_encode($snapshot,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE);
|
||||
file_put_contents(base_path('outputs/iva-l1-returnees-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$stored=DB::table('documents')->where('id',$doc['id'])->first();Storage::disk('local')->put($stored->storage_key,'changed');$this->getJson($doc['url'])->assertStatus(409);
|
||||
}
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$output = base_path('outputs/iva-l1-returnees-20261025');
|
||||
if (! is_dir($output)) {
|
||||
mkdir($output, 0775, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_p104_operational_selection_recovers_without_recalculating_history(): 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-fx-selection.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']);
|
||||
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$b = $s['currencyEvents']['opportunity:365'];
|
||||
$this->assertCount(1, $b['history']);
|
||||
$this->assertSame('6406.9775', $b['history'][0]['rows'][0]['scenarioAmount']);
|
||||
$this->assertSame('12782.00', $b['result']['rows'][0]['scenarioAmount']);
|
||||
$this->assertSame('mean', $b['rows'][0]['fxSelection']['applied']['column']);
|
||||
$this->assertNull($b['result']['rows'][0]['baseAmount']);
|
||||
$this->assertNull($b['result']['rows'][0]['vat']);
|
||||
$prior = json_decode(json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-workflow.json')), true)['modelo_a_snapshot'], true);
|
||||
$this->assertSame(array_diff_key($prior, ['currencyEvents' => true]), array_diff_key($s, ['currencyEvents' => true]));
|
||||
foreach ($prior['currencyEvents'] as $k => $v) {
|
||||
$this->assertSame($v, $s['currencyEvents'][$k]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-returnees-20261025/fx-recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function test_private_decision_attachment_and_recovery_preserve_prior_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]);
|
||||
Queue::fake();
|
||||
Storage::fake('local');
|
||||
$owner = User::factory()->create(['email_verified_at' => now()]);
|
||||
$this->actingAs($owner);
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-workflow.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');
|
||||
$file = UploadedFile::fake()->createWithContent('SYNTHETIC-QA-despacho.txt', 'SYNTHETIC QA despacho privado para teste de continuidade.');
|
||||
$url = '/api/v1/simulation-drafts/'.$id.'/offer-documents';
|
||||
$doc = $this->post($url, ['file' => $file], ['Accept' => 'application/json'])->assertCreated()->json('data');
|
||||
$this->assertSame(hash('sha256', 'SYNTHETIC QA despacho privado para teste de continuidade.'), $doc['sha256']);
|
||||
Queue::assertPushed(ScanDocumentForMalware::class);
|
||||
$this->post($url, ['file' => UploadedFile::fake()->createWithContent('copy.txt', 'SYNTHETIC QA despacho privado para teste de continuidade.')], ['Accept' => 'application/json'])->assertOk()->assertJsonPath('data.id', $doc['id']);
|
||||
$this->getJson($doc['url'])->assertStatus(409);
|
||||
$this->getJson($url)->assertOk()->assertJsonCount(1, 'data');
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$this->getJson($doc['url'])->assertNotFound();
|
||||
$this->getJson($url)->assertNotFound();
|
||||
$this->post($url, ['file' => UploadedFile::fake()->createWithContent('other.txt', 'SYNTHETIC QA other')], ['Accept' => 'application/json'])->assertNotFound();
|
||||
$this->actingAs($owner);
|
||||
DB::table('documents')->where('id', $doc['id'])->update(['status' => 'active', 'malware_scan_status' => 'clean', 'malware_scanned_sha256' => $doc['sha256']]);
|
||||
$this->get($doc['url'])->assertOk()->assertHeader('X-Content-Type-Options', 'nosniff');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$snapshot = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertCount(2, $snapshot['offerPreparations']['opportunity:364']['rows']);
|
||||
$prior = json_decode(json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-returnees.json')), true)['modelo_a_snapshot'], true);
|
||||
$this->assertSame(array_diff_key($prior, ['offerPreparations' => true]), array_diff_key($snapshot, ['offerPreparations' => true]));
|
||||
foreach ($prior['offerPreparations'] as $k => $v) {
|
||||
$this->assertSame($v, $snapshot['offerPreparations'][$k]);
|
||||
}
|
||||
// The UI seed contains the real uploaded private decision identity, not a synthetic URL passed as an upload.
|
||||
foreach ($snapshot['offerPreparations']['opportunity:364']['rows'] as &$row) {
|
||||
$row['workflow']['decisionAttachment'] = $doc;
|
||||
}
|
||||
unset($row);
|
||||
$recovered['modelo_a_snapshot'] = json_encode($snapshot, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
|
||||
file_put_contents(base_path('outputs/iva-l1-returnees-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
$stored = DB::table('documents')->where('id', $doc['id'])->first();
|
||||
Storage::disk('local')->put($stored->storage_key, 'changed');
|
||||
$this->getJson($doc['url'])->assertStatus(409);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -31,7 +32,7 @@ final class IvaOnboardSupplyDraftTest extends TestCase
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('400.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['provisions','fuel','beverages','cargo_products'], array_column($book['rows'], 'supplyCategory'));
|
||||
$this->assertSame(['provisions', 'fuel', 'beverages', 'cargo_products'], array_column($book['rows'], 'supplyCategory'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
|
||||
@@ -39,7 +39,9 @@ final class IvaOperationsDraftTest extends TestCase
|
||||
$this->assertCount(12, $book['result']['rows']);
|
||||
$this->assertSame('160.00', $book['result']['rows'][0]['vat']);
|
||||
$this->assertNull($book['result']['rows'][10]['vat']);
|
||||
if (getenv('IVA_L1_RECOVERED_OUT')) file_put_contents(getenv('IVA_L1_RECOVERED_OUT'), json_encode($economic, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
if (getenv('IVA_L1_RECOVERED_OUT')) {
|
||||
file_put_contents(getenv('IVA_L1_RECOVERED_OUT'), json_encode($economic, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$this->getJson('/api/v1/simulation-drafts/'.$id)->assertNotFound();
|
||||
$this->assertSame($fingerprint, DB::selectOne("select md5(string_agg(row_to_json(r)::text,E'\\n' order by id)) as hash from simulation_tax_rule_versions r")->hash);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -27,15 +28,17 @@ final class IvaOwnNameDraftTest extends TestCase
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['ownNames']['opportunity:352'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['goods_sale_commission','goods_purchase_commission','service_sale_mandate','service_purchase_mandate'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['goods_sale_commission', 'goods_purchase_commission', 'service_sale_mandate', 'service_purchase_mandate'], array_column($book['rows'], 'treatment'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertCount(2,$row['legs']);
|
||||
$this->assertSame(['1000.25','1100.75'],array_column($row['legs'],'consideration'));
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
$this->assertCount(2, $row['legs']);
|
||||
$this->assertSame(['1000.25', '1100.75'], array_column($row['legs'], 'consideration'));
|
||||
$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->assertSame('1000.25',$book['history'][0]['rows'][0]['legs'][0]['consideration']);
|
||||
$this->assertSame('1000.25', $book['history'][0]['rows'][0]['legs'][0]['consideration']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g10-own-name-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, ['ownNames' => true]));
|
||||
@@ -46,4 +49,3 @@ final class IvaOwnNameDraftTest extends TestCase
|
||||
file_put_contents(base_path('outputs/iva-l1-g10-own-name-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaPharmaInputsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_selected_annex_rows_round_trip_with_their_own_opportunity(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
@@ -38,6 +40,8 @@ final class IvaPharmaInputsDraftTest extends TestCase
|
||||
foreach (json_decode($original['modelo_a_snapshot'], true)['salesOperations'] as $key => $value) {
|
||||
$this->assertSame($value, $store['salesOperations'][$key]);
|
||||
}
|
||||
if (getenv('IVA_G2K_RECOVERED')) file_put_contents(getenv('IVA_G2K_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
if (getenv('IVA_G2K_RECOVERED')) {
|
||||
file_put_contents(getenv('IVA_G2K_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -10,6 +11,7 @@ use Tests\TestCase;
|
||||
final class IvaProductionCalendarDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_calendar_delta_round_trips_without_replacing_previous_result(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user