refactor(inventory): update stock validation rules and enforce stock_difference requirement

This commit is contained in:
2026-09-25 15:28:49 -03:00
parent 717f02ce16
commit a05d15d17f
13 changed files with 141 additions and 31 deletions

View File

@@ -124,6 +124,8 @@ class FoodControllerTest extends TestCase
$updated = $this->variantPayload($secondDate->id, 'Cena', 'Vianda', 80, 8500);
$updated['id'] = $variantId;
unset($updated['stock']);
$updated['stock_difference'] = -20;
$updated['description'] = 'Cena para llevar';
$this->postJson('/api/v1/adminapp/tenant/foods', [
@@ -240,7 +242,7 @@ class FoodControllerTest extends TestCase
Inventory::query()->whereKey($replacementInventoryId)->delete();
$updated = $this->patchJson('/api/v1/adminapp/tenant/foods/history-stock', [
'variants' => [['id' => $historicalVariantId, 'stock' => 45]],
'variants' => [['id' => $historicalVariantId, 'stock_difference' => -55]],
])
->assertOk()
->assertJsonPath('data.history.0.variants.0.id', $historicalVariantId)
@@ -258,7 +260,7 @@ class FoodControllerTest extends TestCase
]);
$this->patchJson('/api/v1/adminapp/tenant/foods/history-stock', [
'variants' => [['id' => $activeVariantId, 'stock' => 20]],
'variants' => [['id' => $activeVariantId, 'stock_difference' => -60]],
])
->assertUnprocessable()
->assertJsonValidationErrors(['variants.0.id']);