Skip to content

Commit

Permalink
add contract test and missing behat
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Nov 1, 2021
1 parent 9b36b51 commit be22726
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ Feature: Applying catalog promotions in proper time range
When I view product "T-Shirt"
Then I should see the product price "$20.00"
And I should see this product has no catalog promotion applied

@api @ui
Scenario: Not applying catalog promotion if its end date has already passed after end date modification
Given it is "2021-12-25" now
And the catalog promotion "Winter sale" operates between "2021-12-20" and "2021-12-30"
And I am logged in as an administrator
When I want to modify a catalog promotion "Winter sale"
And I change its end date to "2021-12-23"
And I save my changes
And I am logged out
And I view product "T-Shirt"
Then I should see the product price "$20.00"
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Setup/AdminSecurityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function iAmLoggedInAsAdministrator($email)

/**
* @Given I have been logged out from administration
* @When I am logged out
*/
public function iHaveBeenLoggedOutFromAdministration()
{
Expand Down
27 changes: 27 additions & 0 deletions tests/Api/Admin/CatalogPromotionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ public function it_does_not_create_a_catalog_promotion_with_taken_code(): void
);
}

/** @test */
public function it_does_not_create_a_catalog_promotion_with_end_date_earlier_than_start_date(): void
{
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'catalog_promotion.yaml']);
$header = $this->getLoggedHeader();

$this->client->request(
'POST',
'/api/v2/admin/catalog-promotions',
[],
[],
$header,
json_encode([
'name' => 'calatog Promotion',
'code' => 'catalog_promotion',
'startDate' => '2021-11-04 10:42:00',
'endDate' => '2021-10-04 10:42:00'
], JSON_THROW_ON_ERROR)
);

$this->assertResponse(
$this->client->getResponse(),
'admin/catalog_promotion/post_catalog_promotion_with_invalid_dates_response',
Response::HTTP_UNPROCESSABLE_ENTITY
);
}

/** @test */
public function it_does_not_create_a_catalog_promotion_with_invalid_scopes(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"@context": "\/api\/v2\/contexts\/ConstraintViolationList",
"@type": "ConstraintViolationList",
"hydra:title": "An error occurred",
"hydra:description": "code: The catalog promotion with given code already exists.",
"hydra:description": "endDate: End date can not be before start date.",
"violations": [
{
"propertyPath": "code",
"message": "The catalog promotion with given code already exists.",
"propertyPath": "endDate",
"message": "End date can not be before start date.",
"code": @string@
}
]
Expand Down

0 comments on commit be22726

Please sign in to comment.