2026-09-29 16:59:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Contracts\ActionInput;
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Ranges\DeleteRange;
|
|
|
|
|
use App\Cqs\Actions\Ranges\DeleteRangeInput;
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Models\Range;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
describe('DeleteRange action', function () {
|
|
|
|
|
test('it deletes an existing range from database', function () {
|
2026-10-02 10:53:21 +02:00
|
|
|
/** @var \Tests\TestCase $this */
|
2026-09-29 16:59:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$range = new Range();
|
|
|
|
|
$range->name = 'Gamme Temporaire';
|
|
|
|
|
$range->picture_alt = 'Alt';
|
|
|
|
|
$range->picture_title = 'Title';
|
|
|
|
|
$range->status = true;
|
|
|
|
|
$range->save();
|
|
|
|
|
|
|
|
|
|
$action = new DeleteRange();
|
|
|
|
|
$input = new DeleteRangeInput(range: $range);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $action($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
$this->assertDatabaseMissing('ranges', [
|
|
|
|
|
'id' => $range->id,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when an invalid input is passed', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$action = new DeleteRange();
|
|
|
|
|
$invalidInput = new class () implements ActionInput
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => $action($invalidInput))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class);
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
});
|