@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Controllers\InvestmentPortfolioController;
|
||||
use App\Models\User;
|
||||
use App\Services\ApprovedAnchorTerritories;
|
||||
use App\Services\InvestmentRelations;
|
||||
use App\Services\InvestorContext;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestmentAnchorIntegrationTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $actor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
$this->withoutVite();
|
||||
$this->withoutMiddleware(ThrottleRequests::class);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->actor = User::factory()->create();
|
||||
}
|
||||
|
||||
public function test_documented_sector_filter_is_explicit_and_preserves_the_catalogue_scope(): void
|
||||
{
|
||||
$anchor = InvestmentPortfolioController::visible()->where('content->code', 'A06')->firstOrFail();
|
||||
$sector = $anchor->content['sector'];
|
||||
$this->get('/carteira?'.http_build_query(['kind' => 'project', 'sector' => $sector]))->assertOk()
|
||||
->assertInertia(fn (Assert $p) => $p->where('filters.sector', $sector)->has('records.data', 1)->where('records.data.0.id', $anchor->id)->has('sectors'));
|
||||
$this->get('/carteira?sector=sector-inexistente')->assertOk()->assertInertia(fn (Assert $p) => $p->has('records.data', 0));
|
||||
$this->get('/carteira')->assertOk()->assertInertia(fn (Assert $p) => $p->where('records.total', InvestmentPortfolioController::visible()->count()));
|
||||
}
|
||||
|
||||
public function test_accepted_territories_are_recovered_by_identity_with_citations_and_idempotence(): void
|
||||
{
|
||||
$service = app(ApprovedAnchorTerritories::class);
|
||||
$before = DB::table('investment_dossiers')->orderBy('id')->get()->toJson();
|
||||
$plan = $service->plan();
|
||||
$this->assertCount(28, $plan['links']);
|
||||
$this->assertCount(13, $plan['projects']);
|
||||
$result = $service->apply($plan);
|
||||
$this->assertSame(count(array_filter($plan['links'], fn ($link) => ! $link['already_present'])), $result['relations_restored']);
|
||||
$this->assertSame(0, $result['publication_changes']);
|
||||
$this->assertSame($before, DB::table('investment_dossiers')->orderBy('id')->get()->toJson());
|
||||
$second = $service->apply($service->plan());
|
||||
$this->assertSame(0, $second['relations_restored']);
|
||||
$this->assertSame(0, $second['projects_updated']);
|
||||
$anchor = InvestmentPortfolioController::visible()->where('content->code', 'A06')->firstOrFail();
|
||||
$locations = app(InvestmentRelations::class)->projectLocations($anchor->project_id);
|
||||
$this->assertCount(4, $locations);
|
||||
$this->assertNotEmpty($locations[0]['source_quote']);
|
||||
$this->assertSame('secondary', $locations[0]['role']);
|
||||
$province = $locations[0]['id'];
|
||||
$this->get('/carteira?'.http_build_query(['kind' => 'project', 'sector' => $anchor->content['sector'], 'province_id' => $province]))->assertOk()
|
||||
->assertInertia(fn (Assert $p) => $p->has('records.data', 1)->where('records.data.0.id', $anchor->id));
|
||||
$this->assertCount(0, app(InvestmentRelations::class)->projectLocations(InvestmentPortfolioController::visible()->where('content->code', 'A01')->firstOrFail()->project_id));
|
||||
}
|
||||
|
||||
public function test_anchor_without_offer_survives_login_dossier_and_simulator_as_documentary_origin(): void
|
||||
{
|
||||
$anchor = InvestmentPortfolioController::visible()->where('content->code', 'A06')->firstOrFail();
|
||||
$source = 'portfolio:'.$anchor->id;
|
||||
$entry = '/investimentos/iniciar?'.http_build_query(['source' => $source]);
|
||||
$this->get($entry)->assertRedirect(route('login'));
|
||||
$this->assertStringEndsWith($entry, session('url.intended'));
|
||||
$this->actingAs($this->actor);
|
||||
$this->get($entry)->assertOk()->assertInertia(fn (Assert $p) => $p->where('source.key', $source)->has('opportunityChoices', 0));
|
||||
$reference = app(InvestorContext::class)->reference($source);
|
||||
$this->assertArrayNotHasKey('province_id', $reference['fields']);
|
||||
$this->assertFalse($reference['analysis']['available_opportunity']);
|
||||
$id = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA - ideia propria', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$body = ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => ['portfolio' => $source]];
|
||||
$preview = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->assertSame('SYNTHETIC QA - ideia propria', $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($source, $view['context']['selection']['portfolio']['key']);
|
||||
$this->assertSame([], $view['context']['opportunity_choices']);
|
||||
$snapshot = json_decode($view['prefill']['simulator']['context_applicability_snapshot'], true);
|
||||
$this->assertSame($source, $snapshot['portfolio_origin']['key']);
|
||||
$draft = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'project_title' => 'SYNTHETIC QA - titulo proprio', 'context_applicability_snapshot' => json_encode($snapshot)]], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$saved = $this->getJson('/api/v1/simulation-drafts/'.$draft.'?context='.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($source, json_decode($saved['context_applicability_snapshot'], true)['portfolio_origin']['key']);
|
||||
$this->assertSame('SYNTHETIC QA - titulo proprio', $saved['project_title']);
|
||||
$anchor->publication_status = 'draft';
|
||||
$anchor->save();
|
||||
$this->get($entry)->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_interest_resumption_keeps_the_same_anchor_and_filters_without_creating_a_request_on_get(): void
|
||||
{
|
||||
$anchor = InvestmentPortfolioController::visible()->where('content->code', 'A06')->firstOrFail();
|
||||
$query = http_build_query(['sector' => $anchor->content['sector'], 'kind' => 'project']);
|
||||
$entry = '/carteira/'.$anchor->id.'/interesse?'.http_build_query(['catalogue_query' => $query]);
|
||||
$before = DB::table('investment_submissions')->count();
|
||||
$this->get($entry)->assertRedirect(route('login'));
|
||||
$this->assertStringEndsWith($entry, session('url.intended'));
|
||||
$this->actingAs($this->actor);
|
||||
$this->get($entry)->assertRedirect('/carteira/'.$anchor->id.'?'.http_build_query(['catalogue_query' => $query, 'prepare_interest' => '1']));
|
||||
$this->assertSame($before, DB::table('investment_submissions')->count());
|
||||
$response = $this->postJson('/investidor/manifestacoes', ['dossier_id' => $anchor->id])->assertCreated();
|
||||
$row = DB::table('investment_submissions')->where('id', $response->json('id'))->first();
|
||||
$this->assertSame($anchor->id, $row->dossier_id);
|
||||
$start = '/investimentos/iniciar?'.http_build_query(['source' => 'portfolio:'.$anchor->id, 'submission' => $row->id]);
|
||||
$this->get($start)->assertOk()->assertInertia(fn (Assert $p) => $p->where('entrySubmission.id', $row->id)->where('entrySubmission.version', (int) $row->version));
|
||||
$other = InvestmentPortfolioController::visible()->where('id', '!=', $anchor->id)->firstOrFail();
|
||||
$this->get('/investimentos/iniciar?'.http_build_query(['source' => 'portfolio:'.$other->id, 'submission' => $row->id]))->assertUnprocessable();
|
||||
$case = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA - manifesto e ancora', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$version = $this->getJson('/investimentos/'.$case.'/contexto')->json('case.version');
|
||||
$this->postJson('/investidor/manifestacoes/'.$row->id.'/contexto', ['case_id' => $case, 'case_version' => $version, 'version' => (int) $row->version])->assertOk();
|
||||
$this->assertSame($row->id, DB::table('desk_cases')->where('id', $case)->value('submission_id'));
|
||||
$this->assertSame($anchor->id, DB::table('investment_submissions')->where('id', $row->id)->value('dossier_id'));
|
||||
$this->actingAs(User::factory()->create());
|
||||
$this->get($start)->assertNotFound();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Controllers\InvestmentPortfolioController;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentComplements;
|
||||
use App\Services\PartnershipExchange;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestmentComplementsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$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(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
}
|
||||
|
||||
private function source(): string
|
||||
{
|
||||
return 'portfolio:'.InvestmentPortfolioController::visible()->where('content->code', 'COR-02')->value('id');
|
||||
}
|
||||
|
||||
public function test_public_complements_link_existing_identities_and_distinguish_unoffered_needs(): void
|
||||
{
|
||||
$source = $this->source();
|
||||
$options = $this->getJson('/complementos-investimento?'.http_build_query(['origin' => $source]))->assertOk()->json();
|
||||
$storage = collect($options)->firstWhere('code', 'storage');
|
||||
$this->assertNotEmpty($storage['opportunities']);
|
||||
$offer = $storage['opportunities'][0];
|
||||
$record = Opportunity::findOrFail(substr($offer['key'], 12));
|
||||
$this->assertSame('/oportunidades/'.$record->slug, $offer['href']);
|
||||
$this->get($offer['href'])->assertOk();
|
||||
$spinning = collect($options)->firstWhere('code', 'spinning');
|
||||
$this->assertSame([], $spinning['opportunities']);
|
||||
$query = http_build_query(['complement_origin' => $source, 'complement_code' => 'spinning']);
|
||||
$this->get('/investimentos/iniciar?'.$query)->assertRedirect(route('login'));
|
||||
$this->assertStringContainsString('complement_code=spinning', session('url.intended'));
|
||||
$this->getJson('/complementos-investimento?origin=sector:1')->assertUnprocessable();
|
||||
}
|
||||
|
||||
public function test_complements_survive_draft_confirmation_and_consumer_snapshot_without_overwriting_title(): void
|
||||
{
|
||||
$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));
|
||||
$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));
|
||||
$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);
|
||||
$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->actingAs(User::factory()->create())->getJson('/investimentos/'.$id.'/contexto')->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_offer_cannot_be_forged_or_confirmed_after_withdrawal(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
$id = $this->postJson('/investimentos', ['title' => 'QA complemento', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$origin = $this->source();
|
||||
$target = collect(app(InvestmentComplements::class)->options($origin))->firstWhere('code', 'storage')['opportunities'][0]['key'];
|
||||
$base = ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => []];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', [...$base, 'complements' => [['origin' => $origin, 'code' => 'spinning', 'target' => $target]]])->assertUnprocessable();
|
||||
$body = [...$base, 'opportunity_choices' => [['source' => $target]], 'complements' => [['origin' => $origin, 'code' => 'storage', 'target' => $target]]];
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
Opportunity::whereKey(substr($target, 12))->update(['status' => 'draft']);
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$body, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertUnprocessable();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.revision', 0);
|
||||
}
|
||||
|
||||
public function test_concrete_training_and_finance_services_are_reused_only_for_their_documented_origin(): void
|
||||
{
|
||||
$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,
|
||||
'payload' => ['summary' => 'QA oferta '.$title, 'consent' => true], 'origins' => [['type' => 'dossier', 'target_id' => substr($origin, 10)]]]);
|
||||
// Published fixture only in this rolled-back isolated QA transaction.
|
||||
DB::table('portal_partnerships')->where('id', $service->id)->update(['status' => 'published']);
|
||||
$code = $type === 'finance' ? 'finance' : 'training';
|
||||
$option = collect(app(InvestmentComplements::class)->options($origin))->firstWhere('code', $code);
|
||||
$this->assertSame('partnership:'.$service->id, $option['services'][0]['key']);
|
||||
$this->get($option['services'][0]['href'])->assertOk();
|
||||
$resolved = app(InvestmentComplements::class)->resolve([['origin' => $origin, 'code' => $code, 'target' => 'partnership:'.$service->id]]);
|
||||
$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());
|
||||
}
|
||||
|
||||
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();
|
||||
$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]]]);
|
||||
$link = (string) Str::uuid();
|
||||
DB::table('complementary_project_links')->insert(['id' => $link, 'anchor_project_id' => $projects[0], 'complementary_project_id' => $projects[1], 'relation_type' => 'enabler', 'data_classification' => 'public']);
|
||||
$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();
|
||||
$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();
|
||||
$this->assertSame([], collect($batch['items'])->firstWhere('code', 'irrigation')['opportunities']);
|
||||
DB::table('complementary_project_links')->where('id', $link)->update(['data_classification' => 'internal']);
|
||||
$this->assertSame([], $service->options('opportunity:'.$main->id));
|
||||
}
|
||||
|
||||
public function test_previous_relation_is_preserved_as_history_when_an_offer_is_withdrawn(): void
|
||||
{
|
||||
$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);
|
||||
Opportunity::whereKey(substr($target, 12))->update(['status' => 'draft']);
|
||||
$history = $service->resolve($input, $previous);
|
||||
$this->assertSame($previous[0]['target'], $history[0]['target']);
|
||||
$this->assertSame('review_required', $history[0]['availability']);
|
||||
DB::table('investment_dossiers')->where('id', substr($origin, 10))->update(['publication_status' => 'draft']);
|
||||
$this->assertSame($history, $service->resolve($input, $previous));
|
||||
$this->assertSame(['items' => [], 'issues' => []], $this->postJson('/complementos-investimento', ['contexts' => []])->assertOk()->json());
|
||||
$this->postJson('/complementos-investimento', ['contexts' => [['origin' => $origin], ['origin' => 'portfolio:'.InvestmentPortfolioController::visible()->where('content->code', 'COR-01')->value('id')]]])
|
||||
->assertOk()->assertJsonCount(1, 'issues')->assertJsonPath('issues.0.origin', $origin);
|
||||
}
|
||||
|
||||
public function test_removing_then_explicitly_selecting_a_need_keeps_the_draft_and_does_not_reapply_an_old_entry(): void
|
||||
{
|
||||
$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();
|
||||
$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->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'));
|
||||
$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'));
|
||||
}
|
||||
|
||||
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();
|
||||
$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);
|
||||
$service = app(InvestmentComplements::class);
|
||||
$options = $service->options('opportunity:'.$main->id);
|
||||
$offer = collect(collect($options)->firstWhere('code', 'processing')['opportunities'])->firstWhere('key', 'opportunity:'.$target->id);
|
||||
$this->assertNotNull($offer);
|
||||
$this->assertSame('value_chain', $offer['relationship']['type']);
|
||||
$selected = $service->resolve([['origin' => 'opportunity:'.$main->id, 'code' => 'processing', 'target' => 'opportunity:'.$target->id]]);
|
||||
$this->assertSame($row, $selected[0]['target']['relationship']['principal'][0]);
|
||||
$this->assertSame($row, $selected[0]['target']['relationship']['target'][0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\{CorridorAgribusinessOpportunities, InvestmentCorridorContext, InvestmentConsumerScope, InvestorContext, InvestmentZones, VirtualDesk};
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
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();
|
||||
}
|
||||
$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();
|
||||
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();
|
||||
}
|
||||
|
||||
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']);
|
||||
$this->assertEmpty($view['prefill']['land']['parcels'][0]);
|
||||
$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.'];
|
||||
$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'));
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\{CorridorAgribusinessOpportunities, InvestmentCorridorContext, InvestmentConsumerScope, InvestorContext, InvestmentZones, VirtualDesk};
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
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();
|
||||
}
|
||||
$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();
|
||||
return $this->getJson('/investimentos/'.$this->id.'/contexto')->assertOk()->json();
|
||||
}
|
||||
|
||||
private function treatment(string $key): array
|
||||
{
|
||||
return $this->getJson('/investimentos/'.$this->id.'?opportunity='.urlencode($key))->assertOk()->json();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
$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']);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
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);
|
||||
$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();
|
||||
}
|
||||
|
||||
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->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();
|
||||
$this->actingAs($this->actor->fresh());
|
||||
$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'));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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']);
|
||||
$this->getJson('/investidor/terra-duat/'.$land)->assertOk();
|
||||
$this->assertStringNotContainsString($land,$this->treatment($key)['tools']['land']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 IrpcInterestCerDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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 IrpcMrftaDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_mrfta_and_documented_interest_recover_from_private_api_without_losing_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('outputs/irpc-mrfta/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);
|
||||
$book = $store['irpcWithholdings'][$draft['context_opportunity']];
|
||||
$model = $book['mrftaResult']['model'];
|
||||
$this->assertSame('2026-10', $model['period']);
|
||||
$this->assertSame('20000', $model['principal']['numerator']);
|
||||
$this->assertSame('3000', $model['paid']['numerator']);
|
||||
$this->assertSame('500', $model['interest']['numerator']);
|
||||
$this->assertSame('17500', $model['total']['numerator']);
|
||||
$this->assertSame([], $model['pending']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 IrpcNormalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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 IrpcNormalProfitDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 IrpcReliefsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_demonstrated_reliefs_and_insufficient_information_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-reliefs/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);
|
||||
$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('dispensed', $rent['treatment']);
|
||||
$this->assertSame('cirpc68f', $rent['reliefRule']);
|
||||
$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('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->assertNotEmpty($book['history']);
|
||||
file_put_contents(base_path('outputs/irpc-reliefs/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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 IvaAcquisitionAllocationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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);
|
||||
$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-l2-d-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']);
|
||||
$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('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('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]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-d-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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 IvaAcquisitionBCDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
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);
|
||||
$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-l2-bc-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']);
|
||||
$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('40.00', $book['result']['periods'][0]['fields']['15']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('16.00', $book['result']['periods'][0]['fields']['11']);
|
||||
$this->assertSame('120.00', $book['result']['periods'][0]['fields']['17']);
|
||||
$this->assertSame('customs', $book['rows'][0]['documentType']);
|
||||
$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]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-bc-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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 IvaAcquisitionContinuityDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_acquisition_continuity_recovers_with_document_history_and_previous_sales_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('outputs/iva-l1-g5b-acquisitions-20261024/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']);
|
||||
$this->assertSame('opportunity:329', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$this->assertArrayNotHasKey('monthly_iva_settings', $recovered);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['books']['opportunity:329'];
|
||||
$this->assertCount(1, $book['rows']);
|
||||
$this->assertSame('normal', $book['rows'][0]['acquisitionTreatment']);
|
||||
$this->assertSame('former_exploration_exemption', $book['rows'][0]['acquisitionTreatmentOrigin']['id']);
|
||||
$this->assertSame('100', $book['rows'][0]['net']);
|
||||
$this->assertSame('16', $book['rows'][0]['vat']);
|
||||
$this->assertSame('116', $book['rows'][0]['gross']);
|
||||
$this->assertSame('SYNTHETIC QA G5B 001', $book['rows'][0]['documentRef']);
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('MZN', $book['currency']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['deductible']);
|
||||
$this->assertSame('former_exploration_exemption', $book['history'][0]['inputs'][0]['acquisitionTreatment']);
|
||||
$this->assertSame('16.00', $book['result']['rows'][0]['deductible']);
|
||||
$this->assertSame('16.00', $book['result']['periods'][0]['fields']['10']);
|
||||
$this->assertNull($book['result']['periods'][0]['fields']['17']);
|
||||
$this->assertNull($book['result']['periods'][0]['fields']['18']);
|
||||
$this->assertStringContainsString('BR89', $book['result']['sources']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g5a-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g5b-acquisitions-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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 IvaAcquisitionRightDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_right_recovers_with_sources_totals_history_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()]));
|
||||
$draft = json_decode(file_get_contents(base_path('outputs/iva-l2-a-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']);
|
||||
$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('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]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l2-a-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaActSaleBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_act_sale_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7c-bases.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:341', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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('1500.25', $book['rows'][0]['actValue']);
|
||||
$this->assertSame('2200.50', $book['rows'][0]['normalValue']);
|
||||
$this->assertStringContainsString('acto A', $book['rows'][0]['actRef']);
|
||||
$this->assertStringContainsString('fundamento A', $book['rows'][0]['valuationRef']);
|
||||
$this->assertStringContainsString('dezembro2026', $book['rows'][0]['valuationScope']);
|
||||
$this->assertStringContainsString('15(2)(h)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7c-preserved-inputs.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, ['actSaleBases' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7c-act-bases-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2E_INPUT') ?: base_path('outputs/iva-l1-g2-agro-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:314'];
|
||||
$this->assertCount(4, $book['result']['rows']);
|
||||
$this->assertSame('300.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2L_INPUT') ?: base_path('outputs/iva-l1-g2-agro-annex-20261024/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']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true);
|
||||
$book = $store['salesOperations']['opportunity:321'];
|
||||
$this->assertSame('opportunity:321', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-09', $book['result']['periods'][0]['period']);
|
||||
$this->assertCount(10, $book['result']['rows']);
|
||||
$this->assertSame('800.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$this->assertSame('200.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertSame('listed_fresh_chilled_tomato', $book['rows'][6]['treatment']);
|
||||
$this->assertSame('listed_insecticides', $book['rows'][7]['treatment']);
|
||||
$this->assertStringContainsString('annexI-2022-023', $book['rows'][6]['source']);
|
||||
$this->assertStringContainsString('PDF8–9', $book['result']['rows'][5]['source']);
|
||||
$this->assertStringContainsString('Outros tractores', $book['result']['rows'][4]['source']);
|
||||
$this->assertTrue($book['rows'][8]['annexIOnly']);
|
||||
$original = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-pharma-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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
|
||||
{
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaCommissionBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_commission_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7b-bases.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:340', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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('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']);
|
||||
$this->assertSame('100.10', $book['rows'][0]['commissionAmount']);
|
||||
$this->assertStringContainsString('contrato A', $book['rows'][0]['agreementRef']);
|
||||
$this->assertStringContainsString('antes do ajuste', $book['rows'][0]['priceRef']);
|
||||
$this->assertStringContainsString('comissão contratada', $book['rows'][0]['commissionRef']);
|
||||
$this->assertStringContainsString('15(2)(e)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7b-preserved-inputs.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, ['commissionBases' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7b-commissions-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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 IvaCompositionBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_composition_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7f-bases.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:344', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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(['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->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']);
|
||||
$this->assertStringContainsString('cliente', $book['rows'][0]['parts'][1]['description']);
|
||||
$this->assertStringContainsString('15(5)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7f-preserved-inputs.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, ['considerationCompositions' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7f-composition-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2G_INPUT') ?: base_path('outputs/iva-l1-g2-conditional-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:316'];
|
||||
$this->assertCount(6, $book['result']['rows']);
|
||||
$this->assertSame('600.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2C_INPUT') ?: base_path('outputs/iva-l1-g2-cultural-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:312'];
|
||||
$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']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaCurrencyEventDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_currencyevents_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-currency-events.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:357', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->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]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-currency-events-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaDigitalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_digital_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-digital.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:359', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$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']);
|
||||
$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]);
|
||||
$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']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-digital-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaExclusionBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_exclusion_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7g-bases.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:345', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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(['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('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']);
|
||||
$this->assertSame('yes', $book['rows'][0]['parts'][3]['conditions']['returnMention']);
|
||||
$this->assertStringContainsString('contas de terceiros A', $book['rows'][0]['parts'][2]['accountRef']);
|
||||
$this->assertStringContainsString('adquirente B', $book['rows'][0]['parts'][2]['beneficiaryRef']);
|
||||
$this->assertStringContainsString('devolução acordada', $book['rows'][0]['parts'][3]['documentExcerpt']);
|
||||
$this->assertStringContainsString('declaração judicial', $book['rows'][0]['parts'][0]['reference']);
|
||||
$this->assertStringContainsString('15(6)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7g-preserved-inputs.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, ['considerationExclusions' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7g-exclusions-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 IvaExportBeneficiaryDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_export_beneficiaries_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g4-beneficiaries-20261024/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']);
|
||||
$this->assertSame('opportunity:327', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:327'];
|
||||
$this->assertSame('opportunity:327', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$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'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g4d-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g4-beneficiaries-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 IvaExportDirectDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_direct_export_rules_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g4-export-20261024/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']);
|
||||
$this->assertSame('opportunity:323', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:323'];
|
||||
$this->assertSame('opportunity:323', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-11', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('500.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(5, $book['rows']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g3-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g4-export-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaExportServiceDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_linked_export_services_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g4-services-20261024/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']);
|
||||
$this->assertSame('opportunity:325', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:325'];
|
||||
$this->assertSame('opportunity:325', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('1300.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame('g4c-goods', $book['rows'][2]['relatedExport']['id']);
|
||||
$this->assertSame('100', $book['rows'][2]['amount']);
|
||||
$this->assertSame('1000', $book['rows'][0]['amount']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g4b-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g4-services-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaForeignOperationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_foreignoperations_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-foreign-operations.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:358', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$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']);
|
||||
$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']);
|
||||
$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']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-foreign-operations-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaFuelBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_fuel_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7d-bases.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:342', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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('1500.25', $book['rows'][0]['consideration']);
|
||||
$this->assertSame('100.10', $book['rows'][0]['fuelTax']);
|
||||
$this->assertStringContainsString('TC desta operação', $book['rows'][0]['fuelTaxRef']);
|
||||
$this->assertStringContainsString('preço A', $book['rows'][0]['priceRef']);
|
||||
$this->assertStringContainsString('Manica', $book['rows'][0]['priceScope']);
|
||||
$this->assertSame('2026-12-12', $book['rows'][0]['operationDate']);
|
||||
$this->assertSame('2026-12-01', $book['rows'][0]['priceFrom']);
|
||||
$this->assertSame('2026-12-31', $book['rows'][0]['priceTo']);
|
||||
$this->assertStringContainsString('15(2)(i)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7d-preserved-inputs.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, ['regulatedFuelBases' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7d-fuel-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2J_INPUT') ?: base_path('outputs/iva-l1-g2-fundraising-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:319'];
|
||||
$this->assertCount(2, $book['result']['rows']);
|
||||
$this->assertSame('200.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaGoodsAllocationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_goods_allocation_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-goods-allocation.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:353', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$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']);
|
||||
$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]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-goods-allocation-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaGoodsLocationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_goods_locations_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g8a-bases.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:348', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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('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']);
|
||||
$this->assertStringContainsString('importador A', $book['rows'][2]['chainRef']);
|
||||
$this->assertStringContainsString('local físico', $book['rows'][0]['goodsPlace']);
|
||||
$this->assertStringContainsString('não equivale a isenção', $book['result']['rows'][1]['reason']);
|
||||
$this->assertStringContainsString('6(1)/(2)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g8a-preserved-inputs.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, ['goodsLocations' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g8a-goods-location-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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 IvaGoodsPresumptionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_goodspresumptions_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-goods-presumptions.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:355', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->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]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-goods-presumptions-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2A_INPUT') ?: base_path('outputs/iva-l1-g2-health-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'];
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaImportAssetsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6c-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:332', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:332'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['eligible_ship_import', 'ship_operation_object_import', 'eligible_aircraft_import', 'aircraft_operation_object_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00', '0.00', '0.00', '0.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt', 'exempt', 'exempt', 'exempt'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('4000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6C eligible_ship_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(h/i)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6b-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6c-imports-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaImportBeneficiariesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6b-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:331', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:331'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['author_art_import', 'fire_brigade_vehicle'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00', '0.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt', 'exempt'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('2500', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6B author_art_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(j/l)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6a-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6b-imports-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaImportCustomsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6d-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:333', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:333'];
|
||||
$this->assertCount(3, $book['rows']);
|
||||
$this->assertSame(['customs_transit_import', 'customs_temporary_import', 'customs_drawback_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00', '0.00', '0.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt', 'exempt', 'exempt'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6D customs_transit_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(c)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6c-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6d-imports-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaImportDevelopmentDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_development_scope_and_proportional_result_recover_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6h-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:338', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity: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('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
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']);
|
||||
$this->assertSame('800', $book['rows'][1]['developmentNormalVat']);
|
||||
$this->assertStringContainsString('IVA sem benefício informado', $book['rows'][1]['developmentNormalVatRef']);
|
||||
$this->assertStringContainsString('12(4)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6h-preserved-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions'], array_diff_key($store['importExemptions'], ['opportunity:338' => true]));
|
||||
$this->assertSame($prior['offerPreparations'], $store['offerPreparations']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertSame('0.00', $store['importExemptions']['opportunity:337']['result']['rows'][0]['importVat']);
|
||||
$this->assertSame('0.00', $store['importExemptions']['opportunity:336']['result']['rows'][0]['serviceVat']);
|
||||
$this->assertNull($store['importExemptions']['opportunity:336']['result']['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6h-development-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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 IvaImportExemptionsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6a-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:330', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:330'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['reimport_same_state', 'central_bank_gold'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['0.00', '0.00'], array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(['exempt', 'exempt'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('1000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6A reimport_same_state', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(d/f)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g5b-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6a-imports-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaImportInvestmentDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_investment_scope_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6g-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:337', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:337'];
|
||||
$this->assertCount(1, $book['rows']);
|
||||
$this->assertSame('authorized_investment_equipment', $book['rows'][0]['treatment']);
|
||||
$this->assertSame('0.00', $book['result']['rows'][0]['importVat']);
|
||||
$this->assertSame('exempt', $book['result']['rows'][0]['status']);
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA autorização A, pressuposto expresso', $book['rows'][0]['investmentAuthorizationRef']);
|
||||
$this->assertStringContainsString('não alargar', $book['rows'][0]['investmentScope']);
|
||||
$this->assertStringContainsString('12(1)(k)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6g-preserved-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions'], array_diff_key($store['importExemptions'], ['opportunity:337' => true]));
|
||||
$this->assertSame($prior['offerPreparations'], $store['offerPreparations']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertSame('0.00', $store['importExemptions']['opportunity:336']['result']['rows'][0]['serviceVat']);
|
||||
$this->assertNull($store['importExemptions']['opportunity:336']['result']['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6g-investment-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaImportServicesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6f-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:336', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:336'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$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('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'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6F service_in_customs_value', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(e)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-paths-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertSame($prior['importExemptions'], array_diff_key($store['importExemptions'], ['opportunity:336' => true]));
|
||||
$this->assertSame($prior['offerPreparations'], $store['offerPreparations']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6f-services-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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 IvaImportSpecialRegimesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g5c-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:334', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:334'];
|
||||
$this->assertCount(6, $book['rows']);
|
||||
$this->assertSame(['special_economic_zone_import', 'free_zone_import', 'free_warehouse_import', 'general_free_warehouse_import', 'customs_warehouse_import', 'duty_free_shop_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(array_fill(0, 6, '0.00'), array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(array_fill(0, 6, 'exempt'), array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G5C special_economic_zone_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('14(1)(a)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6d-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:333'], $store['importExemptions']['opportunity:333']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g5c-review-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaImportSuppliesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_fiscal_snapshot_remains_bounded_after_preserving_larger_histories(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$snapshot = json_encode(['padding' => str_repeat('x', 6000000)], JSON_THROW_ON_ERROR);
|
||||
$this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => ['modelo_a_snapshot' => $snapshot]], ['Idempotency-Key' => (string) Str::uuid()])
|
||||
->assertUnprocessable()->assertJsonValidationErrors('economic_snapshot.modelo_a_snapshot');
|
||||
}
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6e-imports.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:335', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['importExemptions']['opportunity:335'];
|
||||
$this->assertCount(8, $book['rows']);
|
||||
$this->assertSame(['ship_provisions_import','ship_fuel_import','ship_technical_products_import','ship_cargo_accessories_import','aircraft_provisions_import','aircraft_fuel_import','aircraft_technical_products_import','aircraft_cargo_accessories_import'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(array_fill(0, 8, '0.00'), array_column($book['result']['rows'], 'importVat'));
|
||||
$this->assertSame(array_fill(0, 8, 'exempt'), array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('5000', $book['rows'][0]['declaredValue']);
|
||||
$this->assertSame('SYNTHETIC QA G6E ship_provisions_import', $book['rows'][0]['documentRef']);
|
||||
$this->assertStringContainsString('12(1)(g)', $book['result']['source']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offers-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertSame($prior['importExemptions'], array_diff_key($store['importExemptions'], ['opportunity:335' => true]));
|
||||
$this->assertSame($prior['offerPreparations'], $store['offerPreparations']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g6e-supplies-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 IvaInternationalAssetDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_international_asset_rules_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g4-transport-20261024/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']);
|
||||
$this->assertSame('opportunity:324', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:324'];
|
||||
$this->assertSame('opportunity:324', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('400.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(4, $book['rows']);
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g4a-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g4-transport-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2H_INPUT') ?: base_path('outputs/iva-l1-g2-listed-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:317'];
|
||||
$this->assertCount(18, $book['result']['rows']);
|
||||
$this->assertSame('0.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaListedServicesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_listed_services_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g9-nondigital.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:350', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['listedServices']['opportunity:350'];
|
||||
$this->assertCount(30, $book['rows']);
|
||||
$this->assertCount(10,array_unique(array_column($book['rows'],'treatment')));
|
||||
$this->assertSame(array_merge(...array_fill(0,10,['national','outside','national'])),array_column($book['result']['rows'],'territory'));
|
||||
$this->assertSame(array_merge(...array_fill(0,10,['acquirer','outside','provider'])),array_column($book['result']['rows'],'responsible'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g9-nondigital-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior, array_diff_key($store, ['listedServices' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g9-nondigital-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaNoncashBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_noncash_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7e-bases.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:343', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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('500.25', $book['rows'][0]['cashAmount']);
|
||||
$this->assertSame('2200.50', $book['rows'][0]['normalValue']);
|
||||
$this->assertStringContainsString('parte monetária', $book['rows'][0]['cashRef']);
|
||||
$this->assertStringContainsString('bens/serviços B', $book['rows'][0]['exchangeDescription']);
|
||||
$this->assertStringContainsString('acordo A', $book['rows'][0]['agreementRef']);
|
||||
$this->assertStringContainsString('fundamento A', $book['rows'][0]['valuationRef']);
|
||||
$this->assertStringContainsString('retalho', $book['rows'][0]['valuationScope']);
|
||||
$this->assertStringContainsString('15(3)/(4)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7e-preserved-inputs.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, ['noncashBases' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7e-noncash-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaOfferPathsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-paths.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:334', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['offerPreparations']['opportunity:334'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['P084','P085'], array_column($book['rows'], 'branch'));
|
||||
$this->assertSame(['import','acquisition'], array_column($book['rows'], 'operation'));
|
||||
$this->assertArrayNotHasKey('result', $book);
|
||||
$this->assertCount(3, $book['history']);
|
||||
$this->assertSame('SYNTHETIC QA finalidade editada deliberadamente', $book['saved']['rows'][0]['purpose']);
|
||||
$this->assertSame('SYNTHETIC QA cheias', $book['rows'][1]['disaster']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g6e-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertSame($prior['importExemptions'], $store['importExemptions']);
|
||||
$this->assertSame('presented', $book['rows'][0]['request']['state']);
|
||||
$this->assertSame('granted', $book['rows'][0]['requestRecords'][0]['request']['state']);
|
||||
$this->assertSame('SYNTHETIC QA apenas bens A', $book['rows'][0]['requestRecords'][0]['request']['goods']);
|
||||
$this->assertSame('2026-11', $book['rows'][0]['requestRecords'][0]['request']['periodTo']);
|
||||
$this->assertSame('SYNTHETIC QA assistência imediata às vítimas das cheias', $book['rows'][1]['humanitarianPurpose']);
|
||||
$this->assertSame('800', $book['rows'][0]['normalVat']);
|
||||
$this->assertSame('yes', $book['rows'][1]['conditionalAssumption']);
|
||||
$this->assertArrayNotHasKey('appliedBenefit', $book);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-offer-paths-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaOfferPreparationsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_import_classification_recovers_privately_without_changing_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-offer-preparations.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:334', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['offerPreparations']['opportunity:334'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['P084','P085'], array_column($book['rows'], 'branch'));
|
||||
$this->assertSame(['import','acquisition'], array_column($book['rows'], 'operation'));
|
||||
$this->assertArrayNotHasKey('result', $book);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('Edição posterior', $book['saved']['rows'][0]['purpose']);
|
||||
$this->assertSame('SYNTHETIC QA cheias', $book['rows'][1]['disaster']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g5c-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['salesOperations'], $store['salesOperations']);
|
||||
$this->assertSame($prior['books'], $store['books']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:330'], $store['importExemptions']['opportunity:330']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:331'], $store['importExemptions']['opportunity:331']);
|
||||
$this->assertSame($prior['importExemptions']['opportunity:332'], $store['importExemptions']['opportunity:332']);
|
||||
$this->assertSame($prior['importExemptions'], $store['importExemptions']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['17']);
|
||||
$this->assertStringContainsString('BR89', $store['books']['opportunity:329']['result']['sources']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g5d-offer-drafts-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
use App\Models\User;
|
||||
use App\Jobs\ScanDocumentForMalware;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 IvaOnboardSupplyDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_onboard_supplies_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g4-supplies-20261024/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']);
|
||||
$this->assertSame('opportunity:326', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:326'];
|
||||
$this->assertSame('opportunity:326', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$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'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g4c-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g4-supplies-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaOperationsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_l1_ui_payload_round_trips_without_duplicate_drafts_or_new_rules_and_other_owner_cannot_read(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$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;
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$path = getenv('IVA_L1_UI_INPUT') ?: base_path('tests/frontend/fixtures/iva-operations.json');
|
||||
$draft = json_decode(file_get_contents($path), true, flags: JSON_THROW_ON_ERROR);
|
||||
$draft['purpose'] = 'simulate_only';
|
||||
$key = (string) Str::uuid();
|
||||
$payload = ['personal_snapshot' => [], 'economic_snapshot' => $draft];
|
||||
$created = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => $key])->assertCreated();
|
||||
$id = $created->json('data.id');
|
||||
$retry = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => $key]);
|
||||
$this->assertSame($id, $retry->json('data.id'));
|
||||
$saved = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$economic = $saved->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $economic['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['context_opportunity'], $economic['context_opportunity']);
|
||||
$store = json_decode($economic['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations'][$draft['context_opportunity']];
|
||||
$this->assertSame('iva-operations-l1/1', $book['result']['version']);
|
||||
$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));
|
||||
$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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaOwnNameDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_own_name_circuits_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g10-own-name.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:352', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['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'));
|
||||
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->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$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]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g10-own-name-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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 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');
|
||||
$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(getenv('IVA_G2K_INPUT') ?: base_path('outputs/iva-l1-g2-pharma-inputs-20261024/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']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true);
|
||||
$book = $store['salesOperations']['opportunity:320'];
|
||||
$this->assertSame('opportunity:320', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertCount(5, $book['result']['rows']);
|
||||
$this->assertSame('500.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$this->assertSame('0.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertNotSame($book['rows'][1]['pharmaAnnexItem'], $book['rows'][2]['pharmaAnnexItem']);
|
||||
$this->assertStringContainsString('2912.19.00', $book['result']['rows'][1]['source']);
|
||||
$this->assertStringContainsString('2912.19.00', $book['result']['rows'][2]['source']);
|
||||
$this->assertStringContainsString('2935.', $book['result']['rows'][3]['source']);
|
||||
$this->assertStringContainsString('PDF16', $book['result']['rows'][4]['source']);
|
||||
$original = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-fundraising.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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 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');
|
||||
$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-l1-g2-production-20261024/calendar-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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:318'];
|
||||
$this->assertSame('2020-02-29', $book['rows'][2]['taxOption']['startupDate']);
|
||||
$this->assertStringContainsString('24 horas de 2025-02-28', $book['result']['rows'][2]['reason']);
|
||||
$this->assertStringContainsString('production-option/2', $book['result']['rows'][2]['reason']);
|
||||
$this->assertSame('48.00', $book['result']['periods'][0]['fields']['02']);
|
||||
$original = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-production.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$old = json_decode($original['modelo_a_snapshot'], true)['salesOperations']['opportunity:318']['result'];
|
||||
$this->assertSame($old, $book['history'][array_key_last($book['history'])]);
|
||||
file_put_contents(base_path('outputs/iva-l1-g2-production-20261024/calendar-recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 IvaProductionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_production_context_preserves_accepted_opportunities(): 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(getenv('IVA_G2I_INPUT') ?: base_path('outputs/iva-l1-g2-production-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:318'];
|
||||
$this->assertCount(7, $book['result']['rows']);
|
||||
$this->assertSame('300.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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']);
|
||||
$this->assertSame('300.00', $book['result']['periods'][0]['fields']['01']);
|
||||
$this->assertSame('48.00', $book['result']['periods'][0]['fields']['02']);
|
||||
$this->assertSame('2024-12-15', $book['rows'][2]['taxOption']['declarationDate']);
|
||||
$this->assertSame('2026-10-15', $book['rows'][2]['taxOption']['operationDate']);
|
||||
if (getenv('IVA_G2I_RECOVERED')) file_put_contents(getenv('IVA_G2I_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaPropertyTransferDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_propertytransfers_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-property-transfers.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:356', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['propertyTransfers']['opportunity:356'];
|
||||
$this->assertCount(3, $book['rows']);
|
||||
$this->assertSame(['binding_lease','business_onerous','business_free'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['goods_transmission','tax_not_exigible_3_5','tax_not_exigible_3_5'],array_column($book['result']['rows'],'classification'));
|
||||
$this->assertSame(['1250.123456',null,null],array_column($book['result']['rows'],'baseAmount'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('1250.123456',$book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-property-transfers-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, ['propertyTransfers' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-property-transfers-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaPublicAuthorityBaseDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_public_act_base_recovers_privately_without_changing_delivered_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]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7a-bases.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:339', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['publicAuthorityBases']['opportunity:339'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['public_authority_indemnity','public_authority_compensation'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1500.25','1250.30'], 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('2026-12', $book['rows'][0]['period']);
|
||||
$this->assertSame('SYNTHETIC QA acto A,operação própria', $book['rows'][0]['actRef']);
|
||||
$this->assertSame('mixed', $book['rows'][1]['compensationForm']);
|
||||
$this->assertSame('1000.10', $book['rows'][1]['moneyAmount']);
|
||||
$this->assertSame('250.20', $book['rows'][1]['nonMoneyValue']);
|
||||
$this->assertStringContainsString('valor normal', $book['rows'][1]['valuationRef']);
|
||||
$this->assertStringContainsString('composição15(5)/(6)', $book['rows'][1]['compositionRef']);
|
||||
$this->assertStringContainsString('15(2)(d)', $book['result']['source']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$this->assertNull($book['history'][1]['rows'][0]['vat']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7a-preserved-inputs.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, ['publicAuthorityBases' => true]));
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertStringContainsString('Plano de importações', $store['importExemptions']['opportunity:338']['rows'][1]['developmentPlanRef']);
|
||||
$this->assertSame('0.00', $store['importExemptions']['opportunity:336']['result']['rows'][0]['serviceVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7a-public-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 IvaPublicationsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_publications_context_preserves_accepted_opportunities(): 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(getenv('IVA_G2D_INPUT') ?: base_path('outputs/iva-l1-g2-publications-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:313'];
|
||||
$this->assertCount(2, $book['result']['rows']);
|
||||
$this->assertSame('200.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_G2D_RECOVERED')) file_put_contents(getenv('IVA_G2D_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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 IvaRationalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_periodic_results_and_accepted_first_opportunity_round_trip_exactly(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$path = getenv('IVA_RATIONAL_INPUT') ?: base_path('tests/frontend/fixtures/iva-rational.json');
|
||||
$draft = json_decode(file_get_contents($path), true, flags: JSON_THROW_ON_ERROR);
|
||||
$store = json_decode($draft['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$first = $store['salesOperations']['opportunity:309'];
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$economic = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $economic['modelo_a_snapshot']);
|
||||
$saved = json_decode($economic['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($first, $saved['salesOperations']['opportunity:309']);
|
||||
$second = $saved['salesOperations']['opportunity:310']['result'];
|
||||
$this->assertSame('iva-operations-l1/2', $second['version']);
|
||||
$this->assertSame(['numerator' => '20', 'denominator' => '21'], $second['rows'][0]['exact']['net']);
|
||||
$this->assertSame(['numerator' => '1', 'denominator' => '21'], $second['rows'][0]['exact']['vat']);
|
||||
$this->assertSame('0.047619', $second['rows'][0]['vat']);
|
||||
if (getenv('IVA_RATIONAL_RECOVERED')) file_put_contents(getenv('IVA_RATIONAL_RECOVERED'), json_encode($economic, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaReducedBasesDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_reduced_bases_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7-reduced.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:351', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['regulatedReducedBases']['opportunity:351'];
|
||||
$this->assertCount(4, $book['rows']);
|
||||
$this->assertSame(['regulated_energy','aeronautical_fees','public_works','public_water'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['620.155','850.2125','400.10','750.1875'],array_column($book['result']['rows'],'baseAmount'));
|
||||
$this->assertSame(['62%','85%','40%','75%'],array_column($book['result']['rows'],'deductionProportion'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('620.155',$book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7-reduced-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, ['regulatedReducedBases' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7-reduced-bases-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 IvaRefundDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_refund_recovers_allocation_request_decision_receipts_history_and_all_prior_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-d-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['ivaRefunds']['opportunity:374'];$this->assertCount(1,$b['rows']);$this->assertCount(1,$b['history']);
|
||||
$r=$b['result']['rows'][0];$this->assertSame('determined',$r['status']);$this->assertSame('compatible',$r['eligibility']);
|
||||
foreach(['requested'=>'600000','reported'=>'200000','approved'=>'550000','received'=>'450000','awaitingReceipt'=>'100000','notGranted'=>'50000']as $f=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$r[$f]);
|
||||
$input=$b['result']['inputs'][0];$this->assertSame('SYNTHETIC QA pedidoR1',$input['requestReference']);$this->assertSame('2026-02-15',$input['requestDate']);$this->assertSame('partial',$input['decision']);$this->assertSame('SYNTHETIC QA decisãoD1',$input['decisionReference']);$this->assertCount(2,$input['receipts']);
|
||||
$allocation=$s['ivaClosures']['opportunity:374']['result']['rows'][0];foreach(['25'=>'800000','26'=>'200000','27'=>'600000']as $f=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$allocation['fields'][(string)$f]);
|
||||
$accepted=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3d-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$accepted=json_decode($accepted['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
foreach($accepted as $key=>$map){if($key==='version')continue;foreach($map as $context=>$original)$this->assertSame($original,$s[$key][$context]);}
|
||||
$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]);}
|
||||
$old=$s['ivaClosures']['opportunity:373']['result']['rows'][2];$this->assertSame(['numerator'=>'72','denominator'=>'1'],$old['fields']['24']);$this->assertSame(['numerator'=>'30','denominator'=>'1'],$old['paid']);$this->assertSame(['numerator'=>'42','denominator'=>'1'],$old['outstanding']);
|
||||
file_put_contents(base_path('outputs/iva-l3-d-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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 IvaRegularizationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_frozen_d_adjustments_assets_totals_and_history_recover_without_changing_other_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('outputs/iva-l2-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);
|
||||
$e=$s['regularizations']['opportunity:370'];
|
||||
$this->assertCount(2,$e['events']);$this->assertCount(1,$e['history']);
|
||||
$this->assertSame(['numerator'=>'132','denominator'=>'25'],$e['result']['events'][0]['delta']);
|
||||
$this->assertSame(['numerator'=>'4','denominator'=>'3'],$s['books']['opportunity:370']['result']['periods'][0]['exactFields']['13']);
|
||||
foreach(['12'=>'5.28','13'=>'1.333333','15'=>'29.44','16'=>'161.333333','17'=>'131.893333','18'=>'0.00'] as $field=>$value)$this->assertSame($value,$s['books']['opportunity:370']['result']['periods'][0]['fields'][(string)$field]);
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2e-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$prior=json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior['books']['opportunity:370']['result'],$s['books']['opportunity:370']['history'][array_key_last($s['books']['opportunity:370']['history'])]);
|
||||
$this->assertSame($prior['books']['opportunity:370']['result'],$e['events'][0]['source']);
|
||||
foreach($prior as $key=>$map){if($key==='version')continue;foreach($map as $context=>$original){if($key==='books'&&$context==='opportunity:370')continue;$this->assertSame($original,$s[$key][$context]);}}
|
||||
$this->assertSame('08',$s['books']['opportunity:372']['rows'][0]['field']);
|
||||
$this->assertSame(['numerator'=>'16','denominator'=>'3'],$s['books']['opportunity:372']['result']['rows'][0]['deductibleExact']);
|
||||
file_put_contents(base_path('outputs/iva-l2-e-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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 IvaRemissionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_four_remission_families_recover_preserving128_accepted_books_and_partial_baggage():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-remission.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:367',$recovered['context_opportunity']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['remissionImports']['opportunity:367'];$this->assertCount(42,$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('CIVA12(1)b',$row['source']);}
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-remission-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$prior=json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);foreach($prior as $key=>$value)$this->assertSame($value,$s[$key]);
|
||||
$path=base_path('outputs/iva-l1-p047-families-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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaSecondhandDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_secondhand_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-secondhand.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:354', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['regulatedSecondhands']['opportunity:354'];
|
||||
$this->assertCount(8, $book['rows']);
|
||||
$this->assertSame(array_merge(array_fill(0,4,'reseller_margin'),array_fill(0,4,'auction_margin')),array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(array_merge(array_fill(0,4,'138.00'),array_fill(0,4,'344.83')),array_column($book['result']['rows'],'baseAmount'));
|
||||
$this->assertSame(array_fill(0,8,'qualified_goods'),array_column($book['result']['rows'],'classification'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame('138.00',$book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-secondhand-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, ['regulatedSecondhands' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-secondhand-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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 IvaServiceLocationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_service_locations_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g8-services.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:349', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['serviceLocations']['opportunity:349'];
|
||||
$this->assertCount(10, $book['rows']);
|
||||
$this->assertSame(['general_service','general_service','immovable_service','immovable_service','movable_work','movable_work','activity_service','activity_service','transport_service','transport_service'],array_column($book['rows'],'treatment'));
|
||||
$this->assertSame(['national','outside','national','outside','national','outside','national','outside','national','outside'],array_column($book['result']['rows'],'territory'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['rate']);
|
||||
}
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g8-services-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, ['serviceLocations' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g8-services-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 IvaServiceNormalDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_service_normals_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7i-bases.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:347', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['serviceNormals']['opportunity:347'];
|
||||
$this->assertCount(3, $book['rows']);
|
||||
$this->assertSame(['free_company_service','private_company_asset_use','exempt_sector_asset_use'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['500.25','700.50','900.75'], array_column($book['result']['rows'], 'baseAmount'));
|
||||
$this->assertSame(['determined','determined','determined'], array_column($book['result']['rows'], 'status'));
|
||||
$this->assertSame([null,null,null], array_column($book['result']['rows'], 'vat'));
|
||||
$this->assertSame([null,null,null], array_column($book['result']['rows'], 'rate'));
|
||||
$this->assertArrayNotHasKey('priorDeduction', $book['rows'][0]['conditions']);
|
||||
$this->assertSame('yes', $book['rows'][1]['conditions']['priorDeduction']);
|
||||
$this->assertSame('yes', $book['rows'][2]['conditions']['exemptSector']);
|
||||
$this->assertStringContainsString('bens/elementos A', $book['rows'][1]['assetRef']);
|
||||
$this->assertStringContainsString('dedução anterior parcial A', $book['rows'][2]['deductionRef']);
|
||||
$this->assertStringContainsString('finalidade/destinatário', $book['rows'][0]['purposeRef']);
|
||||
$this->assertStringContainsString('estádio/tempo/lugar', $book['rows'][2]['valuationScope']);
|
||||
$this->assertStringContainsString('15(2)(c)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7i-preserved-inputs.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, ['serviceNormals' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7i-service-normal-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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 IvaServicesGroupDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_services_group_round_trips_with_conditions_and_source(): 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(getenv('IVA_G1_INPUT') ?: base_path('outputs/iva-l1-groups-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'];
|
||||
$this->assertCount(4, $book['result']['rows']);
|
||||
$this->assertSame('400.00', $book['result']['periods'][0]['fields']['07']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G1_RECOVERED')) file_put_contents(getenv('IVA_G1_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 IvaServicesNatureDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_services_context_preserves_accepted_opportunities(): 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(getenv('IVA_G2F_INPUT') ?: base_path('outputs/iva-l1-g2-services-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:315'];
|
||||
$this->assertCount(3, $book['result']['rows']);
|
||||
$this->assertSame('300.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$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_G2F_RECOVERED')) file_put_contents(getenv('IVA_G2F_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 IvaSocialDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_social_context_preserves_both_accepted_opportunities(): 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(getenv('IVA_G2B_INPUT') ?: base_path('outputs/iva-l1-g2-social-20261024/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']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:311'];
|
||||
$this->assertCount(6, $book['result']['rows']);
|
||||
$this->assertSame('600.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_G2B_RECOVERED')) file_put_contents(getenv('IVA_G2B_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 IvaSpecialRegimeDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_special_regimes_recover_with_the_selected_opportunity_and_previous_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('outputs/iva-l1-g5-regimes-20261024/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']);
|
||||
$this->assertSame('opportunity:328', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:328'];
|
||||
$this->assertSame('opportunity:328', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-12', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('600.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(6, $book['rows']);
|
||||
$this->assertSame(['economic_zone','customs_warehouse','free_zone','duty_free_shop','transit','temporary_import'], array_column($book['rows'], 'specialRegime'));
|
||||
foreach ($book['result']['rows'] as $row) {
|
||||
$this->assertSame('05', $row['field']);
|
||||
$this->assertSame('0.00', $row['vat']);
|
||||
}
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g4e-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g5-regimes-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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 IvaSubstitutionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_substitution_recovers_frozen_predecessor_difference_payments_history_and_all_prior_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-c-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['ivaSubstitutions']['opportunity:373'];$this->assertCount(1,$b['rows']);$this->assertCount(1,$b['history']);
|
||||
$r=$b['result']['rows'][0];$this->assertSame('determined',$r['status']);foreach(['17'=>'220','18'=>'0','21'=>'60','22'=>'60','23'=>'1','24'=>'61']as $f=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$r['fields'][(string)$f]);
|
||||
foreach(['19','20','25','26','27']as $f)$this->assertNull($r['fields'][(string)$f]);
|
||||
foreach(['paid'=>'20','outstanding'=>'41','totalPaid'=>'50','totalOutstanding'=>'83']as $f=>$v)$this->assertSame(['numerator'=>$v,'denominator'=>'1'],$r[$f]);
|
||||
$input=$b['result']['inputs'][0];$this->assertSame('SYNTHETIC QA declaraçãoMarço',$input['priorReference']);$this->assertSame('2026-04-15',$input['priorDate']);$this->assertSame('SYNTHETIC QA reciboP2',$input['payments'][0]['reference']);
|
||||
$prior=$s['ivaClosures']['opportunity:373']['result']['rows'][2];$this->assertSame(['numerator'=>'72','denominator'=>'1'],$prior['fields']['24']);$this->assertSame(['numerator'=>'30','denominator'=>'1'],$prior['paid']);$this->assertSame(['numerator'=>'42','denominator'=>'1'],$prior['outstanding']);
|
||||
$accepted=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3c-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$accepted=json_decode($accepted['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$this->assertSame($accepted['ivaClosures'],$s['ivaClosures']);
|
||||
$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]);}
|
||||
file_put_contents(base_path('outputs/iva-l3-c-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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 IvaTemporaryBenefitDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_cessation_and_explicit_continuations_recover_with_their_opportunity_and_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('outputs/iva-l1-g3-temporary-20261024/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']);
|
||||
$this->assertSame('opportunity:322', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['salesOperations']['opportunity:322'];
|
||||
$this->assertSame('opportunity:322', $book['result']['opportunity']);
|
||||
$this->assertSame('MZN', $book['result']['currency']);
|
||||
$this->assertSame('2026-10', $book['result']['periods'][0]['period']);
|
||||
$this->assertSame('700.00', $book['result']['periods'][0]['fields']['01']);
|
||||
$this->assertSame('112.00', $book['result']['periods'][0]['fields']['02']);
|
||||
$this->assertSame('100.00', $book['result']['periods'][0]['fields']['05']);
|
||||
$this->assertCount(8, $book['rows']);
|
||||
$this->assertSame('116', $book['rows'][0]['amount']);
|
||||
$this->assertSame('included', $book['rows'][0]['basis']);
|
||||
$this->assertSame('temporary_sugar', $book['rows'][0]['temporaryBenefitOrigin']);
|
||||
$this->assertSame('temporary_solar_inputs', $book['rows'][6]['temporaryBenefitOrigin']);
|
||||
$this->assertSame('production_agriculture', $book['rows'][7]['treatment']);
|
||||
$this->assertStringContainsString('P045', $book['rows'][6]['source']);
|
||||
$this->assertCount(7, $book['history'][0]['rows']);
|
||||
$this->assertNull($book['history'][0]['periods'][0]['fields']['01']);
|
||||
$this->assertStringContainsString('terminou em31/12/2025', $book['history'][0]['rows'][0]['reason']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-annex-i-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
||||
$this->assertSame($original, $store['salesOperations'][$context]);
|
||||
}
|
||||
file_put_contents(base_path('outputs/iva-l1-g3-temporary-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 IvaTravelEventDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_travel_margin_and_special_events_recover_without_changing_accepted_books(): void
|
||||
{
|
||||
$target=DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test',$target->name);
|
||||
$this->assertSame(55441,(int)$target->port);
|
||||
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));
|
||||
$draft=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-travel-events.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>[],'economic_snapshot'=>$draft],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);
|
||||
$this->assertSame('opportunity:360',$recovered['context_opportunity']);
|
||||
$this->assertSame('Manica',$recovered['selection_labels']['province_id']);
|
||||
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$travel=$store['travelOperations']['opportunity:360'];$events=$store['travelSpecialEvents']['opportunity:360'];
|
||||
$this->assertCount(10,$travel['rows']);$this->assertCount(5,$travel['periods']);$this->assertCount(12,$events['rows']);
|
||||
$this->assertSame('0.00',$travel['result']['periods'][0]['baseAmount']);
|
||||
$this->assertSame('1160.00',$travel['result']['periods'][1]['carryForward']);
|
||||
$this->assertSame('500.00',$travel['result']['periods'][2]['baseAmount']);
|
||||
$this->assertSame('1160.00',$travel['result']['rows'][4]['generalGross']);
|
||||
$this->assertSame('general',$travel['result']['rows'][5]['regime']);
|
||||
$this->assertSame('outside',$travel['result']['rows'][9]['regime']);
|
||||
$this->assertSame('2026-12-05',$events['result']['rows'][0]['eventDate']);
|
||||
$this->assertSame('2026-12-10',$events['result']['rows'][1]['eventDate']);
|
||||
$this->assertNull($events['result']['rows'][3]['eventDate']);
|
||||
$this->assertSame('232.00',$events['result']['rows'][4]['dueEvents'][0]['amount']);
|
||||
$this->assertSame('928.00',$events['result']['rows'][4]['dueEvents'][1]['amount']);
|
||||
$this->assertSame('2026-12-08',$events['result']['rows'][4]['dueEvents'][1]['date']);
|
||||
$this->assertSame('deferred',$events['result']['rows'][11]['status']);
|
||||
foreach($events['result']['rows'] as $row){$this->assertNull($row['baseAmount']);$this->assertNull($row['vat']);$this->assertNull($row['deduction']);}
|
||||
$this->assertCount(1,$travel['history']);$this->assertCount(1,$events['history']);
|
||||
$this->assertSame($travel['rows'],$travel['result']['inputs']);$this->assertSame($events['rows'],$events['result']['inputs']);
|
||||
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-travel-events-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$prior=json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
|
||||
$this->assertSame($prior,array_diff_key($store,['travelOperations'=>true,'travelSpecialEvents'=>true]));
|
||||
$this->assertSame('regulation_pending',$store['digitalOperations']['opportunity:359']['result']['rows'][0]['procedure']);
|
||||
$this->assertNull($store['digitalOperations']['opportunity:359']['result']['rows'][0]['vat']);
|
||||
$this->assertSame('potential',$store['foreignOperations']['opportunity:358']['result']['rows'][0]['relation19']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-travel-events-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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 IvaValueReviewDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_value_reviews_recover_privately_preserving_all_delivered_books(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7h-bases.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:346', $recovered['context_opportunity']);
|
||||
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
||||
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$book = $store['valueReviews']['opportunity:346'];
|
||||
$this->assertCount(2, $book['rows']);
|
||||
$this->assertSame(['price_comparison','referenced_correction'], array_column($book['rows'], 'treatment'));
|
||||
$this->assertSame(['1000.25','1400.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(['below','below'], array_column($book['result']['rows'], 'comparison'));
|
||||
$this->assertSame('1000.25', $book['rows'][0]['declaredAmount']);
|
||||
$this->assertSame('1500.50', $book['rows'][0]['referenceAmount']);
|
||||
$this->assertSame('1400.75', $book['rows'][1]['correctedAmount']);
|
||||
$this->assertSame('projected', $book['rows'][1]['origin']);
|
||||
$this->assertSame('yes', $book['rows'][1]['correctionApplies']);
|
||||
$this->assertSame('retail', $book['rows'][1]['priceContext']);
|
||||
$this->assertSame('2026-12-20', $book['rows'][1]['correctionDate']);
|
||||
$this->assertStringContainsString('condicionado correcção A', $book['rows'][1]['correctionRef']);
|
||||
$this->assertStringContainsString('dezembro2026', $book['rows'][1]['correctionScope']);
|
||||
$this->assertStringContainsString('Cenário condicionado', $book['result']['rows'][1]['reason']);
|
||||
$this->assertStringContainsString('15(7)', $book['result']['source']);
|
||||
$this->assertSame($book['rows'], $book['result']['inputs']);
|
||||
$this->assertCount(2, $book['history']);
|
||||
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
||||
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7h-preserved-inputs.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, ['valueReviews' => true]));
|
||||
$this->assertSame('1250.30', $store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['baseAmount']);
|
||||
$this->assertNull($store['publicAuthorityBases']['opportunity:339']['result']['rows'][1]['vat']);
|
||||
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
||||
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
||||
file_put_contents(base_path('outputs/iva-l1-g7h-value-review-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +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 ModeloAAcquisitionsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_ui_calculated_payload_is_saved_recovered_and_used_as_the_report_source(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$path = getenv('IVA_ACQUISITION_UI_INPUT') ?: base_path('tests/frontend/fixtures/modelo-a-acquisitions.json');
|
||||
$draft = json_decode(file_get_contents($path), true, flags: JSON_THROW_ON_ERROR);
|
||||
$draft['purpose'] = 'simulate_only';
|
||||
$created = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$created->json('data.id'))->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame($draft['context_opportunity'], $recovered['context_opportunity']);
|
||||
if (getenv('IVA_ACQUISITION_UI_RECOVERED_OUT')) file_put_contents(getenv('IVA_ACQUISITION_UI_RECOVERED_OUT'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function test_calculated_acquisitions_round_trip_in_private_draft_and_other_owner_cannot_read(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$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;
|
||||
$actor = User::factory()->create(['email_verified_at' => now()]);
|
||||
$this->actingAs($actor);
|
||||
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/modelo-a-acquisitions.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$draft['purpose'] = 'simulate_only';
|
||||
$created = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$id = $created->json('data.id');
|
||||
$this->assertNotEmpty($id);
|
||||
$saved = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
||||
$economic = $saved->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $economic['modelo_a_snapshot']);
|
||||
$store = json_decode($economic['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$first = $store['books']['opportunity:309'];
|
||||
$this->assertSame('144.0048', $first['result']['periods'][0]['fields'][17]);
|
||||
$store['books']['opportunity:310'] = $first;
|
||||
$store['books']['opportunity:310']['rows'][0]['net'] = '200';
|
||||
$store['books']['opportunity:310']['rows'][0]['vat'] = '32';
|
||||
$economic['context_opportunity'] = 'opportunity:310';
|
||||
$economic['modelo_a_snapshot'] = json_encode($store, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => [], 'economic_snapshot' => $economic], ['If-Match' => $saved->headers->get('ETag')])->assertOk();
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($economic['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$this->assertSame($first, json_decode($recovered['modelo_a_snapshot'], true)['books']['opportunity:309']);
|
||||
if (getenv('IVA_ACQUISITION_RECOVERED_OUT')) {
|
||||
// The original calculated opportunity, recovered through the real private API, is the report source.
|
||||
$economic['context_opportunity'] = 'opportunity:309';
|
||||
file_put_contents(getenv('IVA_ACQUISITION_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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\RunSimulation;
|
||||
use App\Models\Simulation;
|
||||
use App\Models\SimulationTaxRuleVersion;
|
||||
use App\Models\User;
|
||||
use App\Services\SimulationExecution;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class SimulatorClosureRecoveryTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_existing_monthly_admission_can_be_read_and_finished_when_new_admissions_are_off(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
Queue::fake();
|
||||
// Reuse the existing isolated synthetic rule. No create/publish/suspend of any rule.
|
||||
$rule = SimulationTaxRuleVersion::findOrFail('01a15e50-7972-72e0-8991-82ca28df9b49');
|
||||
$before = $this->ruleFingerprint();
|
||||
config(['simulation-fiscal-consumer.enabled' => true, 'simulation-fiscal-consumer.rule_id' => $rule->id, 'simulation-fiscal-consumer.rule_version' => $rule->rule_version]);
|
||||
$actor = User::factory()->create(['email_verified_at' => now()]);
|
||||
$input = ['scenario_kind' => 'fiscal_rule_published', 'currency' => 'MZN', 'scope_declared' => true, 'sales_vat_basis' => 'net', 'monthly_sales' => [['date' => '2026-01-01', 'amount' => '1000.03']]];
|
||||
$id = $this->actingAs($actor)->postJson('/api/v1/simulations', $input, ['Idempotency-Key' => (string) Str::uuid()])->assertAccepted()->json('data.id');
|
||||
$count = Simulation::count();
|
||||
config(['simulation-fiscal-consumer.enabled' => false]);
|
||||
$this->getJson('/api/v1/fiscal-consumer')->assertOk()->assertJsonPath('data.enabled', false);
|
||||
$this->getJson('/api/v1/simulations/'.$id)->assertOk()->assertJsonPath('data.id', $id)->assertJsonPath('data.status', 'queued');
|
||||
$this->postJson('/api/v1/simulations', $input, ['Idempotency-Key' => (string) Str::uuid()])->assertStatus(503);
|
||||
(new RunSimulation($id, $actor->id, null))->handle(app(SimulationExecution::class));
|
||||
$this->getJson('/api/v1/simulations/'.$id)->assertOk()->assertJsonPath('data.id', $id)->assertJsonPath('data.status', 'completed');
|
||||
$this->assertSame($count, Simulation::count());
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]))->getJson('/api/v1/simulations/'.$id)->assertNotFound();
|
||||
$this->assertSame($before, $this->ruleFingerprint());
|
||||
}
|
||||
|
||||
private function ruleFingerprint(): string
|
||||
{
|
||||
return 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;
|
||||
}
|
||||
|
||||
public function test_cashflow_original_currency_and_amounts_round_trip_in_the_existing_private_draft(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$actor = User::factory()->create(['email_verified_at' => now()]);
|
||||
$this->actingAs($actor);
|
||||
$id = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA — moeda de tesouraria', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$snapshot = json_encode(['version' => 2, 'currency' => 'USD', 'taxMode' => 'fixed', 'inputs' => ['monthlyRevenue' => '123', 'monthlyTaxSchedule' => ['0', '', '0']]], JSON_THROW_ON_ERROR);
|
||||
$this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => [], 'economic_snapshot' => ['purpose' => 'simulate_only', 'project_title' => 'SYNTHETIC QA — moeda', 'currency' => 'MZN', 'cashflow_snapshot' => $snapshot]], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
|
||||
$this->actingAs($actor->fresh());
|
||||
$saved = $this->getJson('/api/v1/simulation-drafts/current?context='.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame('MZN', $saved['currency']);
|
||||
$this->assertSame($snapshot, $saved['cashflow_snapshot']);
|
||||
$this->assertSame('USD', json_decode($saved['cashflow_snapshot'], true)['currency']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\ApprovedAdministrativeBoundaries;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class TerritoryGeometryConsumerAccessTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $actor;
|
||||
|
||||
private string $territory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
||||
$this->assertSame(55441, (int) $identity->port);
|
||||
$this->withoutVite();
|
||||
$this->withoutMiddleware(ThrottleRequests::class);
|
||||
config(['portal.profile_access_enabled' => true, 'portal.managers' => [], 'investor-path.enabled' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->actor = User::factory()->create(['two_factor_secret' => Crypt::encryptString('JBSWY3DPEHPK3PXP'), 'two_factor_confirmed_at' => now()]);
|
||||
$other = User::factory()->create();
|
||||
DB::table('portal_superuser_pair')->updateOrInsert(['id' => 1], ['first_user_id' => $this->actor->id, 'second_user_id' => $other->id, 'approved_by' => $other->id]);
|
||||
$this->territory = DB::table('geo_geometries as g')->join('geo_locations as l', 'l.id', '=', 'g.geo_location_id')
|
||||
->where('g.source_system', 'ine-cod-ab')->where('g.data_classification', 'internal')->where('l.location_type', 'province')->value('l.id');
|
||||
$this->assertNotEmpty($this->territory);
|
||||
}
|
||||
|
||||
public function test_general_consumer_uses_existing_authenticated_read_access_without_the_legacy_gate(): void
|
||||
{
|
||||
$this->assertFalse($this->actor->can('manage-portal'));
|
||||
$before = $this->fingerprint();
|
||||
$this->actingAs($this->actor)->getJson('/api/v1/investment/territory-geometries?territory_id='.$this->territory)
|
||||
->assertOk()->assertJsonPath('selected_geometry_available', true)->assertJsonPath('geometry_scope', 'authorized_internal')
|
||||
->assertJsonPath('areas.0.territory_id', $this->territory)->assertHeader('Cache-Control', 'no-store, private');
|
||||
$this->assertSame($before, $this->fingerprint());
|
||||
}
|
||||
|
||||
public function test_existing_administration_reaches_the_same_geometry_with_its_completed_mfa_session(): void
|
||||
{
|
||||
$this->actingAs($this->actor)->withSession(['portal.mfa_actor' => $this->actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $this->actor->portal_access_revision]);
|
||||
$this->getJson('/management/territory-geometries?territory_id='.$this->territory)->assertOk()->assertJsonPath('selected_geometry_available', true);
|
||||
session()->forget(['portal.mfa_actor', 'portal.mfa_at']);
|
||||
$this->getJson('/management/territory-geometries?territory_id='.$this->territory)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_anonymous_and_ordinary_accounts_do_not_receive_or_publish_internal_layers(): void
|
||||
{
|
||||
$before = $this->fingerprint();
|
||||
$url = '/api/v1/investment/territory-geometries?territory_id='.$this->territory;
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('geometry_scope', 'public')->assertJsonPath('selected_geometry_available', false)->assertJsonCount(0, 'areas');
|
||||
$this->actingAs(User::factory()->create())->getJson($url)->assertOk()->assertJsonPath('geometry_scope', 'public')->assertJsonCount(0, 'areas');
|
||||
$this->getJson('/management/territory-geometries?territory_id='.$this->territory)->assertForbidden();
|
||||
$this->assertSame($before, $this->fingerprint());
|
||||
}
|
||||
|
||||
public function test_saved_territory_is_recovered_in_dossier_and_simulator_and_the_map_uses_that_identity(): void
|
||||
{
|
||||
$this->actingAs($this->actor);
|
||||
$id = $this->postJson('/investimentos', ['title' => 'SYNTHETIC QA - mapa recuperado', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$body = ['version' => $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version'), 'selection' => ['territory' => 'territory:'.$this->territory]];
|
||||
$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();
|
||||
$view = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
$this->assertSame($this->territory, $view['context']['selection']['territory']['id']);
|
||||
$this->assertSame($this->territory, $view['prefill']['simulator']['province_id']);
|
||||
$this->getJson('/api/v1/investment/territory-geometries?territory_id='.$view['prefill']['simulator']['province_id'])
|
||||
->assertOk()->assertJsonPath('selected_geometry_available', true)->assertJsonPath('areas.0.selected_territory', true);
|
||||
$this->assertSame($this->territory, $this->getJson('/investimentos/'.$id.'/contexto')->json('context.selection.territory.id'));
|
||||
}
|
||||
|
||||
public function test_only_the_approved_unchanged_snapshot_is_public_without_reclassifying_the_original(): void
|
||||
{
|
||||
$before = $this->fingerprint();
|
||||
$row = DB::table('geo_geometries as g')->where('geo_location_id', $this->territory)->first([
|
||||
'g.id', 'g.geo_location_id', DB::raw("encode(sha256(ST_AsEWKB(g.geom)),'hex') as geometry_sha256"),
|
||||
DB::raw("encode(sha256(convert_to(g.properties::text,'UTF8')),'hex') as properties_sha256"),
|
||||
]);
|
||||
// The QA import has its own identities; never copy or replace production rows.
|
||||
$approved = $this->partialMock(ApprovedAdministrativeBoundaries::class);
|
||||
$approved->shouldReceive('snapshots')->andReturn([$row->id => [
|
||||
'territory_id' => $row->geo_location_id, 'geometry_sha256' => $row->geometry_sha256,
|
||||
'properties_sha256' => $row->properties_sha256,
|
||||
]]);
|
||||
$url = '/api/v1/investment/territory-geometries?territory_id='.$this->territory;
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('selected_geometry_available', true)
|
||||
->assertJsonPath('areas.0.data_classification', 'public')->assertJsonPath('investment_site', false);
|
||||
$this->actingAs(User::factory()->create())->getJson($url)->assertOk()->assertJsonPath('selected_geometry_available', true);
|
||||
$this->assertSame($before, $this->fingerprint());
|
||||
$this->assertSame('internal', DB::table('geo_geometries')->where('id', $row->id)->value('data_classification'));
|
||||
DB::table('geo_geometries')->where('id', $row->id)->update(['properties' => DB::raw("properties || '{\"qa_changed\":true}'::jsonb")]);
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('selected_geometry_available', false)->assertJsonCount(0, 'areas');
|
||||
$this->actingAs($this->actor)->getJson($url)->assertOk()->assertJsonPath('selected_geometry_available', true);
|
||||
}
|
||||
|
||||
public function test_public_manifest_has_the_exact_approved_scope_and_immutable_hash(): void
|
||||
{
|
||||
$items = app(ApprovedAdministrativeBoundaries::class)->snapshots();
|
||||
$this->assertCount(408, $items);
|
||||
$this->assertCount(408, array_unique(array_column($items, 'territory_id')));
|
||||
$this->assertSame(['2019-06-07'], array_values(array_unique(array_column($items, 'source_version'))));
|
||||
}
|
||||
|
||||
private function fingerprint(): string
|
||||
{
|
||||
return DB::selectOne("select md5(string_agg(row_to_json(g)::text,E'\\n' order by id)) as hash from geo_geometries g")->hash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\ApprovedAdministrativeBoundaries;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Runs in the normal delivery unit suite, without database or external services. */
|
||||
final class ApprovedAdministrativeBoundariesTest extends TestCase
|
||||
{
|
||||
public function test_public_scope_keeps_the_accepted_identity_and_refuses_changed_or_new_internal_shapes(): void
|
||||
{
|
||||
$approved = new ApprovedAdministrativeBoundaries;
|
||||
$items = $approved->snapshots();
|
||||
$this->assertCount(408, $items);
|
||||
$item = reset($items);
|
||||
$this->assertTrue($approved->allows($item['id'], $item['territory_id'], $item['geometry_sha256'], $item['properties_sha256']));
|
||||
$this->assertFalse($approved->allows('00000000-0000-0000-0000-000000000000', $item['territory_id'], $item['geometry_sha256'], $item['properties_sha256']));
|
||||
$this->assertFalse($approved->allows($item['id'], '00000000-0000-0000-0000-000000000000', $item['geometry_sha256'], $item['properties_sha256']));
|
||||
$this->assertFalse($approved->allows($item['id'], $item['territory_id'], str_repeat('0', 64), $item['properties_sha256']));
|
||||
$this->assertFalse($approved->allows($item['id'], $item['territory_id'], $item['geometry_sha256'], str_repeat('0', 64)));
|
||||
}
|
||||
|
||||
public function test_the_public_scope_keeps_the_accepted_edition_and_unique_territories(): void
|
||||
{
|
||||
$items = (new ApprovedAdministrativeBoundaries)->snapshots();
|
||||
$this->assertCount(408, array_unique(array_column($items, 'territory_id')));
|
||||
$this->assertSame(['2019-06-07'], array_values(array_unique(array_column($items, 'source_version'))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { portfolioPreparationHref } from '../../resources/js/lib/search-territory.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
|
||||
test('anchor preparation keeps exact identity and explicit search geography', () => {
|
||||
const query = new URLSearchParams({sector:'Agro-indústria e agricultura',province_id:'province-1',district_id:'district-1'});
|
||||
const href = portfolioPreparationHref('anchor-1','/carteira/anchor-1?catalogue_query='+encodeURIComponent(query.toString()));
|
||||
const params = new URL(href,'https://portal.invalid').searchParams;
|
||||
assert.equal(params.get('source'),'portfolio:anchor-1');
|
||||
assert.equal(params.get('province_id'),'province-1');
|
||||
assert.equal(params.get('district_id'),'district-1');
|
||||
assert.equal(params.has('opportunity'),false);
|
||||
assert.equal(params.has('sector_id'),false);
|
||||
});
|
||||
|
||||
test('report identifies the saved documentary anchor without asserting an available offer', () => {
|
||||
const context = {version:1,portfolio_origin:{key:'portfolio:anchor-1',title:'Âncora documental',version:2,href:'/carteira/anchor-1'}};
|
||||
const report = createProjectDossierReport({context_applicability_snapshot:JSON.stringify(context)},{selectedSections:new Set(['sources'])});
|
||||
const row = report.sections.find(section=>section.id==='sources').rows.find(row=>row.field==='Projecto ou carteira de origem');
|
||||
assert.equal(row.value,'Âncora documental');
|
||||
assert.match(row.origin,/portfolio:anchor-1; versão 2/);
|
||||
assert.match(row.classification,/localização e oferta não presumidas/);
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { inheritCompatibleFields } from '../../resources/js/lib/context-inheritance.ts';
|
||||
import { buildProjectDossierRows } from '../../resources/js/lib/project-dossier.ts';
|
||||
|
||||
test('changing only the treated opportunity refreshes inherited geography and preserves deliberate data',()=>{
|
||||
const scope='dossier:QA:land';
|
||||
const first={project_reference:'Investimento conjunto',purpose:'Segunda oportunidade',parcels:[{province_id:'gaza'}]};
|
||||
const initial=inheritCompatibleFields(scope,{},first,null);
|
||||
const values={...initial.patch,context_reuse:initial.metadata,purpose:'Edição deliberada',parcels:[{province_id:'gaza',area:'23',place_description:'Local declarado'}]};
|
||||
const next=inheritCompatibleFields(scope,values,{...first,purpose:'Novo resumo da segunda',parcels:[{province_id:'manica'}]},initial.metadata);
|
||||
assert.equal(next.patch.parcels[0].province_id,'manica');
|
||||
assert.equal(next.patch.parcels[0].district_id,'');
|
||||
assert.equal(next.patch.parcels[0].area,'23');
|
||||
assert.equal(next.patch.parcels[0].place_description,'Local declarado');
|
||||
assert.equal('purpose' in next.patch,false);
|
||||
assert.ok(next.conflicts.includes('purpose'));
|
||||
// The land form merges this geographic proposal into the existing parcel;
|
||||
// area and the declared place are not part of the geographic replacement.
|
||||
const merged={...values.parcels[0],...next.patch.parcels[0]};
|
||||
assert.equal(merged.area,'23');assert.equal(merged.place_description,'Local declarado');
|
||||
});
|
||||
|
||||
test('a deliberate site in a second-opportunity request remains a conflict instead of being replaced',()=>{
|
||||
const scope='dossier:QA:desk';
|
||||
const source={territory_id:'gaza',description:'Resumo específico'};
|
||||
const initial=inheritCompatibleFields(scope,{},source,null);
|
||||
const next=inheritCompatibleFields(scope,{...initial.patch,territory_id:'local-deliberado'},{...source,territory_id:'manica'},initial.metadata);
|
||||
assert.equal('territory_id' in next.patch,false);
|
||||
assert.ok(next.conflicts.includes('territory_id'));
|
||||
});
|
||||
|
||||
test('report keeps each park attached to its own opportunity after only the second changes',()=>{
|
||||
const choices=[{opportunity:{key:'opportunity:1',title:'Primeira'},territory:{title:'Sofala'},park:{title:'Parque Sofala'}},{opportunity:{key:'opportunity:2',title:'Segunda'},territory:{title:'Manica'},park:{title:'Parque Manica'}}];
|
||||
const rows=buildProjectDossierRows({context_applicability_snapshot:JSON.stringify({version:1,opportunity_choices:choices})});
|
||||
const parks=rows.filter(r=>r[1]==='Zona/parque da oportunidade');
|
||||
assert.deepEqual(parks.map(r=>[r[2],r[3]]),[['Parque Sofala','Primeira; opportunity:1'],['Parque Manica','Segunda; opportunity:2']]);
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user