Skip to content

Commit

Permalink
Add api test for coupon_unique_code_validation.feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojdylak committed Nov 30, 2023
1 parent 854393e commit 6d33557
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Coupon unique code validation
And the store has promotion "Christmas sale" with coupon "SANTA2016"
And I am logged in as an administrator

@ui
@api @ui
Scenario: Trying to add coupon with taken code
When I want to create a new coupon for this promotion
And I specify its code as "SANTA2016"
Expand Down
6 changes: 3 additions & 3 deletions features/promotion/managing_coupons/editing_coupon.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Feature: Editing promotion coupon
Then I should be notified that it has been successfully edited
And this coupon should not be reusable from cancelled orders

@ui @no-api
Scenario: Seeing a disabled code field when editing a coupon
@ui @api
Scenario: Being unable to change code of promotion coupon
When I want to modify the "SANTA2016" coupon for this promotion
Then the code field should be disabled
Then I should not be able to edit its code
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ public function couponShouldStillExistInTheRegistry(PromotionCouponInterface $co
));
}

/**
* @Then /^there should still be only one coupon with code "([^"]+)" related to (this promotion)$/
*/
public function thereShouldStillBeOnlyOneCouponWithCodeRelatedTo(string $code, PromotionInterface $promotion): void
{
Assert::count(
$this->responseChecker->getCollectionItemsWithValue($this->client->index(Resources::PROMOTION_COUPONS), 'code', $code),
1
);
}

/**
* @Then I should be notified that it is in use and cannot be deleted
*/
Expand Down Expand Up @@ -423,6 +434,32 @@ public function iShouldBeNotifiedThatOnlyCouponBasedPromotionsCanHaveCoupons():
);
}

/**
* @Then I should be notified that coupon with this code already exists
*/
public function iShouldBeNotifiedThatCouponWithThisCodeAlreadyExists(): void
{
$response = $this->client->getLastResponse();
Assert::false(
$this->responseChecker->isCreationSuccessful($response),
'Coupon has been created successfully, but it should not',
);
Assert::same(
$this->responseChecker->getError($response),
'code: This coupon already exists.',
);
}

/**
* @Then I should not be able to edit its code
*/
public function iShouldNotBeAbleToEditItsCode(): void
{
$this->client->updateRequestData(['code' => 'NEW_CODE']);

Assert::false($this->responseChecker->hasValue($this->client->update(), 'code', 'NEW_CODE'));
}

private function sortBy(string $order, string $field): void
{
$this->client->sort([$field => str_starts_with($order, 'de') ? 'desc' : 'asc']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,10 @@ public function thisCouponShouldBeReusableFromCancelledOrders(PromotionCouponInt
}

/**
* @Then I should not be able to edit its code
* @Then the code field should be disabled
*/
public function theCodeFieldShouldBeDisabled()
public function iShouldNotBeAbleToEditItsCode(): void
{
Assert::true($this->updatePage->isCodeDisabled());
}
Expand Down

0 comments on commit 6d33557

Please sign in to comment.