Skip to content

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

Ensure that only shipping method available in order channel can be assigned to the order

IKarbowiak9e29d301a7a3
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index 7660590e5f..2574ff1bbc 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -3687,8 +3687,9 @@ ORDER_UPDATE_SHIPPING_QUERY = """
mutation orderUpdateShipping($order: ID!, $shippingMethod: ID) {
orderUpdateShipping(
order: $order, input: {shippingMethod: $shippingMethod}) {
- errors {
+ orderErrors {
field
+ code
message
}
order {
@@ -3807,8 +3808,8 @@ def test_order_update_shipping_shipping_required(
)
content = get_graphql_content(response)
data = content["data"]["orderUpdateShipping"]
- assert data["errors"][0]["field"] == "shippingMethod"
- assert data["errors"][0]["message"] == (
+ assert data["orderErrors"][0]["field"] == "shippingMethod"
+ assert data["orderErrors"][0]["message"] == (
"Shipping method is required for this order."
)
@@ -3832,8 +3833,8 @@ def test_order_update_shipping_no_shipping_address(
)
content = get_graphql_content(response)
data = content["data"]["orderUpdateShipping"]
- assert data["errors"][0]["field"] == "order"
- assert data["errors"][0]["message"] == (
+ assert data["orderErrors"][0]["field"] == "order"
+ assert data["orderErrors"][0]["message"] == (
"Cannot choose a shipping method for an order without" " the shipping address."
)
@@ -3859,12 +3860,36 @@ def test_order_update_shipping_incorrect_shipping_method(
)
content = get_graphql_content(response)
data = content["data"]["orderUpdateShipping"]
- assert data["errors"][0]["field"] == "shippingMethod"
- assert data["errors"][0]["message"] == (
+ assert data["orderErrors"][0]["field"] == "shippingMethod"
+ assert data["orderErrors"][0]["message"] == (
"Shipping method cannot be used with this order."
)
+def test_order_update_shipping_shipping_zone_without_channels(
+ staff_api_client,
+ permission_manage_orders,
+ order_with_lines,
+ shipping_method,
+ staff_user,
+):
+ order = order_with_lines
+ order.channel.shipping_zones.clear()
+ query = ORDER_UPDATE_SHIPPING_QUERY
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
+ variables = {"order": order_id, "shippingMethod": method_id}
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_orders]
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["orderUpdateShipping"]
+ errors = data["orderErrors"]
+ assert len(errors) == 1
+ assert errors[0]["field"] == "shippingMethod"
+ assert errors[0]["code"] == OrderErrorCode.SHIPPING_METHOD_NOT_APPLICABLE.name
+
+
def test_order_update_shipping_excluded_shipping_method_postal_code(
staff_api_client,
permission_manage_orders,
@@ -3893,8 +3918,8 @@ def test_order_update_shipping_excluded_shipping_method_postal_code(
)
content = get_graphql_content(response)
data = content["data"]["orderUpdateShipping"]
- assert data["errors"][0]["field"] == "shippingMethod"
- assert data["errors"][0]["message"] == (
+ assert data["orderErrors"][0]["field"] == "shippingMethod"
+ assert data["orderErrors"][0]["message"] == (
"Shipping method cannot be used with this order."
)