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

58 lines
4.1 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tests\TestCase;
final class 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));
}
}