From eeb8f1e3fa6764a83a39868c371fe37466fbd6c1 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Fri, 9 Jun 2023 16:30:05 +0200 Subject: [PATCH] Fix tests (#67) --- src/Resources/config/services/command.xml | 3 ++ ...queueEcommerceAbandonedCartCommandTest.php | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Resources/config/services/command.xml b/src/Resources/config/services/command.xml index cfb9f58..c769e79 100644 --- a/src/Resources/config/services/command.xml +++ b/src/Resources/config/services/command.xml @@ -47,6 +47,9 @@ + + + %webgriffe_sylius_active_campaign.cart_becomes_abandoned_period% %webgriffe_sylius_active_campaign.command.enqueue_ecommerce_abandoned_cart.name% diff --git a/tests/Integration/Command/EnqueueEcommerceAbandonedCartCommandTest.php b/tests/Integration/Command/EnqueueEcommerceAbandonedCartCommandTest.php index b6e66fb..4a87ccf 100644 --- a/tests/Integration/Command/EnqueueEcommerceAbandonedCartCommandTest.php +++ b/tests/Integration/Command/EnqueueEcommerceAbandonedCartCommandTest.php @@ -8,6 +8,10 @@ use Sylius\Component\Core\Repository\CustomerRepositoryInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Symfony\Component\Messenger\Envelope; +use Webgriffe\SyliusActiveCampaignPlugin\Message\Contact\ContactListsSubscriber; +use Webgriffe\SyliusActiveCampaignPlugin\Message\Contact\ContactTagsAdder; +use Webgriffe\SyliusActiveCampaignPlugin\Message\Contact\ContactUpdate; +use Webgriffe\SyliusActiveCampaignPlugin\Message\EcommerceCustomer\EcommerceCustomerCreate; use Webgriffe\SyliusActiveCampaignPlugin\Message\EcommerceOrder\EcommerceOrderCreate; final class EnqueueEcommerceAbandonedCartCommandTest extends AbstractCommandTest @@ -32,7 +36,7 @@ protected function setUp(): void ], [], [], PurgeMode::createDeleteMode()); } - public function test_that_it_enqueues_ecommerce_abandoned_carts(): void + public function test_that_it_enqueues_ecommerce_abandoned_carts_and_relative_contact(): void { $commandTester = $this->executeCommand([]); self::assertEquals(0, $commandTester->getStatusCode()); @@ -42,10 +46,30 @@ public function test_that_it_enqueues_ecommerce_abandoned_carts(): void $transport = self::getContainer()->get('messenger.transport.main'); /** @var Envelope[] $messages */ $messages = $transport->get(); - $this->assertCount(1, $messages); + $this->assertCount(5, $messages); + $message = $messages[0]; + $this->assertInstanceOf(ContactUpdate::class, $message->getMessage()); + $this->assertEquals($bobCart->getCustomer()->getId(), $message->getMessage()->getCustomerId()); + $this->assertEquals($bobCart->getCustomer()->getActiveCampaignId(), $message->getMessage()->getActiveCampaignId()); + + $message = $messages[1]; + $this->assertInstanceOf(EcommerceCustomerCreate::class, $message->getMessage()); + $this->assertEquals($bobCart->getCustomer()->getId(), $message->getMessage()->getCustomerId()); + $this->assertEquals($bobCart->getChannel()->getId(), $message->getMessage()->getChannelId()); + + $message = $messages[2]; + $this->assertInstanceOf(ContactTagsAdder::class, $message->getMessage()); + $this->assertEquals($bobCart->getCustomer()->getId(), $message->getMessage()->getCustomerId()); + + $message = $messages[3]; + $this->assertInstanceOf(ContactListsSubscriber::class, $message->getMessage()); + $this->assertEquals($bobCart->getCustomer()->getId(), $message->getMessage()->getCustomerId()); + + $message = $messages[4]; $this->assertInstanceOf(EcommerceOrderCreate::class, $message->getMessage()); $this->assertEquals($bobCart->getId(), $message->getMessage()->getOrderId()); + $this->assertTrue($message->getMessage()->isInRealTime()); } protected function getCommandDefinition(): string