createSegment('update_constant_logic_existing'); $this->createConstant($segment, 'update_constant_logic_existing_reference', [ 1 => ['rate' => 10], ]); $payload = [ 'reference' => 'update_constant_logic_existing_reference', 'id' => 2, 'rate' => ['rate' => 15], ]; // A C T $response = $this->actingAsAdmin() ->putJson("/api/v1/segment/{$segment->id}/constant/update", $payload); // A S S E R T $response->assertStatus(200); $response->assertJsonPath('payload.data.reference', 'update_constant_logic_existing_reference'); $constant = $segment->constants()->where('reference', 'update_constant_logic_existing_reference')->first(); $this->assertEquals(['rate' => 15], $constant->value[2] ?? $constant->value['2'] ?? null); } public function test_it_can_create_a_missing_constant_via_controller_logic() { // A R R A N G E $segment = $this->createSegment('update_constant_logic_missing'); $payload = [ 'reference' => 'update_constant_logic_missing_reference', 'id' => 8, 'value' => ['rate' => 44], ]; // A C T $response = $this->actingAsAdmin() ->putJson("/api/v1/segment/{$segment->id}/constant/update", $payload); // A S S E R T $response->assertStatus(200); $response->assertJsonPath('payload.data.reference', 'update_constant_logic_missing_reference'); $constant = $segment->constants()->where('reference', 'update_constant_logic_missing_reference')->first(); $this->assertEquals(['rate' => 44], $constant->value[8] ?? $constant->value['8'] ?? null); $this->assertDatabaseHas('segment_constants', [ 'segment_id' => $segment->id, 'reference' => 'update_constant_logic_missing_reference', ]); } }