assertSame('proactive_investment_20261027_test', $target->name); $this->assertSame(55441, (int) $target->port); $snapshot = static fn (string $table): array => collect(DB::select('select id::text as id,md5(row_to_json(t)::text) as hash from public."'.$table.'" t order by id'))->pluck('hash', 'id')->all(); $protected = []; foreach (['opportunities', 'documents', 'opportunity_documents', 'simulation_form_drafts', 'users', 'organizations', 'audit_events'] as $table) { $protected[$table] = $snapshot($table); } config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]); $this->actingAs(User::findOrFail(1021)); $fixture = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-economic-preserved.json')), true, flags: JSON_THROW_ON_ERROR); $this->assertTrue($fixture['synthetic']); $this->assertFalse($fixture['actualTaxEvidence']); $id = null; $etag = null; foreach ($fixture['cases'] as $name => $draft) { $personal = ['person_type' => $draft['person_type']]; unset($draft['person_type']); $payload = ['personal_snapshot' => $personal, 'economic_snapshot' => $draft]; if ($id === null) { $id = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id'); } else { $this->putJson('/api/v1/simulation-drafts/'.$id, $payload, ['If-Match' => $etag])->assertOk(); } $response = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk(); $etag = $response->headers->get('ETag'); $back = $response->json('data.economic_snapshot'); $this->assertSame($draft['modelo_a_snapshot'], $back['modelo_a_snapshot']); $this->assertSame($draft['business_plan_snapshot'], $back['business_plan_snapshot']); $original = json_decode($draft['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR); $recovered = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR); foreach (['irpcNormal', 'irpcWithholdings', 'books', 'currencyEvents', 'ispcQuarters'] as $map) { $this->assertSame($original[$map], $recovered[$map]); } $book = $recovered['irpcAnnual'][$draft['context_opportunity']]; $model = $book['result']['model']; $this->assertSame($original['irpcAnnual'][$draft['context_opportunity']], $book); $this->assertCount(1, $book['history']); $this->assertSame('IRPC-economic-credit/1', $model['economicCredit']['version']); $this->assertFalse($model['economicCredit']['carryCreated']); $this->assertFalse($model['economicCredit']['officialBalancesConsumed']); $this->assertFalse($model['submitted']); if (in_array($name, ['duplicate', 'missing-gross-up', 'article40', 'partial-parcel'], true)) { $this->assertSame('indeterminate', $model['status']); $this->assertNull($model['arithmeticBalance']); $this->assertNull($model['economicCredit']['deducted']); $this->assertNull($model['internationalCredit']['deducted']); $this->assertNull($model['pecDeduction']['deducted']); } else { $expected = ['payable' => ['688', '1'], 'combined' => ['538', '1'], 'quota' => ['695', '1'], 'prior-use' => ['691', '1'], 'shared-paper' => ['688', '1'], 'fractional' => ['349997', '500'], 'recoverable' => ['-500', '1']][$name]; $this->assertEmpty($model['pending']); $this->assertSame(['numerator' => $expected[0], 'denominator' => $expected[1]], $model['arithmeticBalance']); } if (getenv('INVESTMOZ_ECONOMIC_QA_OUTPUT') === '1') { file_put_contents(base_path('outputs/irpc-l8-economic-20261028/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)); } } $preserved = []; foreach ($protected as $table => $before) { $this->assertSame($before, array_intersect_key($snapshot($table), $before), 'Existing records changed: '.$table); $preserved[$table] = ['existing_rows' => count($before), 'unchanged' => true]; } if (getenv('INVESTMOZ_ECONOMIC_QA_OUTPUT') === '1') { file_put_contents(base_path('outputs/irpc-l8-economic-20261028/existing-records-preservation.json'), json_encode(['database' => $target->name, 'tables' => $preserved, 'transaction_rollback' => true], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)); } } }