73 lines
2.6 KiB
PHP
73 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\Crm;
|
|
|
|
use App\Cqs\Actions\Crm\UnsubscribeFromNewsletter;
|
|
use App\Cqs\Actions\Crm\UnsubscribeFromNewsletterInput;
|
|
use App\Cqs\Actions\Crm\UnsubscribeFromNewsletterOutput;
|
|
use App\Services\CrmService;
|
|
use Shared\Helpers\UuidHelper;
|
|
use Shared\ValueObjects\CrmHashcode;
|
|
|
|
describe('UnsubscribeFromNewsletter action', function (): void {
|
|
it('returns SUCCESS when CRM service unsubscribes the customer', function (): void {
|
|
// GIVEN
|
|
$hashcode = new CrmHashcode(UuidHelper::v4());
|
|
|
|
/** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */
|
|
$crmService = \Mockery::mock(CrmService::class);
|
|
$crmService->shouldReceive('unsubscribeCustomer')
|
|
->once()
|
|
->with(\Mockery::on(static fn (CrmHashcode $h): bool => $h->value === $hashcode->value))
|
|
->andReturnTrue();
|
|
|
|
$action = new UnsubscribeFromNewsletter($crmService);
|
|
|
|
// WHEN
|
|
$output = $action(new UnsubscribeFromNewsletterInput($hashcode));
|
|
|
|
// THEN
|
|
expect($output)->toBe(UnsubscribeFromNewsletterOutput::SUCCESS);
|
|
});
|
|
|
|
it('returns FAILURE when CRM service returns false', function (): void {
|
|
// GIVEN
|
|
$hashcode = new CrmHashcode(UuidHelper::v4());
|
|
|
|
/** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */
|
|
$crmService = \Mockery::mock(CrmService::class);
|
|
$crmService->shouldReceive('unsubscribeCustomer')
|
|
->once()
|
|
->with(\Mockery::on(static fn (CrmHashcode $h): bool => $h->value === $hashcode->value))
|
|
->andReturnFalse();
|
|
|
|
$action = new UnsubscribeFromNewsletter($crmService);
|
|
|
|
// WHEN
|
|
$output = $action(new UnsubscribeFromNewsletterInput($hashcode));
|
|
|
|
// THEN
|
|
expect($output)->toBe(UnsubscribeFromNewsletterOutput::FAILURE);
|
|
});
|
|
|
|
it('returns FAILURE without throwing when CRM service throws an exception', function (): void {
|
|
// GIVEN
|
|
$hashcode = new CrmHashcode(UuidHelper::v4());
|
|
|
|
/** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */
|
|
$crmService = \Mockery::mock(CrmService::class);
|
|
$crmService->shouldReceive('unsubscribeCustomer')
|
|
->once()
|
|
->andThrow(new \RuntimeException('CRM timeout'));
|
|
|
|
$action = new UnsubscribeFromNewsletter($crmService);
|
|
|
|
// WHEN
|
|
$output = $action(new UnsubscribeFromNewsletterInput($hashcode));
|
|
|
|
// THEN
|
|
expect($output)->toBe(UnsubscribeFromNewsletterOutput::FAILURE);
|
|
});
|
|
});
|