[Unit] Add test cases for promotion coupon with non-existing promotion

This commit is contained in:
Rafikooo 2024-09-23 12:59:19 +02:00
parent 7d8d85a4ba
commit 5ba8d3159e
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
2 changed files with 98 additions and 1 deletions

View file

@ -49,7 +49,7 @@ final class PromotionCouponsTest extends JsonApiTestCase
}
/** @test */
public function it_gets_specific_promotion_coupons(): void
public function it_gets_promotion_coupons_for_specific_promotion(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel/channel.yaml', 'promotion/promotion.yaml']);
@ -61,6 +61,16 @@ final class PromotionCouponsTest extends JsonApiTestCase
$this->assertResponseSuccessful('admin/promotion_coupon/get_promotion_coupons_response');
}
/** @test */
public function it_gets_an_empty_array_result_when_the_promotion_has_not_exist(): void
{
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml']);
$this->requestGet('/api/v2/admin/promotions/NON_EXISTING_PROMOTION_CODE/coupons');
$this->assertResponseSuccessful('admin/promotion_coupon/get_empty_promotion_coupons_response');
}
/** @test */
public function it_creates_a_promotion_coupon(): void
{
@ -83,6 +93,25 @@ final class PromotionCouponsTest extends JsonApiTestCase
$this->assertResponseCreated('admin/promotion_coupon/post_promotion_coupon_response');
}
/** @test */
public function it_does_not_create_promotion_coupon_if_promotion_does_not_exist(): void
{
$this->loadFixturesFromFile('authentication/api_administrator.yaml');
$this->requestPost(
'/api/v2/admin/promotions/NON_EXISTING_PROMOTION_CODE/coupons',
[
'code' => 'XYZ3',
'usageLimit' => 100,
'perCustomerUsageLimit' => 3,
'reusableFromCancelledOrders' => false,
'expiresAt' => '23-12-2023',
],
);
$this->assertResponseNotFound('Parent resource not found.');
}
/** @test */
public function it_updates_a_promotion_coupon(): void
{

View file

@ -0,0 +1,68 @@
{
"@context": "\/api\/v2\/contexts\/PromotionCoupon",
"@id": "\/api\/v2\/admin\/promotions\/NON_EXISTING_PROMOTION_CODE\/coupons",
"@type": "hydra:Collection",
"hydra:totalItems": 0,
"hydra:member": [],
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "\/api\/v2\/admin\/promotions\/NON_EXISTING_PROMOTION_CODE\/coupons{?order[code],order[expiresAt],order[usageLimit],order[perCustomerUsageLimit],order[used],code,code[],promotion.code,promotion.code[]}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
"@type": "IriTemplateMapping",
"variable": "order[code]",
"property": "code",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[expiresAt]",
"property": "expiresAt",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[usageLimit]",
"property": "usageLimit",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[perCustomerUsageLimit]",
"property": "perCustomerUsageLimit",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[used]",
"property": "used",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "code",
"property": "code",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "code[]",
"property": "code",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "promotion.code",
"property": "promotion.code",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "promotion.code[]",
"property": "promotion.code",
"required": false
}
]
}
}