Skip to content

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

Remove deprecated checkoutLineDelete mutation (#19580)

Lukasz Ostrowskid0b4811ae4d8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35f72904f9..0f1655bd6a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Removed the deprecated `checkoutId` input argument from the `checkoutShippingAddressUpdate` and `checkoutBillingAddressUpdate` mutations. Use the `id` argument instead.
- `confirmAccount()` mutation no longer allows to confirm an account that was already confirmed. - #19459 by @NyanKiyosi
- Removed the deprecated `shopDomainUpdate` mutation. Use the `PUBLIC_URL` environment variable to configure the shop domain instead.
+- Removed the deprecated `checkoutLineDelete` mutation. Use `checkoutLinesDelete` instead — it takes a `linesIds` list and only accepts the checkout `id` (the `token` and `checkoutId` arguments are gone).
- Removed the deprecated `shopFetchTaxRates` mutation, along with the `ShopFetchTaxRates` type. It was a no-op; configure taxes with the tax mutations (e.g. `taxConfigurationUpdate`) instead.
- Removed the deprecated `orderSettingsUpdate` mutation. Use the `channelUpdate` mutation with the `orderSettings` input to update order settings per channel instead.
- Removed the deprecated `orderSettings` query field. Use the `channel` query and read its `orderSettings` field instead.
diff --git a/saleor/graphql/checkout/mutations/__init__.py b/saleor/graphql/checkout/mutations/__init__.py
index c4615bbd78..fa3538c65e 100644
--- a/saleor/graphql/checkout/mutations/__init__.py
+++ b/saleor/graphql/checkout/mutations/__init__.py
@@ -10,7 +10,6 @@ from .checkout_delete import CheckoutDelete
from .checkout_delivery_method_update import CheckoutDeliveryMethodUpdate
from .checkout_email_update import CheckoutEmailUpdate
from .checkout_language_code_update import CheckoutLanguageCodeUpdate
-from .checkout_line_delete import CheckoutLineDelete
from .checkout_lines_add import CheckoutLinesAdd
from .checkout_lines_delete import CheckoutLinesDelete
from .checkout_lines_update import CheckoutLinesUpdate
@@ -32,7 +31,6 @@ __all__ = [
"CheckoutDeliveryMethodUpdate",
"CheckoutEmailUpdate",
"CheckoutLanguageCodeUpdate",
- "CheckoutLineDelete",
"CheckoutLinesAdd",
"CheckoutLinesDelete",
"CheckoutLinesUpdate",
diff --git a/saleor/graphql/checkout/mutations/checkout_line_delete.py b/saleor/graphql/checkout/mutations/checkout_line_delete.py
deleted file mode 100644
index 10ce684dde..0000000000
--- a/saleor/graphql/checkout/mutations/checkout_line_delete.py
+++ /dev/null
@@ -1,107 +0,0 @@
-import graphene
-
-from ....checkout.actions import call_checkout_info_event
-from ....checkout.error_codes import CheckoutErrorCode
-from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
-from ....checkout.utils import invalidate_checkout
-from ....webhook.event_types import WebhookEventAsyncType
-from ...core import ResolveInfo
-from ...core.context import SyncWebhookControlContext
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
-from ...core.doc_category import DOC_CATEGORY_CHECKOUT
-from ...core.mutations import BaseMutation
-from ...core.scalars import UUID
-from ...core.types import CheckoutError
-from ...core.utils import WebhookEventInfo, raise_validation_error
-from ...plugins.dataloaders import get_plugin_manager_promise
-from ..types import Checkout, CheckoutLine
-from .utils import (
- get_checkout,
- mark_checkout_deliveries_as_stale_if_needed,
-)
-
-
-class CheckoutLineDelete(BaseMutation):
- checkout = graphene.Field(Checkout, description="An updated checkout.")
-
- class Arguments:
- id = graphene.ID(
- description="The checkout's ID.",
- required=False,
- )
- token = UUID(
- description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
- required=False,
- )
- checkout_id = graphene.ID(
- required=False,
- description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
- ),
- )
- line_id = graphene.ID(description="ID of the checkout line to delete.")
-
- class Meta:
- description = "Deletes a CheckoutLine."
- doc_category = DOC_CATEGORY_CHECKOUT
- error_type_class = CheckoutError
- error_type_field = "checkout_errors"
- webhook_events_info = [
- WebhookEventInfo(
- type=WebhookEventAsyncType.CHECKOUT_UPDATED,
- description="A checkout was updated.",
- )
- ]
-
- @classmethod
- def perform_mutation( # type: ignore[override]
- cls,
- _root,
- info: ResolveInfo,
- /,
- *,
- checkout_id=None,
- id=None,
- line_id,
- token=None,
- ):
- checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)
-
- line = cls.get_node_or_error(
- info, line_id, only_type=CheckoutLine, field="line_id"
- )
-
- if line.is_gift:
- raise_validation_error(
- message="Checkout line marked as gift can't be deleted.",
- field="line_id",
- code=CheckoutErrorCode.NON_REMOVABLE_GIFT_LINE.value,
- )
-
- if line and line in checkout.lines.all():
- line.delete()
-
- manager = get_plugin_manager_promise(info.context).get()
- lines, _ = fetch_checkout_lines(checkout)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
-
- shipping_update_fields = mark_checkout_deliveries_as_stale_if_needed(
- checkout_info.checkout, lines
- )
- invalidate_update_fields = invalidate_checkout(
- checkout_info, lines, manager, save=False
- )
- checkout.search_index_dirty = True
- checkout.save(
- update_fields=shipping_update_fields
- + invalidate_update_fields
- + ["search_index_dirty"]
- )
- call_checkout_info_event(
- manager,
- event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
- checkout_info=checkout_info,
- lines=lines,
- )
-
- return CheckoutLineDelete(checkout=SyncWebhookControlContext(node=checkout))
diff --git a/saleor/graphql/checkout/schema.py b/saleor/graphql/checkout/schema.py
index 52827999a9..17819b9d8f 100644
--- a/saleor/graphql/checkout/schema.py
+++ b/saleor/graphql/checkout/schema.py
@@ -30,7 +30,6 @@ from .mutations import (
CheckoutDeliveryMethodUpdate,
CheckoutEmailUpdate,
CheckoutLanguageCodeUpdate,
- CheckoutLineDelete,
CheckoutLinesAdd,
CheckoutLinesDelete,
CheckoutLinesUpdate,
@@ -135,9 +134,6 @@ class CheckoutMutations(graphene.ObjectType):
checkout_customer_note_update = CheckoutCustomerNoteUpdate.Field()
checkout_delete = CheckoutDelete.Field()
checkout_email_update = CheckoutEmailUpdate.Field()
- checkout_line_delete = CheckoutLineDelete.Field(
- deprecation_reason="Use `checkoutLinesDelete` instead."
- )
checkout_lines_delete = CheckoutLinesDelete.Field()
checkout_lines_add = CheckoutLinesAdd.Field()
checkout_lines_update = CheckoutLinesUpdate.Field()
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
deleted file mode 100644
index c698da5078..0000000000
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
+++ /dev/null
@@ -1,167 +0,0 @@
-from unittest import mock
-
-import graphene
-
-from .....checkout.error_codes import CheckoutErrorCode
-from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
-from .....checkout.utils import calculate_checkout_quantity
-from .....plugins.manager import get_plugins_manager
-from ....tests.utils import get_graphql_content
-from ...mutations.utils import mark_checkout_deliveries_as_stale_if_needed
-
-MUTATION_CHECKOUT_LINES_DELETE = """
- mutation checkoutLineDelete($checkoutId: ID, $token: UUID, $lineId: ID!) {
- checkoutLineDelete(checkoutId: $checkoutId, token: $token lineId: $lineId) {
- checkout {
- token
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- message
- code
- }
- }
- }
-"""
-
-
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
-def test_checkout_line_delete_by_id(
- mocked_update_shipping_method, user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- assert line.quantity == 3
-
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"checkoutId": checkout_id, "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 0
- assert calculate_checkout_quantity(lines) == 0
- manager = get_plugins_manager(allow_replica=False)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info.checkout, lines)
-
-
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
-def test_checkout_line_delete_by_token(
- mocked_update_shipping_method, user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- assert line.quantity == 3
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"token": checkout.token, "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 0
- assert calculate_checkout_quantity(lines) == 0
- manager = get_plugins_manager(allow_replica=False)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info.checkout, lines)
-
-
-def test_checkout_line_delete_neither_token_and_id_given(
- user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- line = checkout.lines.first()
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert len(data["errors"]) == 1
- assert not data["checkout"]
- assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
-
-
-def test_checkout_line_delete_both_token_and_id_given(
- user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- line = checkout.lines.first()
-
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"checkoutId": checkout_id, "token": checkout.token, "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert len(data["errors"]) == 1
- assert not data["checkout"]
- assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
-
-
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
-def test_checkout_line_delete_by_old_line_id(
- mocked_update_shipping_method, user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- line.old_id = 1
- line.save(update_fields=["old_id"])
- assert line.quantity == 3
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"token": checkout.token, "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 0
- assert calculate_checkout_quantity(lines) == 0
- manager = get_plugins_manager(allow_replica=False)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info.checkout, lines)
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py
deleted file mode 100644
index d49dd37c8d..0000000000
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py
+++ /dev/null
@@ -1,467 +0,0 @@
-from unittest import mock
-from unittest.mock import ANY, patch
-
-import graphene
-import pytest
-from django.test import override_settings
-from django.utils import timezone
-from freezegun import freeze_time
-
-from .....checkout import base_calculations
-from .....checkout.actions import call_checkout_info_event
-from .....checkout.error_codes import CheckoutErrorCode
-from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
-from .....checkout.tests.utils import add_variant_to_checkout
-from .....checkout.utils import (
- add_voucher_to_checkout,
- calculate_checkout_quantity,
- invalidate_checkout,
-)
-from .....core.models import EventDelivery
-from .....plugins.manager import get_plugins_manager
-from .....product.models import ProductChannelListing, ProductVariantChannelListing
-from .....warehouse.models import Reservation
-from .....webhook.event_types import WebhookEventAsyncType
-from ....core.utils import to_global_id_or_none
-from ....tests.utils import get_graphql_content
-from ...mutations.utils import mark_checkout_deliveries_as_stale_if_needed
-
-MUTATION_CHECKOUT_LINE_DELETE = """
- mutation checkoutLineDelete($id: ID, $lineId: ID!) {
- checkoutLineDelete(id: $id, lineId: $lineId) {
- checkout {
- token
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- message
- code
- }
- }
- }
-"""
-
-
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
- "saleor.graphql.checkout.mutations.checkout_line_delete.invalidate_checkout",
- wraps=invalidate_checkout,
-)
-def test_checkout_line_delete(
- mocked_invalidate_checkout,
- mocked_mark_shipping_method_as_stale,
- user_api_client,
- checkout_line_with_reservation_in_many_stocks,
-):
- # given
- assert Reservation.objects.count() == 2
- checkout = checkout_line_with_reservation_in_many_stocks.checkout
- previous_last_change = checkout.last_change
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- assert line.quantity == 3
- checkout.search_index_dirty = False
- checkout.save(update_fields=["search_index_dirty"])
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
-
- # then
- content = get_graphql_content(response)
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 0
- assert calculate_checkout_quantity(lines) == 0
- assert Reservation.objects.count() == 0
- manager = get_plugins_manager(allow_replica=False)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_mark_shipping_method_as_stale.assert_called_once_with(
- checkout_info.checkout, lines
- )
- assert checkout.last_change != previous_last_change
- assert mocked_invalidate_checkout.call_count == 1
- assert checkout.search_index_dirty is True
-
-
- ("channel_listing_model", "listing_filter_field"),
- [
- (ProductVariantChannelListing, "variant_id"),
- (ProductChannelListing, "product__variants__id"),
- ],
-)
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
- "saleor.graphql.checkout.mutations.checkout_line_delete.invalidate_checkout",
- wraps=invalidate_checkout,
-)
-def test_checkout_line_delete_when_variant_without_channel_listing(
- mocked_invalidate_checkout,
- mocked_mark_shipping_method_as_stale,
- channel_listing_model,
- listing_filter_field,
- user_api_client,
- checkout_line_with_reservation_in_many_stocks,
-):
- # given
- assert Reservation.objects.count() == 2
- checkout = checkout_line_with_reservation_in_many_stocks.checkout
- previous_last_change = checkout.last_change
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
-
- channel_listing_model.objects.filter(
- channel_id=checkout.channel_id, **{listing_filter_field: line.variant_id}
- ).delete()
-
- assert line.quantity == 3
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
-
- # then
- content = get_graphql_content(response)
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 0
- assert calculate_checkout_quantity(lines) == 0
- assert Reservation.objects.count() == 0
- manager = get_plugins_manager(allow_replica=False)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_mark_shipping_method_as_stale.assert_called_once_with(
- checkout_info.checkout, lines
- )
- assert checkout.last_change != previous_last_change
- assert mocked_invalidate_checkout.call_count == 1
-
-
- ("channel_listing_model", "listing_filter_field"),
- [
- (ProductVariantChannelListing, "variant_id"),
- (ProductChannelListing, "product__variants__id"),
- ],
-)
- "saleor.graphql.checkout.mutations.checkout_line_delete."
- "mark_checkout_deliveries_as_stale_if_needed",
- wraps=mark_checkout_deliveries_as_stale_if_needed,
-)
- "saleor.graphql.checkout.mutations.checkout_line_delete.invalidate_checkout",
- wraps=invalidate_checkout,
-)
-def test_checkout_line_delete_when_checkout_has_line_without_channel_listing(
- mocked_invalidate_checkout,
- mocked_mark_shipping_method_as_stale,
- channel_listing_model,
- listing_filter_field,
- user_api_client,
- checkout_with_items,
-):
- # given
- checkout = checkout_with_items
- previous_last_change = checkout.last_change
-
- lines, _ = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 4
- assert checkout.lines.count() == 4
- line_without_listing = checkout.lines.last()
-
- channel_listing_model.objects.filter(
- channel_id=checkout.channel_id,
- **{listing_filter_field: line_without_listing.variant_id},
- ).delete()
-
- line = checkout.lines.first()
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
-
- # then
- content = get_graphql_content(response)
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
-
- assert checkout.lines.count() == 3
- checkout.refresh_from_db()
- manager = get_plugins_manager(allow_replica=False)
- lines, _ = fetch_checkout_lines(checkout)
- checkout_info = fetch_checkout_info(checkout, lines, manager)
- mocked_mark_shipping_method_as_stale.assert_called_once_with(
- checkout_info.checkout, lines
- )
- assert checkout.last_change != previous_last_change
- assert mocked_invalidate_checkout.call_count == 1
-
-
-def test_checkout_lines_delete_with_not_applicable_voucher(
- user_api_client, checkout_with_item, voucher, channel_USD
-):
- manager = get_plugins_manager(allow_replica=False)
- lines, _ = fetch_checkout_lines(checkout_with_item)
- checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)
- subtotal = base_calculations.base_checkout_subtotal(
- lines,
- checkout_info.channel,
- checkout_info.checkout.currency,
- )
- voucher.channel_listings.filter(channel=channel_USD).update(
- min_spent_amount=subtotal.amount
- )
- checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)
-
- add_voucher_to_checkout(
- manager, checkout_info, lines, voucher, voucher.codes.first()
- )
- assert checkout_with_item.voucher_code == voucher.code
-
- line = checkout_with_item.lines.first()
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- variables = {"id": to_global_id_or_none(checkout_with_item), "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout_with_item.refresh_from_db()
- assert checkout_with_item.lines.count() == 0
- assert checkout_with_item.voucher_code is None
-
-
-@freeze_time("2024-05-31 12:00:01")
-def test_checkout_line_marks_shipping_as_stale_if_removed_product_with_shipping(
- user_api_client,
- checkout_with_item,
- product_without_shipping,
- address,
- checkout_delivery,
-):
- checkout = checkout_with_item
- variant = product_without_shipping.variants.get()
- checkout.shipping_address = address
- checkout.assigned_delivery = checkout_delivery(checkout)
- checkout.save()
-
- checkout_info = fetch_checkout_info(
- checkout, [], get_plugins_manager(allow_replica=False)
- )
- add_variant_to_checkout(checkout_info, variant, 1)
- line = checkout.lines.first()
-
- line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
-
- variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLineDelete"]
- assert not data["errors"]
- checkout.refresh_from_db()
- assert checkout.lines.count() == 1
- assert checkout.assigned_delivery
- assert checkout.delivery_methods_stale_at == timezone.now()
-
-
-def test_with_active_problems_flow(
- api_client, checkout_with_problems, product_with_single_variant
-):
- # given
- channel = checkout_with_problems.channel
- channel.use_legacy_error_flow_for_checkout = False
- channel.save(update_fields=["use_legacy_error_flow_for_checkout"])
-
- variant = product_with_single_variant.variants.first()
-
- checkout_info = fetch_checkout_info(
- checkout_with_problems, [], get_plugins_manager(allow_replica=False)
- )
- add_variant_to_checkout(checkout_info, variant, 1)
-
- line = checkout_info.checkout.lines.last()
-
- variables = {
- "id": to_global_id_or_none(checkout_with_problems),
- "lineId": to_global_id_or_none(line),
- }
-
- # when
- response = api_client.post_graphql(
- MUTATION_CHECKOUT_LINE_DELETE,
- variables,
- )
- content = get_graphql_content(response)
-
- # then
- assert not content["data"]["checkoutLineDelete"]["errors"]
-
-
-def test_checkout_line_delete_non_removable_gift(user_api_client, checkout_line):
- # given
- checkout = checkout_line.checkout
- line = checkout_line
- line.is_gift = True
- line.save(update_fields=["is_gift"])
- line_id = to_global_id_or_none(line)
- variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
- content = get_graphql_content(response)
-
- # then
- data = content["data"]["checkoutLineDelete"]
- assert not data["checkout"]
- errors = data["errors"]
- assert len(errors) == 1
- assert errors[0]["field"] == "lineId"
- assert errors[0]["code"] == CheckoutErrorCode.NON_REMOVABLE_GIFT_LINE.name
-
-
-MUTATION_CHECKOUT_LINE_DELETE_WITH_ONLY_ID = """
- mutation checkoutLineDelete($id: ID, $lineId: ID!) {
- checkoutLineDelete(id: $id, lineId: $lineId) {
- checkout {
- token
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- message
- code
- }
- }
- }
-"""
-
-
-@patch(
- "saleor.graphql.checkout.mutations.checkout_line_delete.call_checkout_info_event",
- wraps=call_checkout_info_event,
-)
-@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
-@patch(
- "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
-)
-@patch(
- "saleor.webhook.transport.asynchronous.transport.generate_deferred_payloads.apply_async"
-)
-@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-@override_settings(WEBHOOK_DEFERRED_PAYLOAD_QUEUE_NAME="deferred_queue")
-def test_checkout_line_delete_triggers_webhooks(
- mocked_generate_deferred_payloads,
- mocked_send_webhook_request_async,
- mocked_send_webhook_request_sync,
- wrapped_call_checkout_info_event,
- setup_checkout_webhooks,
- settings,
- api_client,
- checkout_with_items,
- product_with_single_variant,
- address,
-):
- # given
- (
- tax_webhook,
- shipping_webhook,
- shipping_filter_webhook,
- checkout_updated_webhook,
- ) = setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_UPDATED)
-
- variant = product_with_single_variant.variants.first()
-
- checkout_info = fetch_checkout_info(
- checkout_with_items, [], get_plugins_manager(allow_replica=False)
- )
- add_variant_to_checkout(checkout_info, variant, 1)
-
- line = checkout_info.checkout.lines.last()
-
- # Ensure shipping is set so shipping webhooks are emitted
- checkout_with_items.shipping_address = address
- checkout_with_items.billing_address = address
-
- checkout_with_items.save()
-
- variables = {
- "id": to_global_id_or_none(checkout_with_items),
- "lineId": to_global_id_or_none(line),
- }
-
- # when
- response = api_client.post_graphql(
- MUTATION_CHECKOUT_LINE_DELETE_WITH_ONLY_ID,
- variables,
- )
-
- # then
- content = get_graphql_content(response)
- assert not content["data"]["checkoutLineDelete"]["errors"]
-
- assert wrapped_call_checkout_info_event.called
-
- # confirm that event delivery was generated for each async webhook.
- checkout_update_delivery = EventDelivery.objects.get(
- webhook_id=checkout_updated_webhook.id
- )
-
- mocked_generate_deferred_payloads.assert_called_once_with(
- kwargs={
- "event_delivery_ids": [checkout_update_delivery.id],
- "deferred_payload_data": {
- "model_name": "checkout.checkout",
- "object_id": checkout_with_items.pk,
- "requestor_model_name": None,
- "requestor_object_id": None,
- "request_time": None,
- "subscribable_object_data": None,
- },
- "send_webhook_queue": settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
- "telemetry_context": ANY,
- },
- queue=settings.WEBHOOK_DEFERRED_PAYLOAD_QUEUE_NAME,
- MessageGroupId="example.com",
- )
-
- # Deferred payload covers the sync and async actions
- assert not mocked_send_webhook_request_async.called
- assert not mocked_send_webhook_request_sync.called
diff --git a/saleor/graphql/checkout/tests/test_checkout_price_expiration.py b/saleor/graphql/checkout/tests/test_checkout_price_expiration.py
index dd845cf9e5..0d0181ec85 100644
--- a/saleor/graphql/checkout/tests/test_checkout_price_expiration.py
+++ b/saleor/graphql/checkout/tests/test_checkout_price_expiration.py
@@ -147,48 +147,6 @@ def test_checkout_lines_delete_invalidate_prices(
)
-DELETE_CHECKOUT_LINE = """
-mutation deleteCheckoutLine($token: UUID!, $lineId: ID!){
- checkoutLineDelete(token: $token, lineId: $lineId) {
- errors {
- field
- message
- }
- }
-}
-"""
-
-
-@patch("saleor.graphql.checkout.mutations.checkout_line_delete.invalidate_checkout")
-def test_checkout_line_delete_invalidate_prices(
- mocked_invalidate_checkout,
- api_client,
- checkout_with_items,
-):
- # given
- manager = get_plugins_manager(allow_replica=False)
- mocked_invalidate_checkout.return_value = []
- query = DELETE_CHECKOUT_LINE
- variables = {
- "token": checkout_with_items.token,
- "lineId": graphene.Node.to_global_id(
- "CheckoutLine", checkout_with_items.lines.first().pk
- ),
- }
-
- # when
- response = get_graphql_content(api_client.post_graphql(query, variables))
-
- # then
- assert not response["data"]["checkoutLineDelete"]["errors"]
- checkout_with_items.refresh_from_db()
- lines, _ = fetch_checkout_lines(checkout_with_items)
- checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)
- mocked_invalidate_checkout.assert_called_once_with(
- checkout_info, lines, mock.ANY, save=False
- )
-
-
UPDATE_CHECKOUT_SHIPPING_ADDRESS = """
mutation UpdateCheckoutShippingAddress($token: UUID!, $address: AddressInput!) {
checkoutShippingAddressUpdate(token: $token, shippingAddress: $address) {
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 3a52cb7edb..6469d8be0b 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -20930,26 +20930,6 @@ type Mutation {
token: UUID @deprecated(reason: "Use `id` instead.")
): CheckoutEmailUpdate @doc(category: "Checkout") @webhookEventsInfo(asyncEvents: [CHECKOUT_UPDATED], syncEvents: [])
- """
- Deletes a CheckoutLine.
-
- Triggers the following webhook events:
- - CHECKOUT_UPDATED (async): A checkout was updated.
- """
- checkoutLineDelete(
- """The ID of the checkout."""
- checkoutId: ID @deprecated(reason: "Use `id` instead.")
-
- """The checkout's ID."""
- id: ID
-
- """ID of the checkout line to delete."""
- lineId: ID
-
- """Checkout token."""
- token: UUID @deprecated(reason: "Use `id` instead.")
- ): CheckoutLineDelete @doc(category: "Checkout") @webhookEventsInfo(asyncEvents: [CHECKOUT_UPDATED], syncEvents: []) @deprecated(reason: "Use `checkoutLinesDelete` instead.")
-
"""
Deletes checkout lines.
@@ -30983,19 +30963,6 @@ type CheckoutEmailUpdate @doc(category: "Checkout") @webhookEventsInfo(asyncEven
errors: [CheckoutError!]!
}
-"""
-Deletes a CheckoutLine.
-
-Triggers the following webhook events:
-- CHECKOUT_UPDATED (async): A checkout was updated.
-"""
-type CheckoutLineDelete @doc(category: "Checkout") @webhookEventsInfo(asyncEvents: [CHECKOUT_UPDATED], syncEvents: []) {
- """An updated checkout."""
- checkout: Checkout
- checkoutErrors: [CheckoutError!]! @deprecated(reason: "Use `errors` field instead.")
- errors: [CheckoutError!]!
-}
-
"""
Deletes checkout lines.