Skip to content

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

Checkout fixes

Michał Jelonek5d876eae8ee8
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 6484615352..56ca6c48b5 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -91,7 +91,7 @@ class CheckoutCreateInput(graphene.InputObjectType):
'A list of checkout lines, each containing information about '
'an item in the checkout.'), required=True)
email = graphene.String(
- description='The customer\'s email address.', required=True)
+ description='The customer\'s email address.')
shipping_address = AddressInput(
description=(
'The mailling address to where the checkout will be shipped.'))
diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.py
index 1c0e27049b..9bf5aef4f4 100644
--- a/saleor/graphql/order/utils.py
+++ b/saleor/graphql/order/utils.py
@@ -30,9 +30,9 @@ def can_finalize_draft_order(order, errors):
def applicable_shipping_methods(obj, info, price):
if not obj.is_shipping_required():
- return None
+ return []
if not obj.shipping_address:
- return None
+ return []
qs = shipping_models.ShippingMethod.objects
return qs.applicable_shipping_methods(
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index 9c852ca1e1..3581df1c6a 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -205,6 +205,67 @@ def test_checkout_available_payment_gateways(
assert data['availablePaymentGateways'] == checkout_payment_gateways
+def test_checkout_available_shipping_methods(
+ api_client, cart_with_item, address, shipping_zone):
+ cart_with_item.shipping_address = address
+ cart_with_item.save()
+
+ query = """
+ query getCheckout($token: UUID!) {
+ checkout(token: $token) {
+ availableShippingMethods {
+ name
+ }
+ }
+ }
+ """
+ variables = {'token': cart_with_item.token}
+ response = api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content['data']['checkout']
+
+ shipping_method = shipping_zone.shipping_methods.first()
+ assert data['availableShippingMethods'] == [{'name': shipping_method.name}]
+
+
+def test_checkout_no_available_shipping_methods_without_address(
+ api_client, cart_with_item, shipping_zone):
+ query = """
+ query getCheckout($token: UUID!) {
+ checkout(token: $token) {
+ availableShippingMethods {
+ name
+ }
+ }
+ }
+ """
+ variables = {'token': cart_with_item.token}
+ response = api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content['data']['checkout']
+
+ assert data['availableShippingMethods'] == []
+
+
+def test_checkout_no_available_shipping_methods_without_lines(
+ api_client, cart, shipping_zone):
+ query = """
+ query getCheckout($token: UUID!) {
+ checkout(token: $token) {
+ availableShippingMethods {
+ name
+ }
+ }
+ }
+ """
+ variables = {'token': cart.token}
+ response = api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content['data']['checkout']
+
+ assert data['availableShippingMethods'] == []
+
+
MUTATION_CHECKOUT_LINES_ADD = """
mutation checkoutLinesAdd(
$checkoutId: ID!, $lines: [CheckoutLineInput!]!) {