Skip to content

Commit

Permalink
Add PromotionCouponCannotBeRemoved to code mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojdylak committed Nov 30, 2023
1 parent 440a75a commit e6f4b2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ api_platform:
Sylius\Bundle\ApiBundle\Exception\ProductAttributeCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\ProductCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\ProductVariantCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\PromotionCouponCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\ProvinceCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\ShippingMethodCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\TaxonCannotBeRemoved: 422
Expand Down
23 changes: 23 additions & 0 deletions tests/Api/Admin/PromotionCouponsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,27 @@ public function it_removes_a_promotion_coupon(): void

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_NO_CONTENT);
}

/** @test */
public function it_does_not_delete_the_promotion_coupon_in_use(): void
{
$fixtures = $this->loadFixturesFromFiles([
'authentication/api_administrator.yaml',
'channel.yaml',
'promotion/promotion.yaml',
'promotion/promotion_order.yaml',
]);
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);

/** @var PromotionCouponInterface $coupon */
$coupon = $fixtures['promotion_1_off_coupon_1'];

$this->client->request(
method: 'DELETE',
uri: '/api/v2/admin/promotion-coupons/' . $coupon->getCode(),
server: $header,
);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
}
}
1 change: 1 addition & 0 deletions tests/Api/DataFixtures/ORM/promotion/promotion_order.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Sylius\Component\Core\Model\Order:
state: "new"
tokenValue: "token"
promotions: ['@promotion_50_off']
promotionCoupon: '@promotion_1_off_coupon_1'

0 comments on commit e6f4b2b

Please sign in to comment.