13 - Fix allocation_value nulled on partial updates

This commit is contained in:
myrmidex 2026-03-21 10:52:27 +01:00
parent a045ee6c23
commit 4bf3aef610
2 changed files with 22 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}
}