Skip to content

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

test_should_create_and_update_staff (#14683)

Renata056a7dda5100
diff --git a/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.py b/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.py
new file mode 100644
index 0000000000..91d6907109
--- /dev/null
+++ b/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.py
@@ -0,0 +1,54 @@
+import pytest
+
+from ..utils import assign_permissions
+from .utils import create_staff, update_staff
+
+
+def test_create_and_update_staff_with_metadata_core_1515(
+ e2e_staff_api_client,
+ permission_manage_staff,
+):
+ # Before
+ permissions = [
+ permission_manage_staff,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ # Step 1 - Create staff member with metadata
+ metadata = [{"key": "code", "value": "abc"}]
+ private_metadata = [{"key": "priv_code", "value": "priv_abc"}]
+ input_data = {
+ "firstName": "Leo",
+ "lastName": "Test",
+ "email": "[email protected]",
+ "isActive": True,
+ "metadata": metadata,
+ "privateMetadata": private_metadata,
+ }
+ data = create_staff(
+ e2e_staff_api_client,
+ input_data,
+ )
+
+ assert data is not None
+ staff_id = data["id"]
+ assert staff_id is not None
+ assert data["metadata"] == metadata
+ assert data["privateMetadata"] == private_metadata
+
+ # Step 2 - Update staff metadata
+ updated_metadata = [{"key": "code", "value": "update_pub"}]
+ updated_private_metadata = [{"key": "priv_code", "value": "update_priv"}]
+ update_input = {
+ "metadata": updated_metadata,
+ "privateMetadata": updated_private_metadata,
+ }
+ data = update_staff(
+ e2e_staff_api_client,
+ staff_id,
+ update_input,
+ )
+ assert data["id"] == staff_id
+ assert data["metadata"] == updated_metadata
+ assert data["privateMetadata"] == updated_private_metadata
diff --git a/saleor/tests/e2e/users/utils/__init__.py b/saleor/tests/e2e/users/utils/__init__.py
index a7593d0731..4cd4ff633c 100644
--- a/saleor/tests/e2e/users/utils/__init__.py
+++ b/saleor/tests/e2e/users/utils/__init__.py
@@ -1,9 +1,13 @@
from .create_customer import create_customer
from .customer_bulk_update import customer_bulk_update
from .customer_update import customer_update
+from .staff_create import create_staff
+from .staff_update import update_staff
__all__ = [
"create_customer",
"customer_bulk_update",
"customer_update",
+ "create_staff",
+ "update_staff",
]
diff --git a/saleor/tests/e2e/users/utils/staff_create.py b/saleor/tests/e2e/users/utils/staff_create.py
new file mode 100644
index 0000000000..50fec832ed
--- /dev/null
+++ b/saleor/tests/e2e/users/utils/staff_create.py
@@ -0,0 +1,42 @@
+from ...utils import get_graphql_content
+
+STAFF_CREATE_MUTATION = """
+mutation CreateStaff($input: StaffCreateInput!){
+ staffCreate(input:$input) {
+ user {
+ id
+ metadata {
+ key
+ value
+ }
+ privateMetadata {
+ key
+ value
+ }
+ }
+ errors {
+ field
+ message
+ }
+ }
+}
+"""
+
+
+def create_staff(
+ staff_api_client,
+ input_data,
+):
+ variables = {"input": input_data}
+
+ response = staff_api_client.post_graphql(
+ STAFF_CREATE_MUTATION,
+ variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["staffCreate"]["errors"] == []
+
+ data = content["data"]["staffCreate"]["user"]
+
+ return data
diff --git a/saleor/tests/e2e/users/utils/staff_update.py b/saleor/tests/e2e/users/utils/staff_update.py
new file mode 100644
index 0000000000..ec7448c69d
--- /dev/null
+++ b/saleor/tests/e2e/users/utils/staff_update.py
@@ -0,0 +1,45 @@
+from ...utils import get_graphql_content
+
+STAFF_UPDATE_MUTATION = """
+mutation StaffUpdate($id: ID!, $input: StaffUpdateInput!){
+ staffUpdate(id: $id,
+ input: $input) {
+ user {
+ id
+ metadata {
+ key
+ value
+ }
+ privateMetadata {
+ key
+ value
+ }
+ }
+ errors {
+ field
+ message
+ }
+ }
+}
+"""
+
+
+def update_staff(
+ staff_api_client,
+ staff_id,
+ input_data,
+):
+ variables = {
+ "id": staff_id,
+ "input": input_data,
+ }
+
+ response = staff_api_client.post_graphql(
+ STAFF_UPDATE_MUTATION,
+ variables,
+ )
+ content = get_graphql_content(response)
+ assert content["data"]["staffUpdate"]["errors"] == []
+ data = content["data"]["staffUpdate"]["user"]
+
+ return data