ldc-cocotte/tests/Integration/WithApp/App/Cqs/Actions/Customers/UpdateCustomerLastLoginTest.php

55 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Cqs\Actions\Customers;
use App\Contracts\ActionInput;
use App\Cqs\Actions\Customers\UpdateCustomerLastLogin;
use App\Cqs\Actions\Customers\UpdateCustomerLastLoginInput;
use App\Models\Customer;
use Domain\Models\ValueObjects\Email;
use Illuminate\Support\Facades\Date;
use Shared\Helpers\UuidHelper;
use Shared\ValueObjects\CrmHashcode;
describe('UpdateCustomerLastLogin action', function (): void {
it('updates last_login_at on the customer', function (): void {
// GIVEN
Date::setTestNow('2026-11-14 10:30:00');
$customer = new Customer();
$customer->email = new Email('customer@example.com');
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
$customer->last_login_at = null;
$customer->saveOrFail();
$action = new UpdateCustomerLastLogin();
$input = new UpdateCustomerLastLoginInput($customer);
// WHEN
$updated = $action($input);
// THEN
expect($updated->last_login_at?->format('Y-m-d H:i:s'))->toBe('2026-11-14 10:30:00')
->and(Customer::query()->find($customer->id)?->last_login_at?->format('Y-m-d H:i:s'))
->toBe('2026-11-14 10:30:00');
Date::setTestNow();
});
it('throws when an invalid input is passed', function (): void {
// GIVEN
$action = new UpdateCustomerLastLogin();
$invalidInput = new class () implements ActionInput
{
};
// WHEN
expect(
/** @phpstan-ignore argument.type */
fn () => $action($invalidInput)
)
// THEN
->toThrow(\InvalidArgumentException::class);
});
});