Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add giftCardBulkDelete mutation
IKarbowiak79640ca809a4
diff --git a/saleor/graphql/giftcard/bulk_mutations.py b/saleor/graphql/giftcard/bulk_mutations.pynew file mode 100644index 0000000000..de387c123a--- /dev/null+++ b/saleor/graphql/giftcard/bulk_mutations.py@@ -0,0 +1,19 @@+import graphene++from ...core.permissions import GiftcardPermissions+from ...giftcard import models+from ..core.mutations import ModelBulkDeleteMutation+from ..core.types.common import GiftCardError+++class GiftCardBulkDelete(ModelBulkDeleteMutation):+ class Arguments:+ ids = graphene.List(+ graphene.ID, required=True, description="List of gift card IDs to delete."+ )++ class Meta:+ description = "Delete gift cards."+ model = models.GiftCard+ permissions = (GiftcardPermissions.MANAGE_GIFT_CARD,)+ error_type_class = GiftCardErrordiff --git a/saleor/graphql/giftcard/schema.py b/saleor/graphql/giftcard/schema.pyindex 2839f9fc5e..bc32b5d1a9 100644--- a/saleor/graphql/giftcard/schema.py+++ b/saleor/graphql/giftcard/schema.py@@ -5,6 +5,7 @@ from ..core.descriptions import ADDED_IN_31from ..core.fields import FilterInputConnectionFieldfrom ..core.utils import from_global_id_or_errorfrom ..decorators import permission_required+from .bulk_mutations import GiftCardBulkDeletefrom .filters import GiftCardFilterInputfrom .mutations import (GiftCardActivate,@@ -49,3 +50,5 @@ class GiftCardMutations(graphene.ObjectType):gift_card_delete = GiftCardDelete.Field()gift_card_deactivate = GiftCardDeactivate.Field()gift_card_update = GiftCardUpdate.Field()++ gift_card_bulk_delete = GiftCardBulkDelete.Field()diff --git a/saleor/graphql/giftcard/tests/mutations/test_gift_card_bulk_delete.py b/saleor/graphql/giftcard/tests/mutations/test_gift_card_bulk_delete.pynew file mode 100644index 0000000000..e514c894d4--- /dev/null+++ b/saleor/graphql/giftcard/tests/mutations/test_gift_card_bulk_delete.py@@ -0,0 +1,88 @@+import graphene++from .....giftcard.models import GiftCard+from ....tests.utils import assert_no_permission, get_graphql_content++GIFT_CARD_BULK_DELETE_MUTATION = """+ mutation GiftCardBulkDelete($ids: [ID!]!) {+ giftCardBulkDelete(ids: $ids) {+ count+ errors {+ code+ field+ message+ }+ }+ }+"""+++def test_gift_card_bulk_delete_by_staff(+ staff_api_client,+ permission_manage_gift_card,+ gift_card,+ gift_card_expiry_period,+ gift_card_expiry_date,+):+ # given+ gift_card_pks = [gift_card.pk, gift_card_expiry_period.pk, gift_card_expiry_date.pk]+ ids = [graphene.Node.to_global_id("GiftCard", pk) for pk in gift_card_pks]+ variables = {"ids": ids}++ # when+ response = staff_api_client.post_graphql(+ GIFT_CARD_BULK_DELETE_MUTATION,+ variables,+ permissions=(permission_manage_gift_card,),+ )++ # then+ content = get_graphql_content(response)+ data = content["data"]["giftCardBulkDelete"]++ assert not data["errors"]+ assert data["count"] == len(ids)+ assert not GiftCard.objects.filter(id__in=gift_card_pks)+++def test_gift_card_bulk_delete_by_app(+ app_api_client,+ permission_manage_gift_card,+ gift_card,+ gift_card_expiry_period,+ gift_card_expiry_date,+):+ # given+ gift_card_pks = [gift_card.pk, gift_card_expiry_period.pk, gift_card_expiry_date.pk]+ ids = [graphene.Node.to_global_id("GiftCard", pk) for pk in gift_card_pks]+ variables = {"ids": ids}++ # when+ response = app_api_client.post_graphql(+ GIFT_CARD_BULK_DELETE_MUTATION,+ variables,+ permissions=(permission_manage_gift_card,),+ )++ # then+ content = get_graphql_content(response)+ data = content["data"]["giftCardBulkDelete"]++ assert not data["errors"]+ assert data["count"] == len(ids)+ assert not GiftCard.objects.filter(id__in=gift_card_pks)+++def test_gift_card_bulk_delete_by_customer(+ app_api_client, gift_card, gift_card_expiry_period, gift_card_expiry_date+):+ # given+ gift_card_pks = [gift_card.pk, gift_card_expiry_period.pk, gift_card_expiry_date.pk]+ ids = [graphene.Node.to_global_id("GiftCard", pk) for pk in gift_card_pks]+ variables = {"ids": ids}++ # when+ response = app_api_client.post_graphql(GIFT_CARD_BULK_DELETE_MUTATION, variables)++ # then+ assert_no_permission(response)diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 448e66fec7..c32ad9da75 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2259,6 +2259,11 @@ type GiftCardActivate {errors: [GiftCardError!]!}+type GiftCardBulkDelete {+ count: Int!+ errors: [GiftCardError!]!+}+type GiftCardCountableConnection {pageInfo: PageInfo!edges: [GiftCardCountableEdge!]!@@ -3793,6 +3798,7 @@ type Mutation {giftCardDelete(id: ID!): GiftCardDeletegiftCardDeactivate(id: ID!): GiftCardDeactivategiftCardUpdate(id: ID!, input: GiftCardUpdateInput!): GiftCardUpdate+ giftCardBulkDelete(ids: [ID]!): GiftCardBulkDeletepluginUpdate(channelId: ID, id: ID!, input: PluginUpdateInput!): PluginUpdatesaleCreate(input: SaleInput!): SaleCreatesaleDelete(id: ID!): SaleDelete