2026-10-01 11:25:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:21:17 +01:00
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Customers;
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Queries\Customers\GetCustomerByEmailQuery;
|
|
|
|
|
use App\Cqs\Queries\Customers\GetCustomerByEmailQueryInput;
|
2026-10-01 11:25:05 +02:00
|
|
|
use App\Models\Customer;
|
|
|
|
|
use Domain\Models\ValueObjects\Email;
|
|
|
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
2026-11-17 12:15:39 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-10-01 11:25:05 +02:00
|
|
|
use Shared\ValueObjects\CrmHashcode;
|
|
|
|
|
|
|
|
|
|
describe('GetCustomerByEmailQuery', function (): void {
|
|
|
|
|
it('returns ShopperId when customer with email exists', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$email = new Email('john.doe@example.com');
|
|
|
|
|
$customer = new Customer(['email' => $email]);
|
2026-11-17 12:15:39 +01:00
|
|
|
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
|
2026-10-01 11:25:05 +02:00
|
|
|
$customer->save();
|
|
|
|
|
|
2026-11-14 16:06:49 +01:00
|
|
|
$query = new GetCustomerByEmailQuery();
|
2026-10-01 11:25:05 +02:00
|
|
|
$input = new GetCustomerByEmailQueryInput($email);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $query($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeInstanceOf(ShopperId::class)
|
2026-11-16 16:13:14 +01:00
|
|
|
->and($result?->value->toString())->toBe($customer->id);
|
2026-10-01 11:25:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns null when customer with email does not exist', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$email = new Email('nonexistent@example.com');
|
2026-11-14 16:06:49 +01:00
|
|
|
$query = new GetCustomerByEmailQuery();
|
2026-10-01 11:25:05 +02:00
|
|
|
$input = new GetCustomerByEmailQueryInput($email);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $query($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
});
|