Skip to content

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

Fix rewies remarks

fowczarek445d59019f91
diff --git a/saleor/graphql/order/filters.py b/saleor/graphql/order/filters.py
index e64448bdfd..9b95c582ce 100644
--- a/saleor/graphql/order/filters.py
+++ b/saleor/graphql/order/filters.py
@@ -57,10 +57,10 @@ def filter_created_range(qs, _, value):
def filter_order_search(qs, _, value):
order_fields = [
+ "pk",
"discount_name",
- "token",
+ "translated_discount_name",
"user_email",
- "user__email",
"user__first_name",
"user__last_name",
]
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index eebe9f0c77..e4dd69ce29 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -141,7 +141,7 @@ def filter_by_period(queryset, period, field_name):
def generate_query_argument_description(search_fields):
deprecated_info = (
"DEPRECATED: Will be removed in Saleor 2.10,"
- ' use "filter: {search: {}}" instead.\n'
+ " use `filter: {search: {}}` instead.\n"
)
header = "Supported filter parameters:\n"
supported_list = ""
diff --git a/tests/api/test_graphql.py b/tests/api/test_graphql.py
index 6f33437cdd..db52f240a3 100644
--- a/tests/api/test_graphql.py
+++ b/tests/api/test_graphql.py
@@ -269,7 +269,7 @@ def test_filter_by_query_param(qs):
def test_generate_query_argument_description():
expected = (
"DEPRECATED: Will be removed in Saleor 2.10,"
- ' use "filter: {search: {}}" instead.'
+ " use `filter: {search: {}}` instead."
"\nSupported filter parameters:\n* field_1\n* field_2\n"
)
field_list = ["field_1", "field_2"]
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index c8c2215818..1c52de3c19 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -2117,8 +2117,9 @@ def test_order_query_with_filter_created_(
@pytest.mark.parametrize(
"orders_filter, count",
[
- ({"search": "test_token"}, 1),
- ({"search": "test_discount"}, 1),
+ ({"search": "test_discount"}, 2),
+ ({"search": "test_discount1"}, 1),
+ ({"search": "translated_discount1_name"}, 1),
({"search": "user"}, 2),
({"search": "[email protected]"}, 1),
({"search": "[email protected]"}, 1),
@@ -2138,10 +2139,19 @@ def test_orders_query_with_filter_search(
Order.objects.bulk_create(
[
Order(
- user=customer_user, token="test_token", discount_name="test_discount"
+ user=customer_user,
+ token=str(uuid.uuid4()),
+ discount_name="test_discount1",
+ user_email="[email protected]",
+ translated_discount_name="translated_discount1_name",
),
Order(token=str(uuid.uuid4()), user_email="[email protected]"),
- Order(token=str(uuid.uuid4()), user_email="[email protected]"),
+ Order(
+ token=str(uuid.uuid4()),
+ user_email="[email protected]",
+ discount_name="test_discount2",
+ translated_discount_name="translated_discount2_name",
+ ),
]
)
variables = {"filter": orders_filter}
@@ -2151,11 +2161,22 @@ def test_orders_query_with_filter_search(
assert content["data"]["orders"]["totalCount"] == count
+def test_orders_query_with_filter_search_by_id(
+ orders_query_with_filter, order, staff_api_client, permission_manage_orders
+):
+ variables = {"filter": {"search": order.pk}}
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ response = staff_api_client.post_graphql(orders_query_with_filter, variables)
+ content = get_graphql_content(response)
+ assert content["data"]["orders"]["totalCount"] == 1
+
+
@pytest.mark.parametrize(
"draft_orders_filter, count",
[
- ({"search": "test_token"}, 1),
- ({"search": "test_discount"}, 1),
+ ({"search": "test_discount"}, 2),
+ ({"search": "test_discount1"}, 1),
+ ({"search": "translated_discount1_name"}, 1),
({"search": "user"}, 2),
({"search": "[email protected]"}, 1),
({"search": "[email protected]"}, 1),
@@ -2176,8 +2197,10 @@ def test_draft_orders_query_with_filter_search(
[
Order(
user=customer_user,
- token="test_token",
- discount_name="test_discount",
+ token=str(uuid.uuid4()),
+ discount_name="test_discount1",
+ user_email="[email protected]",
+ translated_discount_name="translated_discount1_name",
status=OrderStatus.DRAFT,
),
Order(
@@ -2188,6 +2211,8 @@ def test_draft_orders_query_with_filter_search(
Order(
token=str(uuid.uuid4()),
user_email="[email protected]",
+ discount_name="test_discount2",
+ translated_discount_name="translated_discount2_name",
status=OrderStatus.DRAFT,
),
]
@@ -2197,3 +2222,16 @@ def test_draft_orders_query_with_filter_search(
response = staff_api_client.post_graphql(draft_orders_query_with_filter, variables)
content = get_graphql_content(response)
assert content["data"]["draftOrders"]["totalCount"] == count
+
+
+def test_draft_orders_query_with_filter_search_by_id(
+ draft_orders_query_with_filter,
+ draft_order,
+ staff_api_client,
+ permission_manage_orders,
+):
+ variables = {"filter": {"search": draft_order.pk}}
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ response = staff_api_client.post_graphql(draft_orders_query_with_filter, variables)
+ content = get_graphql_content(response)
+ assert content["data"]["draftOrders"]["totalCount"] == 1