diff --git a/app/Enums/ValidationError.php b/app/Enums/ValidationError.php index 8b5ac909e..efc6ceeb8 100644 --- a/app/Enums/ValidationError.php +++ b/app/Enums/ValidationError.php @@ -60,4 +60,6 @@ final class ValidationError extends Enum public const MEDIASLUG = 'VALIDATION_MEDIA_SLUG'; public const PHONE = 'VALIDATION_PHONE'; public const AUTHPROVIDERACTIVE = 'VALIDATION_AUTH_PROVIDER_ACTIVE'; + public const UNLIMITEDSHIPPINGTIME = 'VALIDATION_UNLIMITED_SHIPPING_TIME'; + public const UNLIMITEDSHIPPINGDATE = 'VALIDATION_UNLIMITED_SHIPPING_DATE'; } diff --git a/tests/Feature/ItemTest.php b/tests/Feature/ItemTest.php index c4de859e0..04b4145a5 100644 --- a/tests/Feature/ItemTest.php +++ b/tests/Feature/ItemTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use App\Enums\ErrorCode; +use App\Enums\ValidationError; use App\Events\ItemCreated; use App\Events\ItemDeleted; use App\Events\ItemUpdated; @@ -726,6 +727,70 @@ public function testUpdateWithPartialDataSku($user): void Event::assertDispatched(ItemUpdated::class); } + /** + * @dataProvider authProvider + */ + public function testUpdateWithInvalidUnlimitedDate($user): void + { + $this->{$user}->givePermissionTo('items.edit'); + + $this->item->update([ + 'shipping_date' => now(), + ]); + + Deposit::factory()->create([ + 'quantity' => 20, + 'from_unlimited' => false, + 'shipping_date' => now(), + 'item_id' => $this->item->getKey(), + ]); + + $item = [ + 'unlimited_stock_shipping_date' => now()->subDay(), + ]; + + $this->actingAs($this->{$user})->patchJson( + '/items/id:' . $this->item->getKey(), + $item, + ) + ->assertUnprocessable() + ->assertJsonFragment([ + 'key' => ValidationError::UNLIMITEDSHIPPINGDATE, + ]); + } + + /** + * @dataProvider authProvider + */ + public function testUpdateWithInvalidUnlimitedTime($user): void + { + $this->{$user}->givePermissionTo('items.edit'); + + $this->item->update([ + 'shipping_time' => 4, + ]); + + Deposit::factory()->create([ + 'quantity' => 20, + 'from_unlimited' => false, + 'shipping_time' => 4, + 'item_id' => $this->item->getKey(), + ]); + + $item = [ + 'unlimited_stock_shipping_time' => 2, + ]; + + $this->actingAs($this->{$user})->patchJson( + '/items/id:' . $this->item->getKey(), + $item, + ) + ->assertUnprocessable() + ->assertJsonFragment([ + 'key' => ValidationError::UNLIMITEDSHIPPINGTIME, + ]); + } + /** * @dataProvider authProvider */