Files
Investidor-V2/tests/Feature/IvaProductionCalendarDraftTest.php

35 lines
2.3 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 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));
}
}