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

45 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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));
}
}