Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
- improve behat steps configuration
- add description to migration
  • Loading branch information
Zales0123 committed Sep 1, 2021
1 parent 769ba79 commit 1bc17ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Seeing applied catalog promotions on variants list
And this product has "Python T-Shirt" variant priced at "$40.00"
And there is a catalog promotion with "winter_sale" code and "Winter sale" name
And it will be applied on "PHP T-Shirt" variant
And it will reduce price by 50%
And it will reduce price by "50%"

@api
Scenario: Seeing applied catalog promotion on variant
Expand Down
31 changes: 13 additions & 18 deletions src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,30 @@ public function theProductOriginalPriceShouldBe(int $originalPrice): void
* @Then /^I should see ("[^"]+" variant) is discounted from ("[^"]+") to ("[^"]+") with "([^"]+)" promotion$/
*/
public function iShouldSeeVariantIsDiscountedFromToWithPromotion(
ProductVariantInterface $targetVariant,
ProductVariantInterface $variant,
int $originalPrice,
int $price,
string $promotionName
): void {
$response = $this->responseChecker->getResponseContent($this->client->getLastResponse());

foreach ($response['hydra:member'] as $variant) {
if ($variant['code'] !== $targetVariant->getCode()) {
continue;
}
$response = $this->client->getLastResponse();
$content = $this->responseChecker->getCollectionItemsWithValue($response, 'code', $variant->getCode())[0];

Assert::same($variant['price'], $price);
Assert::same($variant['originalPrice'], $originalPrice);
Assert::inArray(['name' => $promotionName], $variant['appliedPromotions']);
}
Assert::same($content['price'], $price);
Assert::same($content['originalPrice'], $originalPrice);
Assert::inArray(['name' => $promotionName], $content['appliedPromotions']);
}

/**
* @Then I should see :firstVariant variant and :secondVariant variant are not discounted
* @Then /^I should see ("[^"]+" variant) and ("[^"]+" variant) are not discounted$/
*/
public function iShouldSeeVariantsAreNotDiscounted(string ...$variantsNames): void
public function iShouldSeeVariantsAreNotDiscounted(ProductVariantInterface ...$variants): void
{
$response = $this->responseChecker->getResponseContent($this->client->getLastResponse());
$response = $this->client->getLastResponse();

foreach ($response['hydra:member'] as $variant) {
if (in_array($variant['translations']['en_US']['name'], $variantsNames)) {
Assert::keyNotExists($variant, 'appliedPromotions');
}
foreach ($variants as $variant) {
$items = $this->responseChecker->getCollectionItemsWithValue($response, 'code', $variant->getCode());
$item = array_pop($items);
Assert::keyNotExists($item, 'appliedPromotions');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Version20210830193340 extends AbstractMigration
{
public function getDescription(): string
{
return '';
return 'Add information about applied catalog promotions on channel pricing';
}

public function up(Schema $schema): void
Expand Down

0 comments on commit 1bc17ab

Please sign in to comment.