Skip to content

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

Unify checkout identifier in checkout mutations and queries (#7511)

Iga Karbowiak3b55d05ddd85
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 956b2e873a..c5b8399a4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -218,6 +218,7 @@ All notable, unreleased changes to this project will be documented in this file.
- `values` for attributes without choices from now are empty list.
- attributes with choices - `DROPDOWN` and `MULTISELECT`
- attributes without choices - `FILE`, `REFERENCE`, `NUMERIC` and `RICH_TEXT`
+- Unify checkout identifier in checkout mutations and queries - #7511 by @IKarbowiak
### Other
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 442709856a..694b0e6ca3 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -1,4 +1,5 @@
import datetime
+import uuid
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple
import graphene
@@ -42,8 +43,12 @@ from ..account.types import AddressInput
from ..channel.utils import clean_channel
from ..core.enums import LanguageCodeEnum
from ..core.mutations import BaseMutation, ModelMutation
+from ..core.scalars import UUID
from ..core.types.common import CheckoutError
-from ..core.validators import validate_variants_available_in_channel
+from ..core.validators import (
+ validate_one_of_args_is_in_mutation,
+ validate_variants_available_in_channel,
+)
from ..order.types import Order
from ..product.types import ProductVariant
from ..shipping.types import ShippingMethod
@@ -196,6 +201,23 @@ def validate_variants_available_for_purchase(variants_id: set, channel_id: int):
)
+def get_checkout_by_token(token: uuid.UUID, prefetch_lookups: Iterable[str] = []):
+ try:
+ checkout = models.Checkout.objects.prefetch_related(*prefetch_lookups).get(
+ token=token
+ )
+ except ObjectDoesNotExist:
+ raise ValidationError(
+ {
+ "token": ValidationError(
+ f"Couldn't resolve to a node: {token}.",
+ code=CheckoutErrorCode.NOT_FOUND.value,
+ )
+ }
+ )
+ return checkout
+
+
class CheckoutLineInput(graphene.InputObjectType):
quantity = graphene.Int(required=True, description="The number of items purchased.")
variant_id = graphene.ID(required=True, description="ID of the product variant.")
@@ -393,7 +415,14 @@ class CheckoutLinesAdd(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(description="The ID of the checkout.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "The ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
lines = graphene.List(
CheckoutLineInput,
required=True,
@@ -450,10 +479,22 @@ class CheckoutLinesAdd(BaseMutation):
)
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, lines, replace=False):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(
+ cls, _root, info, lines, checkout_id=None, token=None, replace=False
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
discounts = info.context.discounts
manager = info.context.plugins
@@ -496,15 +537,24 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):
)
@classmethod
- def perform_mutation(cls, root, info, checkout_id, lines):
- return super().perform_mutation(root, info, checkout_id, lines, replace=True)
+ def perform_mutation(cls, root, info, lines, checkout_id=None, token=None):
+ return super().perform_mutation(
+ root, info, lines, checkout_id, token, replace=True
+ )
class CheckoutLineDelete(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(description="The ID of the checkout.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "The ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
line_id = graphene.ID(description="ID of the checkout line to delete.")
class Meta:
@@ -513,10 +563,20 @@ class CheckoutLineDelete(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, line_id):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, line_id, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
line = cls.get_node_or_error(
info, line_id, only_type=CheckoutLine, field="line_id"
)
@@ -541,7 +601,14 @@ class CheckoutCustomerAttach(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(required=True, description="ID of the checkout.")
+ checkout_id = graphene.ID(
+ required=False,
+ description=(
+ "ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ )
+ token = UUID(description="Checkout token.", required=False)
class Meta:
description = "Sets the customer as the owner of the checkout."
@@ -553,11 +620,22 @@ class CheckoutCustomerAttach(BaseMutation):
return context.user.is_authenticated
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, customer_id=None):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(
+ cls, _root, info, checkout_id=None, token=None, customer_id=None
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
checkout.user = info.context.user
checkout.email = info.context.user.email
checkout.save(update_fields=["email", "user", "last_change"])
@@ -570,7 +648,14 @@ class CheckoutCustomerDetach(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
class Meta:
description = "Removes the user assigned as the owner of the checkout."
@@ -582,11 +667,20 @@ class CheckoutCustomerDetach(BaseMutation):
return context.user.is_authenticated
@classmethod
- def perform_mutation(cls, _root, info, checkout_id):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
# Raise error if the current user doesn't own the checkout of the given ID.
if checkout.user and checkout.user != info.context.user:
raise PermissionDenied()
@@ -602,7 +696,14 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(required=True, description="ID of the checkout.")
+ checkout_id = graphene.ID(
+ required=False,
+ description=(
+ "ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ )
+ token = UUID(description="Checkout token.", required=False)
shipping_address = AddressInput(
required=True,
description="The mailing address to where the checkout will be shipped.",
@@ -627,24 +728,36 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):
check_lines_quantity(variants, quantities, country, channel_slug)
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, shipping_address):
- pk = cls.get_global_id_or_error(
- checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(
+ cls, _root, info, shipping_address, checkout_id=None, token=None
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
- try:
- checkout = models.Checkout.objects.prefetch_related(
- "lines__variant__product__product_type"
- ).get(pk=pk)
- except ObjectDoesNotExist:
- raise ValidationError(
- {
- "checkout_id": ValidationError(
- f"Couldn't resolve to a node: {checkout_id}",
- code=CheckoutErrorCode.NOT_FOUND,
- )
- }
+ if token:
+ checkout = get_checkout_by_token(
+ token, prefetch_lookups=["lines__variant__product__product_type"]
)
+ # DEPRECATED
+ if checkout_id:
+ pk = cls.get_global_id_or_error(
+ checkout_id, only_type=Checkout, field="checkout_id"
+ )
+ try:
+ checkout = models.Checkout.objects.prefetch_related(
+ "lines__variant__product__product_type"
+ ).get(pk=pk)
+ except ObjectDoesNotExist:
+ raise ValidationError(
+ {
+ "checkout_id": ValidationError(
+ f"Couldn't resolve to a node: {checkout_id}",
+ code=CheckoutErrorCode.NOT_FOUND,
+ )
+ }
+ )
lines = fetch_checkout_lines(checkout)
if not is_shipping_required(lines):
@@ -695,7 +808,14 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(required=True, description="ID of the checkout.")
+ checkout_id = graphene.ID(
+ required=False,
+ description=(
+ "ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ )
+ token = UUID(description="Checkout token.", required=False)
billing_address = AddressInput(
required=True, description="The billing address of the checkout."
)
@@ -706,10 +826,22 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, billing_address):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(
+ cls, _root, info, billing_address, checkout_id=None, token=None
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
billing_address = cls.validate_address(
billing_address,
address_type=AddressType.BILLING,
@@ -727,7 +859,14 @@ class CheckoutLanguageCodeUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(required=True, description="ID of the checkout.")
+ checkout_id = graphene.ID(
+ required=False,
+ description=(
+ "ID of the checkout."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ )
+ token = UUID(description="Checkout token.", required=False)
language_code = graphene.Argument(
LanguageCodeEnum, required=True, description="New language code."
)
@@ -738,10 +877,20 @@ class CheckoutLanguageCodeUpdate(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, language_code):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, language_code, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
checkout.language_code = language_code
checkout.save(update_fields=["language_code", "last_change"])
info.context.plugins.checkout_updated(checkout)
@@ -752,7 +901,14 @@ class CheckoutEmailUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.")
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
email = graphene.String(required=True, description="email.")
class Meta:
@@ -761,11 +917,20 @@ class CheckoutEmailUpdate(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, email):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, email, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
checkout.email = email
cls.clean_instance(info, checkout)
checkout.save(update_fields=["email", "last_change"])
@@ -777,7 +942,14 @@ class CheckoutShippingMethodUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.")
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
shipping_method_id = graphene.ID(required=True, description="Shipping method.")
class Meta:
@@ -786,10 +958,22 @@ class CheckoutShippingMethodUpdate(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, shipping_method_id):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(
+ cls, _root, info, shipping_method_id, checkout_id=None, token=None
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
manager = info.context.plugins
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(
@@ -857,7 +1041,14 @@ class CheckoutComplete(BaseMutation):
)
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
store_source = graphene.Boolean(
default_value=False,
description=(
@@ -891,22 +1082,35 @@ class CheckoutComplete(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, store_source, **data):
+ def perform_mutation(
+ cls, _root, info, store_source, checkout_id=None, token=None, **data
+ ):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ )
+
tracking_code = analytics.get_client_id(info.context)
with transaction_with_commit_on_errors():
try:
- checkout = cls.get_node_or_error(
- info,
- checkout_id,
- only_type=Checkout,
- field="checkout_id",
- )
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info,
+ checkout_id or token,
+ only_type=Checkout,
+ field="checkout_id",
+ )
except ValidationError as e:
- checkout_token = cls.get_global_id_or_error(
- checkout_id, only_type=Checkout, field="checkout_id"
- )
+ # DEPRECATED
+ if checkout_id:
+ token = cls.get_global_id_or_error(
+ checkout_id, only_type=Checkout, field="checkout_id"
+ )
- order = order_models.Order.objects.get_by_checkout_token(checkout_token)
+ order = order_models.Order.objects.get_by_checkout_token(token)
if order:
if not order.channel.is_active:
raise ValidationError(
@@ -958,7 +1162,14 @@ class CheckoutAddPromoCode(BaseMutation):
)
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID. "
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
promo_code = graphene.String(
description="Gift card code or voucher code.", required=True
)
@@ -969,10 +1180,20 @@ class CheckoutAddPromoCode(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, promo_code):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, promo_code, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
manager = info.context.plugins
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(
@@ -1002,7 +1223,14 @@ class CheckoutRemovePromoCode(BaseMutation):
)
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
promo_code = graphene.String(
description="Gift card code or voucher code.", required=True
)
@@ -1013,10 +1241,20 @@ class CheckoutRemovePromoCode(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, promo_code):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, promo_code, checkout_id=None, token=None):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
manager = info.context.plugins
checkout_info = fetch_checkout_info(
checkout, [], info.context.discounts, manager
diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
index 19247b0188..ce73f66ec6 100644
--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
@@ -242,10 +242,10 @@ def test_add_shipping_to_checkout(
FRAGMENT_CHECKOUT
+ """
mutation updateCheckoutShippingOptions(
- $checkoutId: ID!, $shippingMethodId: ID!
+ $token: UUID, $shippingMethodId: ID!
) {
checkoutShippingMethodUpdate(
- checkoutId: $checkoutId, shippingMethodId: $shippingMethodId
+ token: $token, shippingMethodId: $shippingMethodId
) {
errors {
field
@@ -259,7 +259,7 @@ def test_add_shipping_to_checkout(
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_shipping_address.pk),
+ "token": checkout_with_shipping_address.token,
"shippingMethodId": Node.to_global_id("ShippingMethod", shipping_method.pk),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -275,10 +275,10 @@ def test_add_billing_address_to_checkout(
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutBillingAddress(
- $checkoutId: ID!, $billingAddress: AddressInput!
+ $token: UUID, $billingAddress: AddressInput!
) {
checkoutBillingAddressUpdate(
- checkoutId: $checkoutId, billingAddress: $billingAddress
+ token: $token, billingAddress: $billingAddress
) {
errors {
field
@@ -292,7 +292,7 @@ def test_add_billing_address_to_checkout(
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_shipping_method.pk),
+ "token": checkout_with_shipping_method.token,
"billingAddress": graphql_address_data,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -313,8 +313,8 @@ def test_update_checkout_lines(
query = (
FRAGMENT_CHECKOUT_LINE
+ """
- mutation updateCheckoutLine($checkoutId: ID!, $lines: [CheckoutLineInput]!){
- checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lines) {
+ mutation updateCheckoutLine($token: UUID, $lines: [CheckoutLineInput]!){
+ checkoutLinesUpdate(token: $token, lines: $lines) {
checkout {
id
lines {
@@ -337,7 +337,7 @@ def test_update_checkout_lines(
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_items.pk),
+ "token": checkout_with_items.token,
"lines": [
{
"quantity": 1,
@@ -461,10 +461,10 @@ def test_checkout_shipping_address_update(
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutShippingAddress(
- $checkoutId: ID!, $shippingAddress: AddressInput!
+ $token: UUID, $shippingAddress: AddressInput!
) {
checkoutShippingAddressUpdate(
- checkoutId: $checkoutId, shippingAddress: $shippingAddress
+ token: $token, shippingAddress: $shippingAddress
) {
errors {
field
@@ -478,7 +478,7 @@ def test_checkout_shipping_address_update(
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_variants.pk),
+ "token": checkout_with_variants.pk,
"shippingAddress": graphql_address_data,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -492,9 +492,9 @@ def test_checkout_email_update(api_client, checkout_with_variants, count_queries
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutEmail(
- $checkoutId: ID!, $email: String!
+ $token: UUID, $email: String!
) {
- checkoutEmailUpdate(checkoutId: $checkoutId, email: $email) {
+ checkoutEmailUpdate(token: $token, email: $email) {
checkout {
...Checkout
}
@@ -507,7 +507,7 @@ def test_checkout_email_update(api_client, checkout_with_variants, count_queries
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_variants.pk),
+ "token": checkout_with_variants.token,
"email": "[email protected]",
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -522,8 +522,8 @@ def test_checkout_voucher_code(
query = (
FRAGMENT_CHECKOUT
+ """
- mutation AddCheckoutPromoCode($checkoutId: ID!, $promoCode: String!) {
- checkoutAddPromoCode(checkoutId: $checkoutId, promoCode: $promoCode) {
+ mutation AddCheckoutPromoCode($token: UUID, $promoCode: String!) {
+ checkoutAddPromoCode(token: $token, promoCode: $promoCode) {
checkout {
...Checkout
}
@@ -541,7 +541,7 @@ def test_checkout_voucher_code(
"""
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_billing_address.pk),
+ "token": checkout_with_billing_address.token,
"promoCode": voucher.code,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -554,8 +554,8 @@ def test_checkout_payment_charge(
api_client, checkout_with_billing_address, count_queries
):
query = """
- mutation createPayment($input: PaymentInput!, $checkoutId: ID!) {
- checkoutPaymentCreate(input: $input, checkoutId: $checkoutId) {
+ mutation createPayment($input: PaymentInput!, $token: UUID) {
+ checkoutPaymentCreate(input: $input, token: $token) {
errors {
field
message
@@ -578,7 +578,7 @@ def test_checkout_payment_charge(
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_billing_address.pk),
+ "token": checkout_with_billing_address.token,
"input": {
"amount": total.gross.amount,
"gateway": "mirumee.payments.dummy",
@@ -664,8 +664,8 @@ FRAGMENT_ORDER_DETAIL = (
COMPLETE_CHECKOUT_MUTATION = (
FRAGMENT_ORDER_DETAIL
+ """
- mutation completeCheckout($checkoutId: ID!) {
- checkoutComplete(checkoutId: $checkoutId) {
+ mutation completeCheckout($token: UUID) {
+ checkoutComplete(token: $token) {
errors {
code
field
@@ -689,7 +689,7 @@ def test_complete_checkout(api_client, checkout_with_charged_payment, count_quer
query = COMPLETE_CHECKOUT_MUTATION
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_charged_payment.pk),
+ "token": checkout_with_charged_payment.token,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -707,7 +707,7 @@ def test_complete_checkout_with_single_line(
)
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_charged_payment.pk),
+ "token": checkout_with_charged_payment.token,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -724,7 +724,7 @@ def test_customer_complete_checkout(
checkout.user = customer_user
checkout.save()
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout.pk),
+ "token": checkout.token,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py
new file mode 100644
index 0000000000..e8aa26809f
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py
@@ -0,0 +1,131 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import get_graphql_content
+
+MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """
+ mutation checkoutBillingAddressUpdate(
+ $checkoutId: ID, $token: UUID, $billingAddress: AddressInput!) {
+ checkoutBillingAddressUpdate(
+ checkoutId: $checkoutId,
+ token: $token,
+ billingAddress: $billingAddress
+ ){
+ checkout {
+ token,
+ id
+ },
+ errors {
+ field
+ code
+ message
+ }
+ }
+ }
+"""
+
+
+def test_checkout_billing_address_update_by_id(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+ billing_address = graphql_address_data
+
+ variables = {"checkoutId": checkout_id, "billingAddress": billing_address}
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.billing_address is not None
+ assert checkout.billing_address.first_name == billing_address["firstName"]
+ assert checkout.billing_address.last_name == billing_address["lastName"]
+ assert (
+ checkout.billing_address.street_address_1 == billing_address["streetAddress1"]
+ )
+ assert (
+ checkout.billing_address.street_address_2 == billing_address["streetAddress2"]
+ )
+ assert checkout.billing_address.postal_code == billing_address["postalCode"]
+ assert checkout.billing_address.country == billing_address["country"]
+ assert checkout.billing_address.city == billing_address["city"].upper()
+
+
+def test_checkout_billing_address_update_by_token(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+ billing_address = graphql_address_data
+
+ variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.billing_address is not None
+ assert checkout.billing_address.first_name == billing_address["firstName"]
+ assert checkout.billing_address.last_name == billing_address["lastName"]
+ assert (
+ checkout.billing_address.street_address_1 == billing_address["streetAddress1"]
+ )
+ assert (
+ checkout.billing_address.street_address_2 == billing_address["streetAddress2"]
+ )
+ assert checkout.billing_address.postal_code == billing_address["postalCode"]
+ assert checkout.billing_address.country == billing_address["country"]
+ assert checkout.billing_address.city == billing_address["city"].upper()
+
+
+def test_checkout_billing_address_update_neither_token_and_id_given(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+ billing_address = graphql_address_data
+
+ variables = {"billingAddress": billing_address}
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_billing_address_update_both_token_and_id_given(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+ billing_address = graphql_address_data
+
+ variables = {
+ "billingAddress": billing_address,
+ "token": checkout_with_item.token,
+ "checkoutId": checkout_id,
+ }
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
new file mode 100644
index 0000000000..368136062d
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
@@ -0,0 +1,191 @@
+from unittest.mock import patch
+
+import graphene
+import pytest
+
+from .....checkout import calculations
+from .....checkout.error_codes import CheckoutErrorCode
+from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
+from .....checkout.models import Checkout
+from .....core.taxes import zero_money
+from .....order import OrderOrigin, OrderStatus
+from .....order.models import Order
+from .....plugins.manager import get_plugins_manager
+from ....tests.utils import get_graphql_content
+
+MUTATION_CHECKOUT_COMPLETE = """
+ mutation checkoutComplete($checkoutId: ID, $token: UUID, $redirectUrl: String) {
+ checkoutComplete(
+ checkoutId: $checkoutId, token: $token, redirectUrl: $redirectUrl
+ ) {
+ order {
+ id,
+ token
+ original
+ origin
+ },
+ errors {
+ field,
+ message,
+ variants,
+ code
+ }
+ confirmationNeeded
+ confirmationData
+ }
+ }
+ """
+
+
+def test_checkout_complete_order_already_exists(
+ user_api_client,
+ order_with_lines,
+ checkout_with_gift_card,
+):
+ checkout = checkout_with_gift_card
+ orders_count = Order.objects.count()
+ order_with_lines.checkout_token = checkout.pk
+ order_with_lines.save()
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ checkout.delete()
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert not data["errors"]
+
+ order_data = data["order"]
+ assert Order.objects.count() == orders_count
+ assert order_with_lines.token == order_data["token"]
+ assert order_data["origin"] == order_with_lines.origin.upper()
+ assert not order_data["original"]
+
+
+@patch("saleor.plugins.manager.PluginsManager.order_confirmed")
+def test_checkout_complete(
+ order_confirmed_mock,
+ site_settings,
+ user_api_client,
+ checkout_with_gift_card,
+ gift_card,
+ payment_dummy,
+ address,
+ shipping_method,
+):
+
+ assert not gift_card.last_used_on
+
+ checkout = checkout_with_gift_card
+ checkout.shipping_address = address
+ checkout.shipping_method = shipping_method
+ checkout.billing_address = address
+ checkout.store_value_in_metadata(items={"accepted": "true"})
+ checkout.store_value_in_private_metadata(items={"accepted": "false"})
+ checkout.save()
+
+ checkout_line = checkout.lines.first()
+ checkout_line_quantity = checkout_line.quantity
+ checkout_line_variant = checkout_line.variant
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ total = calculations.calculate_checkout_total_with_gift_cards(
+ manager, checkout_info, lines, address
+ )
+ site_settings.automatically_confirm_all_new_orders = True
+ site_settings.save()
+ payment = payment_dummy
+ payment.is_active = True
+ payment.order = None
+ payment.total = total.gross.amount
+ payment.currency = total.gross.currency
+ payment.checkout = checkout
+ payment.save()
+ assert not payment.transactions.exists()
+
+ orders_count = Order.objects.count()
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ redirect_url = "https://www.example.com"
+ variables = {"checkoutId": checkout_id, "redirectUrl": redirect_url}
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert not data["errors"]
+
+ order_token = data["order"]["token"]
+ assert Order.objects.count() == orders_count + 1
+ order = Order.objects.first()
+ assert order.status == OrderStatus.UNFULFILLED
+ assert order.origin == OrderOrigin.CHECKOUT
+ assert not order.original
+ assert order.token == order_token
+ assert order.redirect_url == redirect_url
+ assert order.total.gross == total.gross
+ assert order.metadata == checkout.metadata
+ assert order.private_metadata == checkout.private_metadata
+
+ order_line = order.lines.first()
+ assert checkout_line_quantity == order_line.quantity
+ assert checkout_line_variant == order_line.variant
+ assert order.shipping_address == address
+ assert order.shipping_method == checkout.shipping_method
+ assert order.payments.exists()
+ order_payment = order.payments.first()
+ assert order_payment == payment
+ assert payment.transactions.count() == 1
+
+ gift_card.refresh_from_db()
+ assert gift_card.current_balance == zero_money(gift_card.currency)
+ assert gift_card.last_used_on
+
+ assert not Checkout.objects.filter(
+ pk=checkout.pk
+ ).exists(), "Checkout should have been deleted"
+ order_confirmed_mock.assert_called_once_with(order)
+
+
+def test_checkout_complete_order_already_exists_neither_token_and_id_given(
+ user_api_client,
+ order_with_lines,
+ checkout_with_gift_card,
+):
+ checkout = checkout_with_gift_card
+ order_with_lines.checkout_token = checkout.pk
+ order_with_lines.save()
+ variables = {"redirectUrl": "https://www.example.com"}
+ checkout.delete()
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert len(data["errors"]) == 1
+ assert not data["order"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_complete_order_already_exists_both_token_and_id_given(
+ user_api_client,
+ order_with_lines,
+ checkout_with_gift_card,
+):
+ checkout = checkout_with_gift_card
+ order_with_lines.checkout_token = checkout.pk
+ order_with_lines.save()
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "redirectUrl": "https://www.example.com",
+ }
+ checkout.delete()
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert len(data["errors"]) == 1
+ assert not data["order"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_create.py
similarity index 100%
rename from saleor/graphql/checkout/tests/deprecated/test_checkout.py
rename to saleor/graphql/checkout/tests/deprecated/test_checkout_create.py
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py
new file mode 100644
index 0000000000..54814b0d81
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py
@@ -0,0 +1,93 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import assert_no_permission, get_graphql_content
+
+CHECKOUT_CUSTOMER_ATTACH_MUTATION = """
+ mutation checkoutCustomerAttach($checkoutId: ID, $token: UUID) {
+ checkoutCustomerAttach(checkoutId: $checkoutId, token: $token) {
+ checkout {
+ token
+ }
+ errors {
+ field
+ message
+ code
+ }
+ }
+ }
+"""
+
+
+def test_checkout_customer_attach_by_id(
+ api_client, user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.email = "[email protected]"
+ checkout.save()
+ assert checkout.user is None
+
+ query = CHECKOUT_CUSTOMER_ATTACH_MUTATION
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ customer_id = graphene.Node.to_global_id("User", customer_user.pk)
+ variables = {"checkoutId": checkout_id, "customerId": customer_id}
+
+ # Mutation should fail for unauthenticated customers
+ response = api_client.post_graphql(query, variables)
+ assert_no_permission(response)
+
+ # Mutation should succeed for authenticated customer
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerAttach"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.user == customer_user
+ assert checkout.email == customer_user.email
+
+
+def test_checkout_customer_attach_neither_token_and_id_given(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.email = "[email protected]"
+ checkout.save()
+ assert checkout.user is None
+
+ query = CHECKOUT_CUSTOMER_ATTACH_MUTATION
+ customer_id = graphene.Node.to_global_id("User", customer_user.pk)
+ variables = {"customerId": customer_id}
+
+ # Mutation should succeed for authenticated customer
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerAttach"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_customer_attach_both_token_and_id_given(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.email = "[email protected]"
+ checkout.save()
+ assert checkout.user is None
+
+ query = CHECKOUT_CUSTOMER_ATTACH_MUTATION
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ customer_id = graphene.Node.to_global_id("User", customer_user.pk)
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "customerId": customer_id,
+ }
+
+ # Mutation should succeed for authenticated customer
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerAttach"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py
new file mode 100644
index 0000000000..e33c8fe914
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py
@@ -0,0 +1,75 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import get_graphql_content
+
+CHECKOUT_EMAIL_UPDATE_MUTATION = """
+ mutation checkoutEmailUpdate($checkoutId: ID, $token: UUID, $email: String!) {
+ checkoutEmailUpdate(checkoutId: $checkoutId, token: $token, email: $email) {
+ checkout {
+ id,
+ email
+ },
+ errors {
+ field,
+ message
+ }
+ errors {
+ field,
+ message
+ code
+ }
+ }
+ }
+"""
+
+
+def test_checkout_email_update_by_id(user_api_client, checkout_with_item):
+ checkout = checkout_with_item
+ assert not checkout.email
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ email = "[email protected]"
+ variables = {"checkoutId": checkout_id, "email": email}
+
+ response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutEmailUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.email == email
+
+
+def test_checkout_email_update_neither_token_and_id_given(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ assert not checkout.email
+
+ email = "[email protected]"
+ variables = {"email": email}
+
+ response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutEmailUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_email_update_both_token_and_id_given(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ assert not checkout.email
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ email = "[email protected]"
+ variables = {"checkoutId": checkout_id, "token": checkout.token, "email": email}
+
+ response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutEmailUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py
new file mode 100644
index 0000000000..8d0d743624
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py
@@ -0,0 +1,88 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import get_graphql_content
+
+MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE = """
+mutation checkoutLanguageCodeUpdate(
+ $checkoutId: ID, $token: UUID, $languageCode: LanguageCodeEnum!
+){
+ checkoutLanguageCodeUpdate(
+ checkoutId: $checkoutId, token: $token, languageCode: $languageCode
+ ){
+ checkout{
+ id
+ languageCode
+ }
+ errors{
+ field
+ message
+ code
+ }
+ }
+}
+"""
+
+
+def test_checkout_update_language_code_by_id(
+ user_api_client,
+ checkout_with_gift_card,
+):
+ language_code = "PL"
+ checkout = checkout_with_gift_card
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {"checkoutId": checkout_id, "languageCode": language_code}
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
+ )
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLanguageCodeUpdate"]
+ assert not data["errors"]
+
+ assert data["checkout"]["languageCode"] == language_code
+ checkout.refresh_from_db()
+ assert checkout.language_code == language_code.lower()
+
+
+def test_checkout_update_language_code_neither_token_and_id_given(
+ user_api_client,
+ checkout_with_gift_card,
+):
+ language_code = "PL"
+ variables = {"languageCode": language_code}
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
+ )
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLanguageCodeUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_update_language_code_both_token_and_id_given(
+ user_api_client,
+ checkout_with_gift_card,
+):
+ language_code = "PL"
+ checkout = checkout_with_gift_card
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "languageCode": language_code,
+ }
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
+ )
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLanguageCodeUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
new file mode 100644
index 0000000000..1f7b89bf51
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
@@ -0,0 +1,100 @@
+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 import update_checkout_shipping_method_if_invalid
+
+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.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+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()
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, 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
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py
new file mode 100644
index 0000000000..9d0dcde6e3
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py
@@ -0,0 +1,113 @@
+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 import update_checkout_shipping_method_if_invalid
+
+MUTATION_CHECKOUT_LINES_ADD = """
+ mutation checkoutLinesAdd(
+ $checkoutId: ID, $token: UUID, $lines: [CheckoutLineInput!]!) {
+ checkoutLinesAdd(checkoutId: $checkoutId, token: $token lines: $lines) {
+ checkout {
+ token
+ quantity
+ lines {
+ quantity
+ variant {
+ id
+ }
+ }
+ }
+ errors {
+ field
+ code
+ message
+ variants
+ }
+ }
+ }"""
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_add_by_checkout_id(
+ mocked_update_shipping_method, user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ lines = fetch_checkout_lines(checkout)
+ assert calculate_checkout_quantity(lines) == 3
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ variables = {
+ "checkoutId": checkout_id,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines = fetch_checkout_lines(checkout)
+ line = checkout.lines.latest("pk")
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 4
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_lines_add_neither_token_and_id_given(
+ user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_lines_add_both_token_and_id_given(
+ user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py
new file mode 100644
index 0000000000..1d1e8c538f
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py
@@ -0,0 +1,120 @@
+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 import update_checkout_shipping_method_if_invalid
+
+MUTATION_CHECKOUT_LINES_UPDATE = """
+ mutation checkoutLinesUpdate(
+ $checkoutId: ID, $token: UUID, $lines: [CheckoutLineInput!]!) {
+ checkoutLinesUpdate(checkoutId: $checkoutId, token: $token, lines: $lines) {
+ checkout {
+ token
+ quantity
+ lines {
+ quantity
+ variant {
+ id
+ }
+ }
+ }
+ errors {
+ field
+ code
+ message
+ variants
+ }
+ }
+ }
+ """
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_update(
+ mocked_update_shipping_method, user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ lines = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ assert calculate_checkout_quantity(lines) == 3
+ line = checkout.lines.first()
+ variant = line.variant
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ variables = {
+ "checkoutId": checkout_id,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 1
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_lines_update_neither_token_and_id_given(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ variant = line.variant
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_lines_update_both_token_and_id_given(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ variant = line.variant
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py
new file mode 100644
index 0000000000..fe317703bb
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py
@@ -0,0 +1,153 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import get_graphql_content
+
+MUTATION_CHECKOUT_ADD_PROMO_CODE = """
+ mutation($checkoutId: ID, $token: UUID, $promoCode: String!) {
+ checkoutAddPromoCode(
+ checkoutId: $checkoutId, token: $token, promoCode: $promoCode) {
+ errors {
+ field
+ message
+ code
+ }
+ checkout {
+ id
+ token
+ voucherCode
+ giftCards {
+ id
+ displayCode
+ }
+ totalPrice {
+ gross {
+ amount
+ }
+ }
+ }
+ }
+ }
+"""
+
+
+def _mutate_checkout_add_promo_code(client, variables):
+ response = client.post_graphql(MUTATION_CHECKOUT_ADD_PROMO_CODE, variables)
+ content = get_graphql_content(response)
+ return content["data"]["checkoutAddPromoCode"]
+
+
+def test_checkout_add_voucher_code_by_id(api_client, checkout_with_item, voucher):
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
+ variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ data = _mutate_checkout_add_promo_code(api_client, variables)
+
+ assert not data["errors"]
+ assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["voucherCode"] == voucher.code
+
+
+def test_checkout_add_voucher_code_neither_token_and_id_given(
+ api_client, checkout_with_item, voucher
+):
+ variables = {"promoCode": voucher.code}
+ data = _mutate_checkout_add_promo_code(api_client, variables)
+
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_add_voucher_code_both_token_and_id_given(
+ api_client, checkout_with_item, voucher
+):
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
+ variables = {
+ "promoCode": voucher.code,
+ "checkoutId": checkout_id,
+ "token": checkout_with_item.token,
+ }
+ data = _mutate_checkout_add_promo_code(api_client, variables)
+
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+MUTATION_CHECKOUT_REMOVE_PROMO_CODE = """
+ mutation($checkoutId: ID, $token: UUID, $promoCode: String!) {
+ checkoutRemovePromoCode(
+ checkoutId: $checkoutId, token: $token, promoCode: $promoCode) {
+ errors {
+ field
+ message
+ code
+ }
+ checkout {
+ id,
+ voucherCode
+ giftCards {
+ id
+ displayCode
+ }
+ }
+ }
+ }
+"""
+
+
+def _mutate_checkout_remove_promo_code(client, variables):
+ response = client.post_graphql(MUTATION_CHECKOUT_REMOVE_PROMO_CODE, variables)
+ content = get_graphql_content(response)
+ return content["data"]["checkoutRemovePromoCode"]
+
+
+def test_checkout_remove_voucher_code(api_client, checkout_with_voucher):
+ assert checkout_with_voucher.voucher_code is not None
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_voucher.pk)
+ variables = {
+ "checkoutId": checkout_id,
+ "promoCode": checkout_with_voucher.voucher_code,
+ }
+
+ data = _mutate_checkout_remove_promo_code(api_client, variables)
+
+ checkout_with_voucher.refresh_from_db()
+ assert not data["errors"]
+ assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["voucherCode"] is None
+ assert checkout_with_voucher.voucher_code is None
+
+
+def test_checkout_remove_voucher_code_neither_token_and_id_given(
+ api_client, checkout_with_voucher
+):
+ assert checkout_with_voucher.voucher_code is not None
+
+ variables = {
+ "promoCode": checkout_with_voucher.voucher_code,
+ }
+
+ data = _mutate_checkout_remove_promo_code(api_client, variables)
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_remove_voucher_code_both_token_and_id_given(
+ api_client, checkout_with_voucher
+):
+ assert checkout_with_voucher.voucher_code is not None
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_voucher.pk)
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout_with_voucher.token,
+ "promoCode": checkout_with_voucher.voucher_code,
+ }
+
+ data = _mutate_checkout_remove_promo_code(api_client, variables)
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py
new file mode 100644
index 0000000000..6791877aca
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py
@@ -0,0 +1,118 @@
+from unittest import mock
+
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
+from .....plugins.manager import get_plugins_manager
+from ....tests.utils import get_graphql_content
+from ...mutations import update_checkout_shipping_method_if_invalid
+
+MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """
+ mutation checkoutShippingAddressUpdate(
+ $checkoutId: ID, $token: UUID, $shippingAddress: AddressInput!) {
+ checkoutShippingAddressUpdate(
+ checkoutId: $checkoutId,
+ token: $token,
+ shippingAddress: $shippingAddress
+ ) {
+ checkout {
+ token,
+ id
+ },
+ errors {
+ field
+ message
+ code
+ }
+ }
+ }"""
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_shipping_address_update_by_id(
+ mocked_update_shipping_method,
+ user_api_client,
+ checkout_with_item,
+ graphql_address_data,
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ shipping_address = graphql_address_data
+ variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutShippingAddressUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.shipping_address is not None
+ assert checkout.shipping_address.first_name == shipping_address["firstName"]
+ assert checkout.shipping_address.last_name == shipping_address["lastName"]
+ assert (
+ checkout.shipping_address.street_address_1 == shipping_address["streetAddress1"]
+ )
+ assert (
+ checkout.shipping_address.street_address_2 == shipping_address["streetAddress2"]
+ )
+ assert checkout.shipping_address.postal_code == shipping_address["postalCode"]
+ assert checkout.shipping_address.country == shipping_address["country"]
+ assert checkout.shipping_address.city == shipping_address["city"].upper()
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_shipping_address_update_neither_token_and_id_given(
+ user_api_client,
+ checkout_with_item,
+ graphql_address_data,
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ shipping_address = graphql_address_data
+ variables = {"shippingAddress": shipping_address}
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutShippingAddressUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_shipping_address_update_both_token_and_id_given(
+ user_api_client,
+ checkout_with_item,
+ graphql_address_data,
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ shipping_address = graphql_address_data
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "shippingAddress": shipping_address,
+ }
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutShippingAddressUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py
new file mode 100644
index 0000000000..cf7ca6c148
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py
@@ -0,0 +1,143 @@
+from unittest.mock import patch
+
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
+from .....plugins.manager import get_plugins_manager
+from ....tests.utils import get_graphql_content
+
+MUTATION_UPDATE_SHIPPING_METHOD = """
+ mutation checkoutShippingMethodUpdate(
+ $checkoutId: ID, $token: UUID, $shippingMethodId: ID!){
+ checkoutShippingMethodUpdate(
+ checkoutId: $checkoutId,
+ token: $token,
+ shippingMethodId: $shippingMethodId
+ ) {
+ errors {
+ field
+ message
+ code
+ }
+ checkout {
+ id
+ token
+ }
+ }
+ }
+"""
+
+
+@patch("saleor.graphql.checkout.mutations.clean_shipping_method")
+def test_checkout_shipping_method_update_by_id(
+ mock_clean_shipping,
+ staff_api_client,
+ shipping_method,
+ checkout_with_item,
+):
+ checkout = checkout_with_item
+ old_shipping_method = checkout.shipping_method
+ query = MUTATION_UPDATE_SHIPPING_METHOD
+ mock_clean_shipping.return_value = True
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
+
+ response = staff_api_client.post_graphql(
+ query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ )
+ data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
+
+ checkout.refresh_from_db()
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ checkout_info.shipping_method = old_shipping_method
+ checkout_info.shipping_method_channel_listings = None
+ mock_clean_shipping.assert_called_once_with(
+ checkout_info=checkout_info, lines=lines, method=shipping_method
+ )
+ errors = data["errors"]
+ assert not errors
+ assert data["checkout"]["id"] == checkout_id
+ assert checkout.shipping_method == shipping_method
+
+
+@patch("saleor.graphql.checkout.mutations.clean_shipping_method")
+def test_checkout_shipping_method_update_by_token(
+ mock_clean_shipping,
+ staff_api_client,
+ shipping_method,
+ checkout_with_item,
+):
+ checkout = checkout_with_item
+ old_shipping_method = checkout.shipping_method
+ query = MUTATION_UPDATE_SHIPPING_METHOD
+ mock_clean_shipping.return_value = True
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
+
+ response = staff_api_client.post_graphql(
+ query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ )
+ data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
+
+ checkout.refresh_from_db()
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ checkout_info.shipping_method = old_shipping_method
+ checkout_info.shipping_method_channel_listings = None
+ mock_clean_shipping.assert_called_once_with(
+ checkout_info=checkout_info, lines=lines, method=shipping_method
+ )
+ errors = data["errors"]
+ assert not errors
+ assert data["checkout"]["id"] == checkout_id
+ assert checkout.shipping_method == shipping_method
+
+
+@patch("saleor.graphql.checkout.mutations.clean_shipping_method")
+def test_checkout_shipping_method_update_neither_token_and_id_given(
+ mock_clean_shipping, staff_api_client, checkout_with_item, shipping_method
+):
+ query = MUTATION_UPDATE_SHIPPING_METHOD
+ mock_clean_shipping.return_value = True
+
+ method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
+
+ response = staff_api_client.post_graphql(query, {"shippingMethodId": method_id})
+ data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+@patch("saleor.graphql.checkout.mutations.clean_shipping_method")
+def test_checkout_shipping_method_update_both_token_and_id_given(
+ mock_clean_shipping, staff_api_client, checkout_with_item, shipping_method
+):
+ checkout = checkout_with_item
+ query = MUTATION_UPDATE_SHIPPING_METHOD
+ mock_clean_shipping.return_value = True
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
+
+ response = staff_api_client.post_graphql(
+ query,
+ {
+ "checkoutId": checkout_id,
+ "token": checkout_with_item.token,
+ "shippingMethodId": method_id,
+ },
+ )
+ data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
+
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py b/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py
new file mode 100644
index 0000000000..fd214cb2e8
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py
@@ -0,0 +1,77 @@
+import graphene
+
+from .....checkout.error_codes import CheckoutErrorCode
+from ....tests.utils import get_graphql_content
+
+MUTATION_CHECKOUT_CUSTOMER_DETACH = """
+ mutation checkoutCustomerDetach($checkoutId: ID, $token: UUID) {
+ checkoutCustomerDetach(checkoutId: $checkoutId, token: $token) {
+ checkout {
+ token
+ }
+ errors {
+ field
+ message
+ code
+ }
+ }
+ }
+ """
+
+
+def test_checkout_customer_detach_by_id(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.user = customer_user
+ checkout.save(update_fields=["user"])
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {"checkoutId": checkout_id}
+
+ # Mutation should succeed if the user owns this checkout.
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_CUSTOMER_DETACH, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerDetach"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.user is None
+
+
+def test_checkout_customer_detach_neither_token_and_id_given(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.user = customer_user
+ checkout.save(update_fields=["user"])
+
+ # Mutation should succeed if the user owns this checkout.
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_CUSTOMER_DETACH, {})
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerDetach"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_customer_detach_both_token_and_id_given(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.user = customer_user
+ checkout.save(update_fields=["user"])
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ variables = {"checkoutId": checkout_id, "token": checkout.token}
+
+ # Mutation should succeed if the user owns this checkout.
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_CUSTOMER_DETACH, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerDetach"]
+ assert len(data["errors"]) == 1
+ assert not data["checkout"]
+ assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.py
index 5fbeec8907..f8bb28ee20 100644
--- a/saleor/graphql/checkout/tests/test_checkout.py
+++ b/saleor/graphql/checkout/tests/test_checkout.py
@@ -1437,443 +1437,6 @@ def test_checkout_no_available_shipping_methods_without_lines(api_client, checko
assert data["availableShippingMethods"] == []
-MUTATION_CHECKOUT_LINES_ADD = """
- mutation checkoutLinesAdd(
- $checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
- checkoutLinesAdd(checkoutId: $checkoutId, lines: $lines) {
- checkout {
- token
- quantity
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- code
- message
- variants
- }
- }
- }"""
-
-
- "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
- wraps=update_checkout_shipping_method_if_invalid,
-)
-def test_checkout_lines_add(
- mocked_update_shipping_method, user_api_client, checkout_with_item, stock
-):
- variant = stock.product_variant
- checkout = checkout_with_item
- line = checkout.lines.first()
- lines = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 3
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- "channelSlug": checkout.channel.slug,
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesAdd"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines = fetch_checkout_lines(checkout)
- line = checkout.lines.latest("pk")
- assert line.variant == variant
- assert line.quantity == 1
- assert calculate_checkout_quantity(lines) == 4
-
- manager = get_plugins_manager()
- lines = fetch_checkout_lines(checkout)
- checkout_info = fetch_checkout_info(checkout, lines, [], manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
-
-
-def test_checkout_lines_add_with_unavailable_variant(
- user_api_client, checkout_with_item, stock
-):
- variant = stock.product_variant
- variant.channel_listings.filter(channel=checkout_with_item.channel).update(
- price_amount=None
- )
- checkout = checkout_with_item
- line = checkout.lines.first()
- assert line.quantity == 3
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- "channelSlug": checkout.channel.slug,
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- errors = content["data"]["checkoutLinesAdd"]["errors"]
- assert errors[0]["code"] == CheckoutErrorCode.UNAVAILABLE_VARIANT_IN_CHANNEL.name
- assert errors[0]["field"] == "lines"
- assert errors[0]["variants"] == [variant_id]
-
-
-def test_checkout_lines_add_with_zero_quantity(
- user_api_client, checkout_with_item, stock
-):
- variant = stock.product_variant
- checkout = checkout_with_item
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 0}],
- "channelSlug": checkout.channel.slug,
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- errors = content["data"]["checkoutLinesAdd"]["errors"]
- assert errors[0]["code"] == CheckoutErrorCode.ZERO_QUANTITY.name
- assert errors[0]["field"] == "quantity"
-
-
-def test_checkout_lines_add_no_channel_shipping_zones(
- user_api_client, checkout_with_item, stock
-):
- variant = stock.product_variant
- checkout = checkout_with_item
- checkout.channel.shipping_zones.clear()
- line = checkout.lines.first()
- assert line.quantity == 3
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- "channelSlug": checkout.channel.slug,
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLinesAdd"]
- errors = data["errors"]
- assert len(errors) == 1
- assert errors[0]["code"] == CheckoutErrorCode.INSUFFICIENT_STOCK.name
- assert errors[0]["field"] == "quantity"
-
-
-def test_checkout_lines_add_with_unpublished_product(
- user_api_client, checkout_with_item, stock, channel_USD
-):
- variant = stock.product_variant
- product = variant.product
- ProductChannelListing.objects.filter(product=product, channel=channel_USD).update(
- is_published=False
- )
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- "channelSlug": checkout_with_item.channel.slug,
- }
-
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
-
- content = get_graphql_content(response)
- error = content["data"]["checkoutLinesAdd"]["errors"][0]
- assert error["code"] == CheckoutErrorCode.PRODUCT_NOT_PUBLISHED.name
-
-
-def test_checkout_lines_add_with_unavailable_for_purchase_product(
- user_api_client, checkout_with_item, stock
-):
- # given
- variant = stock.product_variant
- product = stock.product_variant.product
- product.channel_listings.update(available_for_purchase=None)
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
-
- # then
- content = get_graphql_content(response)
- error = content["data"]["checkoutLinesAdd"]["errors"][0]
- assert error["field"] == "lines"
- assert error["code"] == CheckoutErrorCode.PRODUCT_UNAVAILABLE_FOR_PURCHASE.name
- assert error["variants"] == [variant_id]
-
-
-def test_checkout_lines_add_with_available_for_purchase_from_tomorrow_product(
- user_api_client, checkout_with_item, stock
-):
- # given
- variant = stock.product_variant
- product = stock.product_variant.product
- product.channel_listings.update(
- available_for_purchase=datetime.date.today() + datetime.timedelta(days=1)
- )
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
-
- # when
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
-
- # then
- content = get_graphql_content(response)
- error = content["data"]["checkoutLinesAdd"]["errors"][0]
- assert error["field"] == "lines"
- assert error["code"] == CheckoutErrorCode.PRODUCT_UNAVAILABLE_FOR_PURCHASE.name
- assert error["variants"] == [variant_id]
-
-
-def test_checkout_lines_add_too_many(user_api_client, checkout_with_item, stock):
- variant = stock.product_variant
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 51}],
- "channelSlug": checkout_with_item.channel.slug,
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)["data"]["checkoutLinesAdd"]
-
- assert content["errors"]
- assert content["errors"] == [
- {
- "field": "quantity",
- "message": "Cannot add more than 50 times this item.",
- "code": "QUANTITY_GREATER_THAN_LIMIT",
- "variants": None,
- }
- ]
-
-
-def test_checkout_lines_add_empty_checkout(user_api_client, checkout, stock):
- variant = stock.product_variant
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesAdd"]
- assert not data["errors"]
- checkout.refresh_from_db()
- line = checkout.lines.first()
- assert line.variant == variant
- assert line.quantity == 1
-
-
-def test_checkout_lines_add_variant_without_inventory_tracking(
- user_api_client, checkout, variant_without_inventory_tracking
-):
- variant = variant_without_inventory_tracking
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesAdd"]
- assert not data["errors"]
- checkout.refresh_from_db()
- line = checkout.lines.first()
- assert line.variant == variant
- assert line.quantity == 1
-
-
-def test_checkout_lines_add_check_lines_quantity(user_api_client, checkout, stock):
- variant = stock.product_variant
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 16}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesAdd"]
- assert data["errors"][0]["message"] == (
- "Could not add items SKU_A. Only 15 remaining in stock."
- )
- assert data["errors"][0]["field"] == "quantity"
-
-
-def test_checkout_lines_invalid_variant_id(user_api_client, checkout, stock):
- variant = stock.product_variant
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- invalid_variant_id = "InvalidId"
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [
- {"variantId": variant_id, "quantity": 1},
- {"variantId": invalid_variant_id, "quantity": 3},
- ],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesAdd"]
- error_msg = "Could not resolve to a node with the global id list of '%s'."
- assert data["errors"][0]["message"] == error_msg % [invalid_variant_id]
- assert data["errors"][0]["field"] == "variantId"
-
-
-MUTATION_CHECKOUT_LINES_UPDATE = """
- mutation checkoutLinesUpdate(
- $checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
- checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lines) {
- checkout {
- token
- quantity
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- code
- message
- variants
- }
- }
- }
- """
-
-
- "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
- wraps=update_checkout_shipping_method_if_invalid,
-)
-def test_checkout_lines_update(
- mocked_update_shipping_method, user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- lines = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 1
- assert calculate_checkout_quantity(lines) == 3
- line = checkout.lines.first()
- variant = line.variant
- assert line.quantity == 3
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLinesUpdate"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines = fetch_checkout_lines(checkout)
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- assert line.variant == variant
- assert line.quantity == 1
- assert calculate_checkout_quantity(lines) == 1
-
- manager = get_plugins_manager()
- lines = fetch_checkout_lines(checkout)
- checkout_info = fetch_checkout_info(checkout, lines, [], manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
-
-
-def test_checkout_lines_update_with_unavailable_variant(
- user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- variant = line.variant
- variant.channel_listings.filter(channel=checkout_with_item.channel).update(
- price_amount=None
- )
- assert line.quantity == 3
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
-
- errors = content["data"]["checkoutLinesUpdate"]["errors"]
- assert errors[0]["code"] == CheckoutErrorCode.UNAVAILABLE_VARIANT_IN_CHANNEL.name
- assert errors[0]["field"] == "lines"
- assert errors[0]["variants"] == [variant_id]
-
-
-def test_checkout_lines_update_channel_without_shipping_zones(
- user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- checkout.channel.shipping_zones.clear()
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- variant = line.variant
- assert line.quantity == 3
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesUpdate"]
- errors = data["errors"]
- assert len(errors) == 1
- assert errors[0]["code"] == CheckoutErrorCode.INSUFFICIENT_STOCK.name
- assert errors[0]["field"] == "quantity"
-
-
def test_create_checkout_with_unpublished_product(
user_api_client, checkout_with_item, stock, channel_USD
):
@@ -1909,173 +1472,6 @@ def test_create_checkout_with_unpublished_product(
assert error["code"] == CheckoutErrorCode.PRODUCT_NOT_PUBLISHED.name
-def test_checkout_lines_update_with_unpublished_product(
- user_api_client, checkout_with_item, channel_USD
-):
- checkout = checkout_with_item
- line = checkout.lines.first()
- variant = line.variant
- product = variant.product
- ProductChannelListing.objects.filter(product=product, channel=channel_USD).update(
- is_published=False
- )
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
-
- content = get_graphql_content(response)
- error = content["data"]["checkoutLinesUpdate"]["errors"][0]
- assert error["code"] == CheckoutErrorCode.PRODUCT_NOT_PUBLISHED.name
-
-
-def test_checkout_lines_update_invalid_checkout_id(user_api_client):
- variables = {"checkoutId": "test", "lines": []}
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutLinesUpdate"]
- assert data["errors"][0]["field"] == "checkoutId"
-
-
-def test_checkout_lines_update_check_lines_quantity(
- user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- line = checkout.lines.first()
- variant = line.variant
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 11}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLinesUpdate"]
- assert data["errors"][0]["message"] == (
- "Could not add items 123. Only 10 remaining in stock."
- )
- assert data["errors"][0]["field"] == "quantity"
-
-
-def test_checkout_lines_update_with_chosen_shipping(
- user_api_client, checkout, stock, address, shipping_method
-):
- checkout.shipping_address = address
- checkout.shipping_method = shipping_method
- checkout.save()
-
- variant = stock.product_variant
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 1}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLinesUpdate"]
- assert not data["errors"]
- checkout.refresh_from_db()
- lines = fetch_checkout_lines(checkout)
- assert calculate_checkout_quantity(lines) == 1
-
-
-MUTATION_CHECKOUT_LINES_DELETE = """
- mutation checkoutLineDelete($checkoutId: ID!, $lineId: ID!) {
- checkoutLineDelete(checkoutId: $checkoutId, lineId: $lineId) {
- checkout {
- token
- lines {
- quantity
- variant {
- id
- }
- }
- }
- errors {
- field
- message
- }
- }
- }
-"""
-
-
- "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
- wraps=update_checkout_shipping_method_if_invalid,
-)
-def test_checkout_line_delete(
- 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()
- checkout_info = fetch_checkout_info(checkout, lines, [], manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
-
-
- "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
- wraps=update_checkout_shipping_method_if_invalid,
-)
-def test_checkout_line_delete_by_zero_quantity(
- mocked_update_shipping_method, user_api_client, checkout_with_item
-):
- checkout = checkout_with_item
- assert checkout.lines.count() == 1
- line = checkout.lines.first()
- variant = line.variant
- assert line.quantity == 3
-
- variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
-
- variables = {
- "checkoutId": checkout_id,
- "lines": [{"variantId": variant_id, "quantity": 0}],
- }
- response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
- content = get_graphql_content(response)
-
- data = content["data"]["checkoutLinesUpdate"]
- assert not data["errors"]
- checkout.refresh_from_db()
- assert checkout.lines.count() == 0
- manager = get_plugins_manager()
- lines = fetch_checkout_lines(checkout)
- checkout_info = fetch_checkout_info(checkout, lines, [], manager)
- mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
-
-
def test_checkout_customer_attach(
api_client, user_api_client, checkout_with_item, customer_user
):
@@ -2085,8 +1481,8 @@ def test_checkout_customer_attach(
assert checkout.user is None
query = """
- mutation checkoutCustomerAttach($checkoutId: ID!) {
- checkoutCustomerAttach(checkoutId: $checkoutId) {
+ mutation checkoutCustomerAttach($token: UUID) {
+ checkoutCustomerAttach(token: $token) {
checkout {
token
}
@@ -2097,9 +1493,8 @@ def test_checkout_customer_attach(
}
}
"""
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
customer_id = graphene.Node.to_global_id("User", customer_user.pk)
- variables = {"checkoutId": checkout_id, "customerId": customer_id}
+ variables = {"token": checkout.token, "customerId": customer_id}
# Mutation should fail for unauthenticated customers
response = api_client.post_graphql(query, variables)
@@ -2116,8 +1511,8 @@ def test_checkout_customer_attach(
MUTATION_CHECKOUT_CUSTOMER_DETACH = """
- mutation checkoutCustomerDetach($checkoutId: ID!) {
- checkoutCustomerDetach(checkoutId: $checkoutId) {
+ mutation checkoutCustomerDetach($token: UUID) {
+ checkoutCustomerDetach(token: $token) {
checkout {
token
}
@@ -2135,8 +1530,7 @@ def test_checkout_customer_detach(user_api_client, checkout_with_item, customer_
checkout.user = customer_user
checkout.save(update_fields=["user"])
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id}
+ variables = {"token": checkout.token}
# Mutation should succeed if the user owns this checkout.
response = user_api_client.post_graphql(
@@ -2160,9 +1554,9 @@ def test_checkout_customer_detach(user_api_client, checkout_with_item, customer_
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """
mutation checkoutShippingAddressUpdate(
- $checkoutId: ID!, $shippingAddress: AddressInput!) {
+ $token: UUID, $shippingAddress: AddressInput!) {
checkoutShippingAddressUpdate(
- checkoutId: $checkoutId, shippingAddress: $shippingAddress) {
+ token: $token, shippingAddress: $shippingAddress) {
checkout {
token,
id
@@ -2188,10 +1582,9 @@ def test_checkout_shipping_address_update(
):
checkout = checkout_with_item
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout_with_item.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2236,13 +1629,12 @@ def test_checkout_shipping_address_update_changes_checkout_country(
checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())
add_variant_to_checkout(checkout_info, variant, 1)
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2291,13 +1683,12 @@ def test_checkout_shipping_address_update_insufficient_stocks(
warehouse__shipping_zones__countries__contains="US", product_variant=variant
).update(quantity=0)
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2317,10 +1708,9 @@ def test_checkout_shipping_address_update_channel_without_shipping_zones(
checkout = checkout_with_item
checkout.channel.shipping_zones.clear()
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2345,7 +1735,7 @@ def test_checkout_shipping_address_with_invalid_phone_number_returns_error(
user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,
{
- "checkoutId": graphene.Node.to_global_id("Checkout", checkout.pk),
+ "token": checkout.token,
"shippingAddress": shipping_address,
},
)
@@ -2368,11 +1758,10 @@ def test_checkout_shipping_address_update_with_phone_country_prefix(
):
checkout = checkout_with_item
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
shipping_address["phone"] = number
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2387,11 +1776,10 @@ def test_checkout_shipping_address_update_without_phone_country_prefix(
):
checkout = checkout_with_item
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
shipping_address = graphql_address_data
shipping_address["phone"] = "+1-202-555-0132"
- variables = {"checkoutId": checkout_id, "shippingAddress": shipping_address}
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2406,13 +1794,12 @@ def test_checkout_billing_address_update(
):
checkout = checkout_with_item
assert checkout.shipping_address is None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
query = """
mutation checkoutBillingAddressUpdate(
- $checkoutId: ID!, $billingAddress: AddressInput!) {
+ $token: UUID, $billingAddress: AddressInput!) {
checkoutBillingAddressUpdate(
- checkoutId: $checkoutId, billingAddress: $billingAddress) {
+ token: $token, billingAddress: $billingAddress) {
checkout {
token,
id
@@ -2426,7 +1813,7 @@ def test_checkout_billing_address_update(
"""
billing_address = graphql_address_data
- variables = {"checkoutId": checkout_id, "billingAddress": billing_address}
+ variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -2448,8 +1835,8 @@ def test_checkout_billing_address_update(
CHECKOUT_EMAIL_UPDATE_MUTATION = """
- mutation checkoutEmailUpdate($checkoutId: ID!, $email: String!) {
- checkoutEmailUpdate(checkoutId: $checkoutId, email: $email) {
+ mutation checkoutEmailUpdate($token: UUID, $email: String!) {
+ checkoutEmailUpdate(token: $token, email: $email) {
checkout {
id,
email
@@ -2471,10 +1858,9 @@ CHECKOUT_EMAIL_UPDATE_MUTATION = """
def test_checkout_email_update(user_api_client, checkout_with_item):
checkout = checkout_with_item
assert not checkout.email
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "email": email}
+ variables = {"token": checkout.token, "email": email}
response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
content = get_graphql_content(response)
@@ -2485,8 +1871,7 @@ def test_checkout_email_update(user_api_client, checkout_with_item):
def test_checkout_email_update_validation(user_api_client, checkout_with_item):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "email": ""}
+ variables = {"token": checkout_with_item.token, "email": ""}
response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
content = get_graphql_content(response)
@@ -2829,16 +2214,16 @@ def test_checkout_prices(user_api_client, checkout_with_item):
MUTATION_UPDATE_SHIPPING_METHOD = """
mutation checkoutShippingMethodUpdate(
- $checkoutId:ID!, $shippingMethodId:ID!){
+ $token: UUID, $shippingMethodId: ID!){
checkoutShippingMethodUpdate(
- checkoutId:$checkoutId, shippingMethodId:$shippingMethodId) {
+ token: $token, shippingMethodId: $shippingMethodId) {
errors {
field
message
code
}
checkout {
- id
+ token
}
}
}
@@ -2859,11 +2244,10 @@ def test_checkout_shipping_method_update(
query = MUTATION_UPDATE_SHIPPING_METHOD
mock_clean_shipping.return_value = is_valid_shipping_method
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -2880,7 +2264,7 @@ def test_checkout_shipping_method_update(
errors = data["errors"]
if is_valid_shipping_method:
assert not errors
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert checkout.shipping_method == shipping_method
else:
assert len(errors) == 1
@@ -2905,11 +2289,10 @@ def test_checkout_shipping_method_update_excluded_postal_code(
query = MUTATION_UPDATE_SHIPPING_METHOD
mock_is_shipping_method_available.return_value = False
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -2938,11 +2321,10 @@ def test_checkout_shipping_method_update_shipping_zone_without_channel(
checkout.save(update_fields=["shipping_address"])
query = MUTATION_UPDATE_SHIPPING_METHOD
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -2966,11 +2348,10 @@ def test_checkout_shipping_method_update_shipping_zone_with_channel(
checkout.save(update_fields=["shipping_address"])
query = MUTATION_UPDATE_SHIPPING_METHOD
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -2979,7 +2360,7 @@ def test_checkout_shipping_method_update_shipping_zone_with_channel(
checkout.refresh_from_db()
errors = data["errors"]
assert not errors
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert checkout.shipping_method == shipping_method
diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.py
index db1409b176..55a372b352 100644
--- a/saleor/graphql/checkout/tests/test_checkout_complete.py
+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py
@@ -1,3 +1,4 @@
+import uuid
from decimal import Decimal
from unittest.mock import ANY, patch
@@ -21,8 +22,8 @@ from ....warehouse.tests.utils import get_available_quantity_for_stock
from ...tests.utils import get_graphql_content
MUTATION_CHECKOUT_COMPLETE = """
- mutation checkoutComplete($checkoutId: ID!, $redirectUrl: String) {
- checkoutComplete(checkoutId: $checkoutId, redirectUrl: $redirectUrl) {
+ mutation checkoutComplete($token: UUID, $redirectUrl: String) {
+ checkoutComplete(token: $token, redirectUrl: $redirectUrl) {
order {
id,
token
@@ -75,8 +76,7 @@ def test_checkout_complete_unconfirmed_order_already_exists(
order_with_lines.status = OrderStatus.UNCONFIRMED
order_with_lines.checkout_token = checkout.pk
order_with_lines.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -100,8 +100,7 @@ def test_checkout_complete_order_already_exists(
orders_count = Order.objects.count()
order_with_lines.checkout_token = checkout.pk
order_with_lines.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -128,8 +127,7 @@ def test_checkout_complete_with_inactive_channel_order_already_exists(
channel.save()
order_with_lines.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -180,8 +178,7 @@ def test_checkout_complete_with_inactive_channel(
payment.save()
assert not payment.transactions.exists()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -235,9 +232,8 @@ def test_checkout_complete(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
redirect_url = "https://www.example.com"
- variables = {"checkoutId": checkout_id, "redirectUrl": redirect_url}
+ variables = {"token": checkout.token, "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -298,10 +294,9 @@ def test_checkout_complete_with_variant_without_price(
price_amount=None
)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
variant_id = graphene.Node.to_global_id("ProductVariant", checkout_line_variant.pk)
redirect_url = "https://www.example.com"
- variables = {"checkoutId": checkout_id, "redirectUrl": redirect_url}
+ variables = {"token": checkout.token, "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -325,8 +320,10 @@ def test_checkout_complete_requires_confirmation(
payment.checkout = checkout_ready_to_complete
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_ready_to_complete.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "token": checkout_ready_to_complete.token,
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -380,8 +377,7 @@ def test_checkout_with_voucher_complete(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -449,8 +445,7 @@ def test_checkout_complete_without_inventory_tracking(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -525,8 +520,7 @@ def test_checkout_complete_error_in_gateway_response_for_dummy_credit_card(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -598,8 +592,7 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
get_graphql_content(response)
@@ -621,15 +614,15 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
mocked_process_payment.assert_called_once()
-def test_checkout_complete_invalid_checkout_id(user_api_client):
- checkout_id = "invalidId"
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+def test_checkout_complete_invalid_token(user_api_client):
+ token = uuid.uuid4()
+ variables = {"token": token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutComplete"]
- assert data["errors"][0]["message"] == "Couldn't resolve id: invalidId."
- assert data["errors"][0]["field"] == "checkoutId"
+ assert data["errors"][0]["message"] == f"Couldn't resolve to a node: {token}."
+ assert data["errors"][0]["field"] == "token"
assert orders_count == Order.objects.count()
@@ -641,8 +634,7 @@ def test_checkout_complete_no_payment(
checkout.shipping_method = shipping_method
checkout.billing_address = address
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -684,8 +676,7 @@ def test_checkout_complete_confirmation_needed(
payment.checkout = checkout
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -738,10 +729,9 @@ def test_checkout_confirm(
payment.checkout = checkout
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
orders_count = Order.objects.count()
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutComplete"]
@@ -783,8 +773,7 @@ def test_checkout_complete_insufficient_stock(
payment.currency = total.gross.currency
payment.checkout = checkout
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -831,8 +820,7 @@ def test_checkout_complete_insufficient_stock_payment_refunded(
payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
# when
@@ -888,8 +876,7 @@ def test_checkout_complete_insufficient_stock_payment_voided(
payment.charge_status = ChargeStatus.NOT_CHARGED
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
# when
@@ -944,8 +931,7 @@ def test_checkout_complete_without_redirect_url(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id}
+ variables = {"token": checkout.token}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1010,8 +996,7 @@ def test_checkout_complete_payment_payment_total_different_than_checkout(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -1035,10 +1020,10 @@ def test_order_already_exists(
checkout = checkout_ready_to_complete
order_with_lines.checkout_token = checkout.token
order_with_lines.save()
+ token = checkout.token
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
checkout.delete()
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1075,8 +1060,7 @@ def test_create_order_raises_insufficient_stock(
payment.checkout = checkout
payment.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1095,8 +1079,7 @@ def test_checkout_complete_with_digital(
order_count = Order.objects.count()
checkout = checkout_with_digital_item
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
# Set a billing address
checkout.billing_address = address
@@ -1177,8 +1160,7 @@ def test_checkout_complete_0_total_value(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
diff --git a/saleor/graphql/checkout/tests/test_checkout_digital.py b/saleor/graphql/checkout/tests/test_checkout_digital.py
index f23902ef50..0ba7b73b69 100644
--- a/saleor/graphql/checkout/tests/test_checkout_digital.py
+++ b/saleor/graphql/checkout/tests/test_checkout_digital.py
@@ -12,11 +12,13 @@ from ...checkout.mutations import update_checkout_shipping_method_if_invalid
from ...tests.utils import get_graphql_content
from .test_checkout import (
MUTATION_CHECKOUT_CREATE,
- MUTATION_CHECKOUT_LINES_DELETE,
- MUTATION_CHECKOUT_LINES_UPDATE,
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,
MUTATION_UPDATE_SHIPPING_METHOD,
)
+from .test_checkout_lines import (
+ MUTATION_CHECKOUT_LINES_DELETE,
+ MUTATION_CHECKOUT_LINES_UPDATE,
+)
@pytest.mark.parametrize("with_shipping_address", (True, False))
@@ -96,8 +98,7 @@ def test_checkout_update_shipping_address(
"""Test updating the shipping address of a digital order throws an error."""
checkout = checkout_with_digital_item
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "shippingAddress": graphql_address_data}
+ variables = {"token": checkout.token, "shippingAddress": graphql_address_data}
response = api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -124,9 +125,8 @@ def test_checkout_update_shipping_method(
"""Test updating the shipping method of a digital order throws an error."""
checkout = checkout_with_digital_item
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.pk)
- variables = {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ variables = {"token": checkout.token, "shippingMethodId": method_id}
# Put a shipping address, to ensure it is still handled properly
checkout.shipping_address = address
@@ -181,10 +181,9 @@ def test_checkout_lines_update_remove_shipping_if_removed_product_with_shipping(
variant = line.variant
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"lines": [{"variantId": variant_id, "quantity": 0}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -210,9 +209,8 @@ def test_checkout_line_delete_remove_shipping_if_removed_product_with_shipping(
line = checkout.lines.first()
line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "lineId": line_id}
+ variables = {"token": checkout.token, "lineId": line_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
content = get_graphql_content(response)
diff --git a/saleor/graphql/checkout/tests/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
index a13444ebf3..ca21fec5c2 100644
--- a/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
+++ b/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
@@ -1,10 +1,8 @@
-import graphene
-
from saleor.graphql.tests.utils import get_graphql_content
MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE = """
-mutation checkoutLanguageCodeUpdate($checkoutId: ID!, $languageCode: LanguageCodeEnum!){
- checkoutLanguageCodeUpdate(checkoutId:$checkoutId, languageCode: $languageCode){
+mutation checkoutLanguageCodeUpdate($token: UUID, $languageCode: LanguageCodeEnum!){
+ checkoutLanguageCodeUpdate(token: $token, languageCode: $languageCode){
checkout{
id
languageCode
@@ -12,6 +10,7 @@ mutation checkoutLanguageCodeUpdate($checkoutId: ID!, $languageCode: LanguageCod
errors{
field
message
+ code
}
}
}
@@ -24,8 +23,7 @@ def test_checkout_update_language_code(
):
language_code = "PL"
checkout = checkout_with_gift_card
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "languageCode": language_code}
+ variables = {"token": checkout.token, "languageCode": language_code}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
diff --git a/saleor/graphql/checkout/tests/test_checkout_lines.py b/saleor/graphql/checkout/tests/test_checkout_lines.py
new file mode 100644
index 0000000000..0409b3a70b
--- /dev/null
+++ b/saleor/graphql/checkout/tests/test_checkout_lines.py
@@ -0,0 +1,596 @@
+import datetime
+import uuid
+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 ....product.models import ProductChannelListing
+from ...tests.utils import get_graphql_content
+from ..mutations import update_checkout_shipping_method_if_invalid
+
+MUTATION_CHECKOUT_LINES_ADD = """
+ mutation checkoutLinesAdd(
+ $token: UUID, $lines: [CheckoutLineInput!]!) {
+ checkoutLinesAdd(token: $token, lines: $lines) {
+ checkout {
+ token
+ quantity
+ lines {
+ quantity
+ variant {
+ id
+ }
+ }
+ }
+ errors {
+ field
+ code
+ message
+ variants
+ }
+ }
+ }"""
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_add(
+ mocked_update_shipping_method, user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ lines = fetch_checkout_lines(checkout)
+ assert calculate_checkout_quantity(lines) == 3
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines = fetch_checkout_lines(checkout)
+ line = checkout.lines.latest("pk")
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 4
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_lines_add_with_unavailable_variant(
+ user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ variant.channel_listings.filter(channel=checkout_with_item.channel).update(
+ price_amount=None
+ )
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ assert line.quantity == 3
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ errors = content["data"]["checkoutLinesAdd"]["errors"]
+ assert errors[0]["code"] == CheckoutErrorCode.UNAVAILABLE_VARIANT_IN_CHANNEL.name
+ assert errors[0]["field"] == "lines"
+ assert errors[0]["variants"] == [variant_id]
+
+
+def test_checkout_lines_add_with_zero_quantity(
+ user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 0}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ errors = content["data"]["checkoutLinesAdd"]["errors"]
+ assert errors[0]["code"] == CheckoutErrorCode.ZERO_QUANTITY.name
+ assert errors[0]["field"] == "quantity"
+
+
+def test_checkout_lines_add_no_channel_shipping_zones(
+ user_api_client, checkout_with_item, stock
+):
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ checkout.channel.shipping_zones.clear()
+ line = checkout.lines.first()
+ assert line.quantity == 3
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesAdd"]
+ errors = data["errors"]
+ assert len(errors) == 1
+ assert errors[0]["code"] == CheckoutErrorCode.INSUFFICIENT_STOCK.name
+ assert errors[0]["field"] == "quantity"
+
+
+def test_checkout_lines_add_with_unpublished_product(
+ user_api_client, checkout_with_item, stock, channel_USD
+):
+ variant = stock.product_variant
+ product = variant.product
+ ProductChannelListing.objects.filter(product=product, channel=channel_USD).update(
+ is_published=False
+ )
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout_with_item.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout_with_item.channel.slug,
+ }
+
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+
+ content = get_graphql_content(response)
+ error = content["data"]["checkoutLinesAdd"]["errors"][0]
+ assert error["code"] == CheckoutErrorCode.PRODUCT_NOT_PUBLISHED.name
+
+
+def test_checkout_lines_add_with_unavailable_for_purchase_product(
+ user_api_client, checkout_with_item, stock
+):
+ # given
+ variant = stock.product_variant
+ product = stock.product_variant.product
+ product.channel_listings.update(available_for_purchase=None)
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout_with_item.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+
+ # when
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+
+ # then
+ content = get_graphql_content(response)
+ error = content["data"]["checkoutLinesAdd"]["errors"][0]
+ assert error["field"] == "lines"
+ assert error["code"] == CheckoutErrorCode.PRODUCT_UNAVAILABLE_FOR_PURCHASE.name
+ assert error["variants"] == [variant_id]
+
+
+def test_checkout_lines_add_with_available_for_purchase_from_tomorrow_product(
+ user_api_client, checkout_with_item, stock
+):
+ # given
+ variant = stock.product_variant
+ product = stock.product_variant.product
+ product.channel_listings.update(
+ available_for_purchase=datetime.date.today() + datetime.timedelta(days=1)
+ )
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout_with_item.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+
+ # when
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+
+ # then
+ content = get_graphql_content(response)
+ error = content["data"]["checkoutLinesAdd"]["errors"][0]
+ assert error["field"] == "lines"
+ assert error["code"] == CheckoutErrorCode.PRODUCT_UNAVAILABLE_FOR_PURCHASE.name
+ assert error["variants"] == [variant_id]
+
+
+def test_checkout_lines_add_too_many(user_api_client, checkout_with_item, stock):
+ variant = stock.product_variant
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout_with_item.token,
+ "lines": [{"variantId": variant_id, "quantity": 51}],
+ "channelSlug": checkout_with_item.channel.slug,
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)["data"]["checkoutLinesAdd"]
+
+ assert content["errors"]
+ assert content["errors"] == [
+ {
+ "field": "quantity",
+ "message": "Cannot add more than 50 times this item.",
+ "code": "QUANTITY_GREATER_THAN_LIMIT",
+ "variants": None,
+ }
+ ]
+
+
+def test_checkout_lines_add_empty_checkout(user_api_client, checkout, stock):
+ variant = stock.product_variant
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ line = checkout.lines.first()
+ assert line.variant == variant
+ assert line.quantity == 1
+
+
+def test_checkout_lines_add_variant_without_inventory_tracking(
+ user_api_client, checkout, variant_without_inventory_tracking
+):
+ variant = variant_without_inventory_tracking
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ line = checkout.lines.first()
+ assert line.variant == variant
+ assert line.quantity == 1
+
+
+def test_checkout_lines_add_check_lines_quantity(user_api_client, checkout, stock):
+ variant = stock.product_variant
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 16}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert data["errors"][0]["message"] == (
+ "Could not add items SKU_A. Only 15 remaining in stock."
+ )
+ assert data["errors"][0]["field"] == "quantity"
+
+
+def test_checkout_lines_invalid_variant_id(user_api_client, checkout, stock):
+ variant = stock.product_variant
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ invalid_variant_id = "InvalidId"
+
+ variables = {
+ "token": checkout.token,
+ "lines": [
+ {"variantId": variant_id, "quantity": 1},
+ {"variantId": invalid_variant_id, "quantity": 3},
+ ],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ error_msg = "Could not resolve to a node with the global id list of '%s'."
+ assert data["errors"][0]["message"] == error_msg % [invalid_variant_id]
+ assert data["errors"][0]["field"] == "variantId"
+
+
+MUTATION_CHECKOUT_LINES_UPDATE = """
+ mutation checkoutLinesUpdate(
+ $token: UUID, $lines: [CheckoutLineInput!]!) {
+ checkoutLinesUpdate(token: $token, lines: $lines) {
+ checkout {
+ token
+ quantity
+ lines {
+ quantity
+ variant {
+ id
+ }
+ }
+ }
+ errors {
+ field
+ code
+ message
+ variants
+ }
+ }
+ }
+ """
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_update(
+ mocked_update_shipping_method, user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ lines = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ assert calculate_checkout_quantity(lines) == 3
+ line = checkout.lines.first()
+ variant = line.variant
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout_with_item.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 1
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_lines_update_with_unavailable_variant(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ variant = line.variant
+ variant.channel_listings.filter(channel=checkout_with_item.channel).update(
+ price_amount=None
+ )
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ errors = content["data"]["checkoutLinesUpdate"]["errors"]
+ assert errors[0]["code"] == CheckoutErrorCode.UNAVAILABLE_VARIANT_IN_CHANNEL.name
+ assert errors[0]["field"] == "lines"
+ assert errors[0]["variants"] == [variant_id]
+
+
+def test_checkout_lines_update_channel_without_shipping_zones(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ checkout.channel.shipping_zones.clear()
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ variant = line.variant
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesUpdate"]
+ errors = data["errors"]
+ assert len(errors) == 1
+ assert errors[0]["code"] == CheckoutErrorCode.INSUFFICIENT_STOCK.name
+ assert errors[0]["field"] == "quantity"
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_line_delete_by_zero_quantity(
+ mocked_update_shipping_method, user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ variant = line.variant
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 0}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.lines.count() == 0
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
+def test_checkout_lines_update_with_unpublished_product(
+ user_api_client, checkout_with_item, channel_USD
+):
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ variant = line.variant
+ product = variant.product
+ ProductChannelListing.objects.filter(product=product, channel=channel_USD).update(
+ is_published=False
+ )
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+
+ content = get_graphql_content(response)
+ error = content["data"]["checkoutLinesUpdate"]["errors"][0]
+ assert error["code"] == CheckoutErrorCode.PRODUCT_NOT_PUBLISHED.name
+
+
+def test_checkout_lines_update_invalid_checkout_id(user_api_client):
+ variables = {"token": uuid.uuid4(), "lines": []}
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesUpdate"]
+ assert data["errors"][0]["field"] == "token"
+
+
+def test_checkout_lines_update_check_lines_quantity(
+ user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ line = checkout.lines.first()
+ variant = line.variant
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 11}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert data["errors"][0]["message"] == (
+ "Could not add items 123. Only 10 remaining in stock."
+ )
+ assert data["errors"][0]["field"] == "quantity"
+
+
+def test_checkout_lines_update_with_chosen_shipping(
+ user_api_client, checkout, stock, address, shipping_method
+):
+ checkout.shipping_address = address
+ checkout.shipping_method = shipping_method
+ checkout.save()
+
+ variant = stock.product_variant
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines = fetch_checkout_lines(checkout)
+ assert calculate_checkout_quantity(lines) == 1
+
+
+MUTATION_CHECKOUT_LINES_DELETE = """
+ mutation checkoutLineDelete($token: UUID, $lineId: ID!) {
+ checkoutLineDelete(token: $token, lineId: $lineId) {
+ checkout {
+ token
+ lines {
+ quantity
+ variant {
+ id
+ }
+ }
+ }
+ errors {
+ field
+ message
+ }
+ }
+ }
+"""
+
+
+ "saleor.graphql.checkout.mutations.update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_line_delete(
+ 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()
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
diff --git a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
index cb61103315..2702026431 100644
--- a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
+++ b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
@@ -1,3 +1,4 @@
+import uuid
from datetime import date, timedelta
from decimal import Decimal
@@ -12,10 +13,8 @@ from ....core.taxes import TaxedMoney
from ....discount import DiscountInfo, VoucherType
from ....plugins.manager import get_plugins_manager
from ...tests.utils import get_graphql_content
-from .test_checkout import (
- MUTATION_CHECKOUT_LINES_DELETE,
- MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,
-)
+from .test_checkout import MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE
+from .test_checkout_lines import MUTATION_CHECKOUT_LINES_DELETE
def test_checkout_lines_delete_with_not_applicable_voucher(
@@ -40,9 +39,8 @@ def test_checkout_lines_delete_with_not_applicable_voucher(
line = checkout_with_item.lines.first()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- variables = {"checkoutId": checkout_id, "lineId": line_id}
+ variables = {"token": checkout_with_item.token, "lineId": line_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
content = get_graphql_content(response)
@@ -78,9 +76,8 @@ def test_checkout_shipping_address_update_with_not_applicable_voucher(
add_voucher_to_checkout(manager, checkout_info, lines, voucher)
assert checkout_with_item.voucher_code == voucher.code
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
new_address = graphql_address_data
- variables = {"checkoutId": checkout_id, "shippingAddress": new_address}
+ variables = {"token": checkout_with_item.token, "shippingAddress": new_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
)
@@ -225,16 +222,17 @@ def test_checkout_get_gift_card_code_without_gift_card(user_api_client, checkout
MUTATION_CHECKOUT_ADD_PROMO_CODE = """
- mutation($checkoutId: ID!, $promoCode: String!) {
+ mutation($token: UUID, $promoCode: String!) {
checkoutAddPromoCode(
- checkoutId: $checkoutId, promoCode: $promoCode) {
+ token: $token, promoCode: $promoCode) {
errors {
field
message
code
}
checkout {
- id,
+ id
+ token
voucherCode
giftCards {
id
@@ -257,13 +255,12 @@ def _mutate_checkout_add_promo_code(client, variables):
return content["data"]["checkoutAddPromoCode"]
-def test_checkout_add_voucher_code(api_client, checkout_with_item, voucher):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+def test_checkout_add_voucher_code_by_token(api_client, checkout_with_item, voucher):
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert data["checkout"]["voucherCode"] == voucher.code
@@ -285,12 +282,11 @@ def test_checkout_add_voucher_code_with_display_gross_prices(
),
)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert data["checkout"]["voucherCode"] == voucher.code
@@ -312,8 +308,7 @@ def test_checkout_add_voucher_code_without_display_gross_prices(
),
)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"][0]["code"] == CheckoutErrorCode.VOUCHER_NOT_APPLICABLE.name
@@ -338,8 +333,10 @@ def test_checkout_add_voucher_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher_percentage.code}
+ variables = {
+ "token": checkout_with_item.token,
+ "promoCode": voucher_percentage.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
checkout_with_item.refresh_from_db()
@@ -374,8 +371,7 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(
)
assert subtotal > subtotal_discounted
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
checkout.refresh_from_db()
@@ -415,8 +411,7 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
checkout.refresh_from_db()
@@ -454,8 +449,7 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
checkout.refresh_from_db()
@@ -493,8 +487,7 @@ def test_checkout_add_category_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
- variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
checkout.refresh_from_db()
@@ -506,9 +499,8 @@ def test_checkout_add_category_code_checkout_with_sale(
def test_checkout_add_voucher_code_not_applicable_voucher(
api_client, checkout_with_item, voucher_with_high_min_spent_amount
):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_item.token,
"promoCode": voucher_with_high_min_spent_amount.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -520,9 +512,8 @@ def test_checkout_add_voucher_code_not_applicable_voucher(
def test_checkout_add_voucher_code_not_assigned_to_channel(
api_client, checkout_with_item, voucher_without_channel
):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_item.token,
"promoCode": voucher_without_channel.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -532,13 +523,12 @@ def test_checkout_add_voucher_code_not_assigned_to_channel(
def test_checkout_add_gift_card_code(api_client, checkout_with_item, gift_card):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}
+ variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert data["checkout"]["giftCards"][0]["id"] == gift_card_id
assert data["checkout"]["giftCards"][0]["displayCode"] == gift_card.display_code
@@ -547,16 +537,15 @@ def test_checkout_add_many_gift_card_code(
api_client, checkout_with_gift_card, gift_card_created_by_staff
):
assert checkout_with_gift_card.gift_cards.count() > 0
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card_created_by_staff.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_gift_card.token,
"promoCode": gift_card_created_by_staff.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_gift_card.token)
gift_card_data = data["checkout"]["giftCards"][-1]
assert gift_card_data["id"] == gift_card_id
assert gift_card_data["displayCode"] == gift_card_created_by_staff.display_code
@@ -574,12 +563,11 @@ def test_checkout_get_total_with_gift_card(api_client, checkout_with_item, gift_
)
total_with_gift_card = taxed_total.gross.amount - gift_card.current_balance_amount
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}
+ variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert not data["checkout"]["giftCards"] == []
assert data["checkout"]["totalPrice"]["gross"]["amount"] == total_with_gift_card
@@ -603,27 +591,25 @@ def test_checkout_get_total_with_many_gift_card(
)
assert checkout_with_gift_card.gift_cards.count() > 0
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_gift_card.token,
"promoCode": gift_card_created_by_staff.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_gift_card.token)
assert data["checkout"]["totalPrice"]["gross"]["amount"] == total_with_gift_card
def test_checkout_get_total_with_more_money_on_gift_card(
api_client, checkout_with_item, gift_card_used
):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card_used.code}
+ variables = {"token": checkout_with_item.token, "promoCode": gift_card_used.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
assert not data["checkout"]["giftCards"] == []
assert data["checkout"]["totalPrice"]["gross"]["amount"] == 0
@@ -632,12 +618,11 @@ def test_checkout_add_same_gift_card_code(api_client, checkout_with_gift_card):
gift_card = checkout_with_gift_card.gift_cards.first()
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)
gift_card_count = checkout_with_gift_card.gift_cards.count()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}
+ variables = {"token": checkout_with_gift_card.token, "promoCode": gift_card.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_gift_card.token)
assert data["checkout"]["giftCards"][0]["id"] == gift_card_id
assert data["checkout"]["giftCards"][0]["displayCode"] == gift_card.display_code
assert len(data["checkout"]["giftCards"]) == gift_card_count
@@ -649,8 +634,7 @@ def test_checkout_add_gift_card_code_in_active_gift_card(
gift_card.is_active = False
gift_card.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}
+ variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -663,8 +647,7 @@ def test_checkout_add_gift_card_code_in_expired_gift_card(
gift_card.end_date = date.today() - timedelta(days=1)
gift_card.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}
+ variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -672,16 +655,15 @@ def test_checkout_add_gift_card_code_in_expired_gift_card(
def test_checkout_add_promo_code_invalid_checkout(api_client, voucher):
- variables = {"checkoutId": "unexisting_checkout", "promoCode": voucher.code}
+ variables = {"token": uuid.uuid4(), "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
- assert data["errors"][0]["field"] == "checkoutId"
+ assert data["errors"][0]["field"] == "token"
def test_checkout_add_promo_code_invalid_promo_code(api_client, checkout_with_item):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": "unexisting_code"}
+ variables = {"token": checkout_with_item.token, "promoCode": "unexisting_code"}
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -689,15 +671,15 @@ def test_checkout_add_promo_code_invalid_promo_code(api_client, checkout_with_it
MUTATION_CHECKOUT_REMOVE_PROMO_CODE = """
- mutation($checkoutId: ID!, $promoCode: String!) {
+ mutation($token: UUID, $promoCode: String!) {
checkoutRemovePromoCode(
- checkoutId: $checkoutId, promoCode: $promoCode) {
+ token: $token, promoCode: $promoCode) {
errors {
field
message
}
checkout {
- id,
+ token,
voucherCode
giftCards {
id
@@ -718,9 +700,8 @@ def _mutate_checkout_remove_promo_code(client, variables):
def test_checkout_remove_voucher_code(api_client, checkout_with_voucher):
assert checkout_with_voucher.voucher_code is not None
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_voucher.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_voucher.token,
"promoCode": checkout_with_voucher.voucher_code,
}
@@ -728,7 +709,7 @@ def test_checkout_remove_voucher_code(api_client, checkout_with_voucher):
checkout_with_voucher.refresh_from_db()
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_voucher.token)
assert data["checkout"]["voucherCode"] is None
assert checkout_with_voucher.voucher_code is None
@@ -740,9 +721,8 @@ def test_checkout_remove_voucher_code_with_inactive_channel(
channel.is_active = False
channel.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_voucher.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_voucher.token,
"promoCode": checkout_with_voucher.voucher_code,
}
@@ -750,22 +730,21 @@ def test_checkout_remove_voucher_code_with_inactive_channel(
checkout_with_voucher.refresh_from_db()
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_voucher.token)
assert data["checkout"]["voucherCode"] == checkout_with_voucher.voucher_code
def test_checkout_remove_gift_card_code(api_client, checkout_with_gift_card):
assert checkout_with_gift_card.gift_cards.count() == 1
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout_with_gift_card.token,
"promoCode": checkout_with_gift_card.gift_cards.first().code,
}
data = _mutate_checkout_remove_promo_code(api_client, variables)
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_gift_card.token)
assert data["checkout"]["giftCards"] == []
assert not checkout_with_gift_card.gift_cards.all().exists()
@@ -778,31 +757,32 @@ def test_checkout_remove_one_of_gift_cards(
gift_card_first = checkout_with_gift_card.gift_cards.first()
gift_card_last = checkout_with_gift_card.gift_cards.last()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)
- variables = {"checkoutId": checkout_id, "promoCode": gift_card_first.code}
+ variables = {
+ "token": checkout_with_gift_card.token,
+ "promoCode": gift_card_first.code,
+ }
data = _mutate_checkout_remove_promo_code(api_client, variables)
checkout_gift_cards = checkout_with_gift_card.gift_cards
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_gift_card.token)
assert checkout_gift_cards.filter(code=gift_card_last.code).exists()
assert not checkout_gift_cards.filter(code=gift_card_first.code).exists()
def test_checkout_remove_promo_code_invalid_promo_code(api_client, checkout_with_item):
- checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
- variables = {"checkoutId": checkout_id, "promoCode": "unexisting_code"}
+ variables = {"token": checkout_with_item.token, "promoCode": "unexisting_code"}
data = _mutate_checkout_remove_promo_code(api_client, variables)
assert not data["errors"]
- assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["token"] == str(checkout_with_item.token)
def test_checkout_remove_promo_code_invalid_checkout(api_client, voucher):
- variables = {"checkoutId": "unexisting_checkout", "promoCode": voucher.code}
+ variables = {"token": uuid.uuid4(), "promoCode": voucher.code}
data = _mutate_checkout_remove_promo_code(api_client, variables)
assert data["errors"]
- assert data["errors"][0]["field"] == "checkoutId"
+ assert data["errors"][0]["field"] == "token"
diff --git a/saleor/graphql/core/validators.py b/saleor/graphql/core/validators.py
index e101c4766d..1ff013657a 100644
--- a/saleor/graphql/core/validators.py
+++ b/saleor/graphql/core/validators.py
@@ -11,6 +11,13 @@ if TYPE_CHECKING:
from decimal import Decimal
+def validate_one_of_args_is_in_mutation(error_class, *args):
+ try:
+ validate_one_of_args_is_in_query(*args)
+ except GraphQLError as e:
+ raise ValidationError(str(e), code=error_class.GRAPHQL_ERROR)
+
+
def validate_one_of_args_is_in_query(*args):
# split args into a list with 2-element tuples:
# [(arg1_name, arg1_value), (arg2_name, arg2_value), ...]
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.py
index e40452512e..d69b4c933a 100644
--- a/saleor/graphql/payment/mutations.py
+++ b/saleor/graphql/payment/mutations.py
@@ -13,10 +13,12 @@ from ...payment import PaymentError, gateway
from ...payment.error_codes import PaymentErrorCode
from ...payment.utils import create_payment, is_currency_supported
from ..account.i18n import I18nMixin
+from ..checkout.mutations import get_checkout_by_token
from ..checkout.types import Checkout
from ..core.mutations import BaseMutation
-from ..core.scalars import PositiveDecimal
+from ..core.scalars import UUID, PositiveDecimal
from ..core.types import common as common_types
+from ..core.validators import validate_one_of_args_is_in_mutation
from .types import Payment, PaymentInitialized
@@ -56,7 +58,14 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
payment = graphene.Field(Payment, description="A newly created payment.")
class Arguments:
- checkout_id = graphene.ID(description="Checkout ID.", required=True)
+ checkout_id = graphene.ID(
+ description=(
+ "Checkout ID."
+ "DEPRECATED: Will be removed in Saleor 4.0. Use token instead."
+ ),
+ required=False,
+ )
+ token = UUID(description="Checkout token.", required=False)
input = PaymentInput(
description="Data required to create a new payment.", required=True
)
@@ -124,10 +133,20 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
)
@classmethod
- def perform_mutation(cls, _root, info, checkout_id, **data):
- checkout = cls.get_node_or_error(
- info, checkout_id, only_type=Checkout, field="checkout_id"
+ def perform_mutation(cls, _root, info, checkout_id=None, token=None, **data):
+ # DEPRECATED
+ validate_one_of_args_is_in_mutation(
+ PaymentErrorCode, "checkout_id", checkout_id, "token", token
)
+
+ if token:
+ checkout = get_checkout_by_token(token)
+ # DEPRECATED
+ else:
+ checkout = cls.get_node_or_error(
+ info, checkout_id or token, only_type=Checkout, field="checkout_id"
+ )
+
data = data["input"]
gateway = data["gateway"]
diff --git a/saleor/graphql/payment/tests/deprecated/__init__.py b/saleor/graphql/payment/tests/deprecated/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py b/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py
new file mode 100644
index 0000000000..f253d173ce
--- /dev/null
+++ b/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py
@@ -0,0 +1,129 @@
+import graphene
+
+from .....checkout import calculations
+from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
+from .....payment.error_codes import PaymentErrorCode
+from .....payment.models import ChargeStatus, Payment
+from .....plugins.manager import get_plugins_manager
+from ....tests.utils import get_graphql_content
+
+DUMMY_GATEWAY = "mirumee.payments.dummy"
+
+CREATE_PAYMENT_MUTATION = """
+ mutation CheckoutPaymentCreate(
+ $checkoutId: ID, $token: UUID, $input: PaymentInput!
+ ) {
+ checkoutPaymentCreate(checkoutId: $checkoutId, token: $token, input: $input) {
+ payment {
+ transactions {
+ kind,
+ token
+ }
+ chargeStatus
+ }
+ errors {
+ code
+ field
+ }
+ }
+ }
+ """
+
+
+def test_checkout_add_payment_by_checkout_id(
+ user_api_client, checkout_without_shipping_required, address
+):
+ checkout = checkout_without_shipping_required
+ checkout.billing_address = address
+ checkout.save()
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ total = calculations.checkout_total(
+ manager=manager, checkout_info=checkout_info, lines=lines, address=address
+ )
+ variables = {
+ "checkoutId": checkout_id,
+ "input": {
+ "gateway": DUMMY_GATEWAY,
+ "token": "sample-token",
+ "amount": total.gross.amount,
+ },
+ }
+ response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutPaymentCreate"]
+ assert not data["errors"]
+ transactions = data["payment"]["transactions"]
+ assert not transactions
+ payment = Payment.objects.get()
+ assert payment.checkout == checkout
+ assert payment.is_active
+ assert payment.token == "sample-token"
+ assert payment.total == total.gross.amount
+ assert payment.currency == total.gross.currency
+ assert payment.charge_status == ChargeStatus.NOT_CHARGED
+ assert payment.billing_address_1 == checkout.billing_address.street_address_1
+ assert payment.billing_first_name == checkout.billing_address.first_name
+ assert payment.billing_last_name == checkout.billing_address.last_name
+
+
+def test_checkout_add_payment_neither_token_and_id_given(
+ user_api_client, checkout_without_shipping_required, address
+):
+ checkout = checkout_without_shipping_required
+ checkout.billing_address = address
+ checkout.save()
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ total = calculations.checkout_total(
+ manager=manager, checkout_info=checkout_info, lines=lines, address=address
+ )
+ variables = {
+ "input": {
+ "gateway": DUMMY_GATEWAY,
+ "token": "sample-token",
+ "amount": total.gross.amount,
+ },
+ }
+ response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutPaymentCreate"]
+ assert len(data["errors"]) == 1
+ assert not data["payment"]
+ assert data["errors"][0]["code"] == PaymentErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_add_payment_both_token_and_id_given(
+ user_api_client, checkout_without_shipping_required, address
+):
+ checkout = checkout_without_shipping_required
+ checkout.billing_address = address
+ checkout.save()
+
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ total = calculations.checkout_total(
+ manager=manager, checkout_info=checkout_info, lines=lines, address=address
+ )
+ variables = {
+ "checkoutId": checkout_id,
+ "token": checkout.token,
+ "input": {
+ "gateway": DUMMY_GATEWAY,
+ "token": "sample-token",
+ "amount": total.gross.amount,
+ },
+ }
+ response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutPaymentCreate"]
+ assert len(data["errors"]) == 1
+ assert not data["payment"]
+ assert data["errors"][0]["code"] == PaymentErrorCode.GRAPHQL_ERROR.name
diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.py
index 2d0c8a5cab..b4a820a964 100644
--- a/saleor/graphql/payment/tests/test_payment.py
+++ b/saleor/graphql/payment/tests/test_payment.py
@@ -91,8 +91,8 @@ def test_payment_void_gateway_error(
CREATE_PAYMENT_MUTATION = """
- mutation CheckoutPaymentCreate($checkoutId: ID!, $input: PaymentInput!) {
- checkoutPaymentCreate(checkoutId: $checkoutId, input: $input) {
+ mutation CheckoutPaymentCreate($token: UUID, $input: PaymentInput!) {
+ checkoutPaymentCreate(token: $token, input: $input) {
payment {
transactions {
kind,
@@ -116,7 +116,6 @@ def test_checkout_add_payment_without_shipping_method_and_not_shipping_required(
checkout.billing_address = address
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -124,7 +123,7 @@ def test_checkout_add_payment_without_shipping_method_and_not_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -157,7 +156,6 @@ def test_checkout_add_payment_without_shipping_method_with_shipping_required(
checkout.billing_address = address
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -165,7 +163,7 @@ def test_checkout_add_payment_without_shipping_method_with_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -189,7 +187,6 @@ def test_checkout_add_payment_with_shipping_method_and_shipping_required(
checkout.shipping_method = other_shipping_method
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -197,7 +194,7 @@ def test_checkout_add_payment_with_shipping_method_and_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -232,7 +229,6 @@ def test_checkout_add_payment(
checkout.user = customer_user
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -241,7 +237,7 @@ def test_checkout_add_payment(
)
return_url = "https://www.example.com"
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -277,7 +273,6 @@ def test_checkout_add_payment_default_amount(
checkout.billing_address = address
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -286,7 +281,7 @@ def test_checkout_add_payment_default_amount(
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {"gateway": DUMMY_GATEWAY, "token": "sample-token"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -310,7 +305,6 @@ def test_checkout_add_payment_bad_amount(
checkout = checkout_without_shipping_required
checkout.billing_address = address
checkout.save()
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
@@ -320,7 +314,7 @@ def test_checkout_add_payment_bad_amount(
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -342,10 +336,9 @@ def test_checkout_add_payment_not_supported_gateways(
checkout.billing_address = address
checkout.currency = "EUR"
checkout.save(update_fields=["billing_address", "currency"])
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {"gateway": DUMMY_GATEWAY, "token": "sample-token", "amount": "10.0"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -359,7 +352,6 @@ def test_use_checkout_billing_address_as_payment_billing(
user_api_client, checkout_without_shipping_required, address
):
checkout = checkout_without_shipping_required
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
manager = get_plugins_manager()
lines = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, [], manager)
@@ -367,7 +359,7 @@ def test_use_checkout_billing_address_as_payment_billing(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -412,9 +404,8 @@ def test_create_payment_for_checkout_with_active_payments(
total = calculations.checkout_total(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
variables = {
- "checkoutId": checkout_id,
+ "token": checkout.token,
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 7af7436549..c23d8b6fa1 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2877,21 +2877,21 @@ type Mutation {
voucherChannelListingUpdate(id: ID!, input: VoucherChannelListingInput!): VoucherChannelListingUpdate
exportProducts(input: ExportProductsInput!): ExportProducts
fileUpload(file: Upload!): FileUpload
- checkoutAddPromoCode(checkoutId: ID!, promoCode: String!): CheckoutAddPromoCode
- checkoutBillingAddressUpdate(billingAddress: AddressInput!, checkoutId: ID!): CheckoutBillingAddressUpdate
- checkoutComplete(checkoutId: ID!, paymentData: JSONString, redirectUrl: String, storeSource: Boolean = false): CheckoutComplete
+ checkoutAddPromoCode(checkoutId: ID, promoCode: String!, token: UUID): CheckoutAddPromoCode
+ checkoutBillingAddressUpdate(billingAddress: AddressInput!, checkoutId: ID, token: UUID): CheckoutBillingAddressUpdate
+ checkoutComplete(checkoutId: ID, paymentData: JSONString, redirectUrl: String, storeSource: Boolean = false, token: UUID): CheckoutComplete
checkoutCreate(input: CheckoutCreateInput!): CheckoutCreate
- checkoutCustomerAttach(checkoutId: ID!): CheckoutCustomerAttach
- checkoutCustomerDetach(checkoutId: ID!): CheckoutCustomerDetach
- checkoutEmailUpdate(checkoutId: ID, email: String!): CheckoutEmailUpdate
- checkoutLineDelete(checkoutId: ID!, lineId: ID): CheckoutLineDelete
- checkoutLinesAdd(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesAdd
- checkoutLinesUpdate(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesUpdate
- checkoutRemovePromoCode(checkoutId: ID!, promoCode: String!): CheckoutRemovePromoCode
- checkoutPaymentCreate(checkoutId: ID!, input: PaymentInput!): CheckoutPaymentCreate
- checkoutShippingAddressUpdate(checkoutId: ID!, shippingAddress: AddressInput!): CheckoutShippingAddressUpdate
- checkoutShippingMethodUpdate(checkoutId: ID, shippingMethodId: ID!): CheckoutShippingMethodUpdate
- checkoutLanguageCodeUpdate(checkoutId: ID!, languageCode: LanguageCodeEnum!): CheckoutLanguageCodeUpdate
+ checkoutCustomerAttach(checkoutId: ID, token: UUID): CheckoutCustomerAttach
+ checkoutCustomerDetach(checkoutId: ID, token: UUID): CheckoutCustomerDetach
+ checkoutEmailUpdate(checkoutId: ID, email: String!, token: UUID): CheckoutEmailUpdate
+ checkoutLineDelete(checkoutId: ID, lineId: ID, token: UUID): CheckoutLineDelete
+ checkoutLinesAdd(checkoutId: ID, lines: [CheckoutLineInput]!, token: UUID): CheckoutLinesAdd
+ checkoutLinesUpdate(checkoutId: ID, lines: [CheckoutLineInput]!, token: UUID): CheckoutLinesUpdate
+ checkoutRemovePromoCode(checkoutId: ID, promoCode: String!, token: UUID): CheckoutRemovePromoCode
+ checkoutPaymentCreate(checkoutId: ID, input: PaymentInput!, token: UUID): CheckoutPaymentCreate
+ checkoutShippingAddressUpdate(checkoutId: ID, shippingAddress: AddressInput!, token: UUID): CheckoutShippingAddressUpdate
+ checkoutShippingMethodUpdate(checkoutId: ID, shippingMethodId: ID!, token: UUID): CheckoutShippingMethodUpdate
+ checkoutLanguageCodeUpdate(checkoutId: ID, languageCode: LanguageCodeEnum!, token: UUID): CheckoutLanguageCodeUpdate
channelCreate(input: ChannelCreateInput!): ChannelCreate
channelUpdate(id: ID!, input: ChannelUpdateInput!): ChannelUpdate
channelDelete(id: ID!, input: ChannelDeleteInput): ChannelDelete