diff --git a/app/Http/Controllers/BucketController.php b/app/Http/Controllers/BucketController.php index e52b7b1..bcd13c2 100644 --- a/app/Http/Controllers/BucketController.php +++ b/app/Http/Controllers/BucketController.php @@ -75,10 +75,10 @@ public function update(Request $request, Bucket $bucket): JsonResponse 'name' => 'sometimes|required|string|max:255', 'type' => 'sometimes|required|in:'.implode(',', BucketTypeEnum::values()), 'allocation_type' => 'sometimes|required|in:'.implode(',', BucketAllocationTypeEnum::values()), - 'allocation_value' => 'nullable|numeric', + 'allocation_value' => 'sometimes|nullable|numeric', 'buffer_multiplier' => 'sometimes|numeric|min:0', 'starting_amount' => 'sometimes|integer|min:0', - 'priority' => 'nullable|integer|min:1', + 'priority' => 'sometimes|nullable|integer|min:1', ]); $type = isset($validated['type']) ? BucketTypeEnum::from($validated['type']) : $bucket->type; diff --git a/tests/Feature/BucketUpdateTest.php b/tests/Feature/BucketUpdateTest.php index 22da158..6b3f2d5 100644 --- a/tests/Feature/BucketUpdateTest.php +++ b/tests/Feature/BucketUpdateTest.php @@ -166,4 +166,24 @@ public function test_can_update_name_only(): void 'name' => 'New Name', ]); } + + public function test_partial_update_does_not_null_other_fields(): void + { + $bucket = Bucket::factory()->need()->fixedLimit(1000)->create([ + 'scenario_id' => $this->scenario->id, + 'starting_amount' => 500, + 'buffer_multiplier' => 1.5, + 'priority' => 1, + ]); + + $response = $this->patchJson("/buckets/{$bucket->uuid}", [ + 'starting_amount' => 750, + ]); + + $response->assertOk(); + $bucket->refresh(); + $this->assertEquals(750, $bucket->starting_amount); + $this->assertEquals(1000, (float) $bucket->allocation_value); + $this->assertEquals(1.5, (float) $bucket->buffer_multiplier); + } }