Skip to content

Commit

Permalink
Fix tests (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Jun 9, 2023
1 parent 0f4809b commit eeb8f1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Resources/config/services/command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.enqueuer.ecommerce_order"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.logger"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.enqueuer.contact"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.enqueuer.ecommerce_customer"/>
<argument type="service" id="messenger.default_bus"/>
<argument>%webgriffe_sylius_active_campaign.cart_becomes_abandoned_period%</argument>
<argument>%webgriffe_sylius_active_campaign.command.enqueue_ecommerce_abandoned_cart.name%</argument>
<tag name="console.command"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit eeb8f1e

Please sign in to comment.