assertSame('simulator_fiscal_delta_20261021_test', $identity->name); $this->assertSame(55441, (int) $identity->port); $this->actingAs(User::factory()->create(['email_verified_at' => now()])); $path = getenv('IVA_ACQUISITION_UI_INPUT') ?: base_path('tests/frontend/fixtures/modelo-a-acquisitions.json'); $draft = json_decode(file_get_contents($path), true, flags: JSON_THROW_ON_ERROR); $draft['purpose'] = 'simulate_only'; $created = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated(); $recovered = $this->getJson('/api/v1/simulation-drafts/'.$created->json('data.id'))->assertOk()->json('data.economic_snapshot'); $this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']); $this->assertSame($draft['context_opportunity'], $recovered['context_opportunity']); if (getenv('IVA_ACQUISITION_UI_RECOVERED_OUT')) { file_put_contents(getenv('IVA_ACQUISITION_UI_RECOVERED_OUT'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)); } } public function test_calculated_acquisitions_round_trip_in_private_draft_and_other_owner_cannot_read(): void { $identity = DB::selectOne('select current_database() as name,inet_server_port() as port'); $this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name); $this->assertSame(55441, (int) $identity->port); config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]); $fingerprint = DB::selectOne("select md5(string_agg(row_to_json(r)::text,E'\\n' order by id)) as hash from simulation_tax_rule_versions r")->hash; $actor = User::factory()->create(['email_verified_at' => now()]); $this->actingAs($actor); $draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/modelo-a-acquisitions.json')), true, flags: JSON_THROW_ON_ERROR); $draft['purpose'] = 'simulate_only'; $created = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated(); $id = $created->json('data.id'); $this->assertNotEmpty($id); $saved = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk(); $economic = $saved->json('data.economic_snapshot'); $this->assertSame($draft['modelo_a_snapshot'], $economic['modelo_a_snapshot']); $store = json_decode($economic['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR); $first = $store['books']['opportunity:309']; $this->assertSame('144.0048', $first['result']['periods'][0]['fields'][17]); $store['books']['opportunity:310'] = $first; $store['books']['opportunity:310']['rows'][0]['net'] = '200'; $store['books']['opportunity:310']['rows'][0]['vat'] = '32'; $economic['context_opportunity'] = 'opportunity:310'; $economic['modelo_a_snapshot'] = json_encode($store, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE); $this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => [], 'economic_snapshot' => $economic], ['If-Match' => $saved->headers->get('ETag')])->assertOk(); $recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot'); $this->assertSame($economic['modelo_a_snapshot'], $recovered['modelo_a_snapshot']); $this->assertSame($first, json_decode($recovered['modelo_a_snapshot'], true)['books']['opportunity:309']); if (getenv('IVA_ACQUISITION_RECOVERED_OUT')) { // The original calculated opportunity, recovered through the real private API, is the report source. $economic['context_opportunity'] = 'opportunity:309'; file_put_contents(getenv('IVA_ACQUISITION_RECOVERED_OUT'), json_encode($economic, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)); } $this->actingAs(User::factory()->create(['email_verified_at' => now()])); $this->getJson('/api/v1/simulation-drafts/'.$id)->assertNotFound(); $this->assertSame($fingerprint, DB::selectOne("select md5(string_agg(row_to_json(r)::text,E'\\n' order by id)) as hash from simulation_tax_rule_versions r")->hash); } }