Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Split GiftCardInput to create and update input

fowczarek6d7e5de8eec0
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 94da5b2b78..2a0482b525 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -585,9 +585,7 @@ class CheckoutAddPromoCode(BaseMutation):
checkout = cls.get_node_or_error(
info, checkout_id, only_type=Checkout, field="checkout_id"
)
-
add_promo_code_to_checkout(checkout, promo_code)
-
return CheckoutAddPromoCode(checkout=checkout)
@@ -610,7 +608,5 @@ class CheckoutRemovePromoCode(BaseMutation):
checkout = cls.get_node_or_error(
info, checkout_id, only_type=Checkout, field="checkout_id"
)
-
remove_promo_code_from_checkout(checkout, promo_code)
-
return CheckoutUpdateVoucher(checkout=checkout)
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index b29660e715..b3f358a200 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -11,8 +11,7 @@ from ..core.scalars import Decimal
from .types import GiftCard
-class GiftCardInput(graphene.InputObjectType):
- code = graphene.String(required=False, decription="Code to use the gift card.")
+class GiftCardUpdateInput(graphene.InputObjectType):
start_date = graphene.types.datetime.Date(
description="Start date of the gift card in ISO 8601 format."
)
@@ -25,9 +24,13 @@ class GiftCardInput(graphene.InputObjectType):
)
+class GiftCardCreateInput(GiftCardUpdateInput):
+ code = graphene.String(required=False, decription="Code to use the gift card.")
+
+
class GiftCardCreate(ModelMutation):
class Arguments:
- input = GiftCardInput(
+ input = GiftCardCreateInput(
required=True, description="Fields required to create a gift card."
)
@@ -64,7 +67,7 @@ class GiftCardCreate(ModelMutation):
class GiftCardUpdate(GiftCardCreate):
class Arguments:
id = graphene.ID(required=True, description="ID of a gift card to update.")
- input = GiftCardInput(
+ input = GiftCardUpdateInput(
required=True, description="Fields required to update a gift card."
)
@@ -73,13 +76,6 @@ class GiftCardUpdate(GiftCardCreate):
model = models.GiftCard
permissions = ("giftcard.manage_gift_card",)
- @classmethod
- def clean_input(cls, info, instance, data):
- code = data.get("code", None)
- if code:
- raise ValidationError({"code": "Cannot update a gift card code."})
- return super().clean_input(info, instance, data)
-
class GiftCardDeactivate(BaseMutation):
gift_card = graphene.Field(GiftCard, description="A gift card to deactivate.")
diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.py
index 2903dfbe12..80e2b33792 100644
--- a/tests/api/test_gift_card.py
+++ b/tests/api/test_gift_card.py
@@ -377,44 +377,6 @@ def test_update_gift_card_without_premissions(staff_api_client, gift_card):
assert_no_permission(response)
-def test_update_gift_card_update_code_error(
- staff_api_client, gift_card, permission_manage_gift_card
-):
- query = """
- mutation giftCardUpdate($id: ID!, $code: String!) {
- giftCardUpdate(id: $id, input: { code: $code }) {
- errors {
- field
- message
- }
- giftCard {
- code
- currentBalance {
- amount
- }
- user {
- email
- }
- }
- }
- }
- """
- variables = {
- "id": graphene.Node.to_global_id("GiftCard", gift_card.id),
- "code": "new_code",
- }
- response = staff_api_client.post_graphql(
- query, variables, permissions=[permission_manage_gift_card]
- )
- content = get_graphql_content(response)
- assert content["data"]["giftCardUpdate"]["errors"]
- errors = content["data"]["giftCardUpdate"]["errors"]
- assert len(errors) == 1
- assert errors[0]["field"] == "code"
- assert errors[0]["message"] == "Cannot update a gift card code."
- assert not content["data"]["giftCardUpdate"]["giftCard"]
-
-
DEACTIVATE_GIFT_CARD_MUTATION = """
mutation giftCardDeactivate($id: ID!) {
giftCardDeactivate(id: $id) {