66 lines
4.9 KiB
PHP
66 lines
4.9 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 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', 4000000)], 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));
|
|
}
|
|
}
|