Skip to content

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

When working on meta identify Order with token

Mira Szewczyk773205381993
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
index ccf52cf3a5..2c7e0954ab 100644
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -23,6 +23,7 @@ from ...core.mutations import (
UpdateMetaBaseMutation,
)
from ...core.scalars import Decimal
+from ...core.types import MetaInput, MetaPath
from ...core.types.common import OrderError
from ...order.mutations.draft_orders import DraftOrderUpdate
from ...order.types import Order, OrderEvent
@@ -426,6 +427,20 @@ class OrderUpdateMeta(UpdateMetaBaseMutation):
model = models.Order
public = True
+ class Arguments:
+ token = graphene.UUID(
+ description="Token of an object to update.", required=True
+ )
+ input = MetaInput(
+ description="Fields required to update new or stored metadata item.",
+ required=True,
+ )
+
+ @classmethod
+ def get_instance(cls, info, **data):
+ token = data["token"]
+ return models.Order.objects.get(token=token)
+
class OrderUpdatePrivateMeta(UpdateMetaBaseMutation):
class Meta:
@@ -442,6 +457,18 @@ class OrderClearMeta(ClearMetaBaseMutation):
permissions = ("order.manage_orders",)
public = True
+ class Arguments:
+ token = graphene.UUID(description="Token of an object to clear.", required=True)
+ input = MetaPath(
+ description="Fields required to update new or stored metadata item.",
+ required=True,
+ )
+
+ @classmethod
+ def get_instance(cls, info, **data):
+ token = data["token"]
+ return models.Order.objects.get(token=token)
+
class OrderClearPrivateMeta(ClearMetaBaseMutation):
class Meta:
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index a845ef15bb..e611c68bb0 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2112,14 +2112,14 @@ type Mutation {
orderCancel(id: ID!, restock: Boolean!): OrderCancel
orderCapture(amount: Decimal!, id: ID!): OrderCapture
orderClearPrivateMeta(id: ID!, input: MetaPath!): OrderClearPrivateMeta
- orderClearMeta(id: ID!, input: MetaPath!): OrderClearMeta
+ orderClearMeta(input: MetaPath!, token: UUID!): OrderClearMeta
orderFulfillmentCancel(id: ID!, input: FulfillmentCancelInput!): FulfillmentCancel
orderFulfillmentCreate(input: FulfillmentCreateInput!, order: ID): FulfillmentCreate
orderFulfillmentUpdateTracking(id: ID!, input: FulfillmentUpdateTrackingInput!): FulfillmentUpdateTracking
orderMarkAsPaid(id: ID!): OrderMarkAsPaid
orderRefund(amount: Decimal!, id: ID!): OrderRefund
orderUpdate(id: ID!, input: OrderUpdateInput!): OrderUpdate
- orderUpdateMeta(id: ID!, input: MetaInput!): OrderUpdateMeta
+ orderUpdateMeta(input: MetaInput!, token: UUID!): OrderUpdateMeta
orderUpdatePrivateMeta(id: ID!, input: MetaInput!): OrderUpdatePrivateMeta
orderUpdateShipping(order: ID!, input: OrderUpdateShippingInput): OrderUpdateShipping
orderVoid(id: ID!): OrderVoid
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 0bc14f249e..276df201a1 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -2248,33 +2248,47 @@ def test_draft_orders_query_with_filter_search_by_id(
assert content["data"]["draftOrders"]["totalCount"] == 1
-def update_meta(mutation_name):
+def update_order_meta():
return """
- mutation %s($id: ID!, $input: MetaInput!) {
- %s(id: $id, input: $input){
+ mutation orderUpdateMeta($token: UUID!, $input: MetaInput!) {
+ orderUpdateMeta(token: $token, input: $input){
errors {
message
}
}
}
- """ % (
- mutation_name,
- mutation_name,
- )
+ """
@pytest.fixture
-def update_order_meta():
- return update_meta("orderUpdateMeta")
+def update_order_private_meta():
+ return """
+ mutation orderUpdatePrivateMeta($id: ID!, $input: MetaInput!) {
+ orderUpdatePrivateMeta(id: $id, input: $input){
+ errors {
+ message
+ }
+ }
+ }
+ """
@pytest.fixture
-def update_order_private_meta():
- return update_meta("orderUpdatePrivateMeta")
+def order_meta_update_variables(order):
+ return {
+ "token": order.token,
+ "input": {
+ "namespace": "test",
+ "clientName": "client1",
+ "key": "foo",
+ "value": "bar",
+ },
+ }
@pytest.fixture
-def order_meta_update_variables(order):
+def order_private_meta_update_variables(order):
order_id = graphene.Node.to_global_id("Order", order.id)
return {
"id": order_id,
@@ -2288,11 +2302,14 @@ def order_meta_update_variables(order):
def test_user_without_permission_cannot_update_private_meta(
- staff_api_client, staff_user, update_order_private_meta, order_meta_update_variables
+ staff_api_client,
+ staff_user,
+ update_order_private_meta,
+ order_private_meta_update_variables,
):
assert not staff_user.has_perm("order.manage_orders")
response = staff_api_client.post_graphql(
- update_order_private_meta, order_meta_update_variables
+ update_order_private_meta, order_private_meta_update_variables
)
assert_no_permission(response)
@@ -2315,13 +2332,13 @@ def test_user_with_permission_can_update_private_meta(
staff_api_client,
staff_user,
update_order_private_meta,
- order_meta_update_variables,
+ order_private_meta_update_variables,
order,
):
staff_user.user_permissions.add(permission_manage_orders)
assert staff_user.has_perm("order.manage_orders")
response = staff_api_client.post_graphql(
- update_order_private_meta, order_meta_update_variables
+ update_order_private_meta, order_private_meta_update_variables
)
content = get_graphql_content(response)
errors = content["data"]["orderUpdatePrivateMeta"]["errors"]
@@ -2330,36 +2347,36 @@ def test_user_with_permission_can_update_private_meta(
assert order.get_private_meta(namespace="test", client="client1") == {"foo": "bar"}
-def clear_meta(mutation_name):
+def clear_order_meta():
return """
- mutation %s($id: ID!, $input: MetaPath!) {
- %s(id: $id, input: $input) {
+ mutation orderClearMeta($token: UUID!, $input: MetaPath!) {
+ orderClearMeta(token: $token, input: $input) {
errors {
message
}
}
}
- """ % (
- mutation_name,
- mutation_name,
- )
-
-
-def clear_order_meta():
- return clear_meta("orderClearMeta")
+ """
@pytest.fixture
def clear_order_private_meta():
- return clear_meta("orderClearPrivateMeta")
+ return """
+ mutation orderClearPrivateMeta($id: ID!, $input: MetaPath!) {
+ orderClearPrivateMeta(id: $id, input: $input) {
+ errors {
+ message
+ }
+ }
+ }
+ """
@pytest.fixture
def clear_meta_variables(order):
- order_id = graphene.Node.to_global_id("Order", order.id)
return {
- "id": order_id,
+ "token": order.token,
"input": {"namespace": "test", "clientName": "client1", "key": "foo"},
}