2026-09-30 12:08:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:21:17 +01:00
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\PickupExceptions;
|
|
|
|
|
|
2026-09-30 12:08:22 +02:00
|
|
|
use App\Contracts\ActionInput;
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\PickupExceptions\UpdatePickupException;
|
|
|
|
|
use App\Cqs\Actions\PickupExceptions\UpdatePickupExceptionInput;
|
2026-09-30 12:08:22 +02:00
|
|
|
use App\Models\PickupException;
|
|
|
|
|
use Domain\Enums\RepeatFrequency;
|
|
|
|
|
|
|
|
|
|
describe('UpdatePickupException action', function () {
|
|
|
|
|
test('it updates and persists a pickup exception in database', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$pickupException = PickupException::factory()->create([
|
|
|
|
|
'date' => '2026-05-01',
|
|
|
|
|
'label' => 'Old Label',
|
|
|
|
|
'repeatable' => false,
|
|
|
|
|
'repeat_frequency' => RepeatFrequency::WEEKLY,
|
|
|
|
|
'auto_updated' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$action = new UpdatePickupException();
|
|
|
|
|
$input = new UpdatePickupExceptionInput(
|
|
|
|
|
pickupException: $pickupException,
|
|
|
|
|
date: '2026-05-08',
|
|
|
|
|
label: 'New Label',
|
|
|
|
|
repeatable: true,
|
|
|
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$updated = $action($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($updated->id)->toBe($pickupException->id)
|
|
|
|
|
->and($updated->date->format('Y-m-d'))->toBe('2026-05-08')
|
|
|
|
|
->and($updated->label)->toBe('New Label')
|
|
|
|
|
->and($updated->repeatable)->toBeTrue()
|
|
|
|
|
->and($updated->repeat_frequency)->toBe(RepeatFrequency::YEARLY)
|
|
|
|
|
->and($updated->auto_updated)->toBeFalse();
|
|
|
|
|
|
|
|
|
|
$fresh = PickupException::query()->find($pickupException->id);
|
|
|
|
|
expect($fresh)->not->toBeNull()
|
|
|
|
|
->and($fresh?->label)->toBe('New Label')
|
|
|
|
|
->and($fresh?->auto_updated)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when an invalid input is passed', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$action = new UpdatePickupException();
|
|
|
|
|
$invalidInput = new class () implements ActionInput
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-16 16:13:14 +01:00
|
|
|
/** @var \Closure(\App\Contracts\ActionInput): mixed $callable */
|
|
|
|
|
$callable = \Closure::fromCallable($action);
|
|
|
|
|
|
2026-09-30 12:08:22 +02:00
|
|
|
// WHEN & THEN
|
2026-11-16 16:13:14 +01:00
|
|
|
expect(fn () => $callable($invalidInput))->toThrow(\InvalidArgumentException::class);
|
2026-09-30 12:08:22 +02:00
|
|
|
});
|
|
|
|
|
});
|