admin = new User(); $this->admin->name = 'Admin User'; $this->admin->email = 'admin@example.com'; $this->admin->password = bcrypt('password'); $this->admin->type = RoleTypes::ADMIN; $this->admin->status = 1; $this->admin->save(); // Create a test segment $this->segment = new Segment(); $this->segment->name = 'Test Segment'; $this->segment->company_module_id = 1; $this->segment->save(); } /** * Test updating an existing segment price constant. */ public function test_it_can_update_segment_price_constant() { // Arrange $reference = 'test_price_ref'; $value = 100.50; $constant = new SegmentConstant(); $constant->segment_id = $this->segment->id; $constant->reference = $reference; $constant->value = [50.00]; $constant->save(); $payload = [ 'reference' => $reference, 'value' => $value ]; // Act $response = $this->actingAs($this->admin, 'api') ->putJson("/v1/api/segment/price/update/{$this->segment->id}", $payload); // Assert $response->assertStatus(200); $response->assertJsonStructure([ 'data' => [ 'id', 'reference', 'value' ], 'notification' => [ 'title', 'message' ] ]); $this->assertDatabaseHas('segment_constants', [ 'segment_id' => $this->segment->id, 'reference' => $reference, 'value' => json_encode([$value]) ]); } /** * Test creating a constant if it doesn't exist and then updating it. */ public function test_it_creates_constant_if_not_exists_then_updates_it() { // Arrange $reference = 'new_price_ref'; $value = 75.25; $payload = [ 'reference' => $reference, 'value' => $value ]; // Act $response = $this->actingAs($this->admin, 'api') ->putJson("/v1/api/segment/price/update/{$this->segment->id}", $payload); // Assert $response->assertStatus(200); $this->assertDatabaseHas('segment_constants', [ 'segment_id' => $this->segment->id, 'reference' => $reference, 'value' => json_encode([$value]) ]); } }