Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for not sending emails when refund validation fails #222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion features/having_credit_memo_sent_to_customer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ Feature: Having credit memo sent to customer
And I am logged in as an administrator
And the order "#00000022" is already paid

@application
@application @email
Scenario: Having credit memo file sent to a customer
When I want to refund some units of order "#00000022"
And I decide to refund 1st "Mr. Meeseeks T-Shirt" product with "Space money" payment
Then I should be notified that selected order units have been successfully refunded
And email to "[email protected]" with credit memo should be sent

@ui @email
Scenario: Not sending email with credit memo if the refund validation fails
When I want to refund some units of order "#00000022"
And I refund zero items
Then I should be notified that at least one unit should be selected to refund
And email to "[email protected]" with credit memo should not be sent
2 changes: 1 addition & 1 deletion tests/Behat/Context/Application/RefundingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function shouldBeAbleToRefundUnitWithProduct(
*/
public function emailToWithCreditMemoShouldBeSent(string $email): void
{
$this->emailChecker->hasMessageTo('Some of the units from your order have been refunded.', $email);
Assert::true($this->emailChecker->hasMessageTo('Some of the units from your order have been refunded.', $email));
}

/**
Expand Down
20 changes: 19 additions & 1 deletion tests/Behat/Context/Ui/RefundingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Core\Test\Services\EmailCheckerInterface;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use Tests\Sylius\RefundPlugin\Behat\Page\Admin\OrderRefundsPageInterface;
use Webmozart\Assert\Assert;

Expand All @@ -19,12 +21,17 @@ final class RefundingContext implements Context
/** @var NotificationCheckerInterface */
private $notificationChecker;

/** @var EmailCheckerInterface */
private $emailChecker;

public function __construct(
OrderRefundsPageInterface $orderRefundsPage,
NotificationCheckerInterface $notificationChecker
NotificationCheckerInterface $notificationChecker,
EmailCheckerInterface $emailChecker
) {
$this->orderRefundsPage = $orderRefundsPage;
$this->notificationChecker = $notificationChecker;
$this->emailChecker = $emailChecker;
}

/**
Expand Down Expand Up @@ -339,6 +346,17 @@ public function theSelectedRefundPaymentMethodShouldBe(string $paymentMethod): v
Assert::true($this->orderRefundsPage->isPaymentMethodSelected($paymentMethod));
}

/**
* @Then email to :email with credit memo should not be sent
*/
public function emailToWithCreditMemoShouldNotBeSent(string $email): void
{
try {
Assert::false($this->emailChecker->hasMessageTo('Some of the units from your order have been refunded.', $email));
} catch (DirectoryNotFoundException $exception) {
}
}

private function provideLongComment(): string
{
return 'Tu ne quaesieris scire nefas, quem mihi quem tibi finem di dederint, Leuconoe, nec Babylonios temptaris numeros. Ut melius quidquid erit pati. Seu plures hiemes sue tribuit Iuppiter ultimam. Qae nunc oppositis debilitat pumicibus mare Tyrrenum: sapias vina liques et spatio brevi. Spem longam resecens. Dum loquimur fugerit invida Aetas: CARPE DIEM, quam minimum credula postero.';
Expand Down
1 change: 1 addition & 0 deletions tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<service id="Tests\Sylius\RefundPlugin\Behat\Context\Ui\RefundingContext">
<argument type="service" id="Tests\Sylius\RefundPlugin\Behat\Page\Admin\OrderRefundsPage" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="sylius.behat.email_checker" />
</service>

<service id="Tests\Sylius\RefundPlugin\Behat\Context\Ui\CreditMemoContext">
Expand Down