Skip to content

Commit

Permalink
Merge pull request #974 from spryker/feature/frw-9631/refactor-servic…
Browse files Browse the repository at this point in the history
…e-points-api-tests

FRW-9631: refactor service points api tests
  • Loading branch information
AntonShopin authored Jan 3, 2025
2 parents 2f2430a + 48d87f9 commit 22d1f86
Show file tree
Hide file tree
Showing 33 changed files with 558 additions and 427 deletions.
2 changes: 1 addition & 1 deletion resources/common/common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -787,5 +787,5 @@ Trigger product labels update
Run console command console product-label:validity DE
Run console command console product-label:relations:update -vvv --no-touch AT
Run console command console product-label:validity AT
Repeat Keyword 3 Trigger multistore p&s
Repeat Keyword 2 Trigger multistore p&s
IF ${docker} or ${ignore_console} != True Sleep ${timeout}
76 changes: 72 additions & 4 deletions resources/common/common_api.robot
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ I set Headers:
Set Test Variable &{headers}
RETURN &{headers}

Reset API Headers
[Documentation] This keyword resets all previously set headers to their default values.
... It can be used to ensure that no unwanted headers persist between API requests.
...
... *Example:*
...
... ``I Reset Headers``
# Clear previously set headers
${headers}= Create Dictionary

# Reapply default headers if needed
Set To Dictionary ${headers} &{default_headers}
Log Default headers have been restored.

# Re-register headers as a test variable
Set Test Variable &{headers}
RETURN &{headers}

I set default Headers:
[Arguments] &{headers}
Log Dictionary ${headers}
Expand Down Expand Up @@ -1122,6 +1141,31 @@ Each array element of array in response should contain property with value NOT i
END
END

Each array element of array in response should NOT be empty:
[Documentation] This keyword checks that each array element of array contsains the speficied parameter ``${expected_property}`` with the value that does not empty.
...
... *Example:*
...
... ``Each array element of array in response should NOT be empty: [data] id``
[Arguments] ${json_path} ${expected_property}

@{data}= Get Value From Json ${response_body} ${json_path}
${list_length}= Get Length @{data}
${log_list}= Log List @{data}
FOR ${index} IN RANGE 0 ${list_length}
${list_element}= Get From List @{data} ${index}
${list_element}= Get Value From Json ${list_element} ${expected_property}
${list_element}= Convert To String ${list_element}
${list_element}= Replace String ${list_element} ' ${EMPTY}
${list_element}= Replace String ${list_element} [ ${EMPTY}
${list_element}= Replace String ${list_element} ] ${EMPTY}
TRY
Should Not Be Empty ${list_element}
EXCEPT
Fail Array element: '${expected_property}' of array: '${json_path}' is empty but SHOULD NOT
END
END

Each array element of nested array should contain property with value in:
[Documentation] This keyword checks that each array element of ``${nested_array} that is inside the parent array ``${json_path}`` contains the speficied parameter ``${expected_property}`` with the value that matches any of the parameters ``${expected_value1}``, ``${expected_value2}``, etc..
...
Expand Down Expand Up @@ -1446,10 +1490,13 @@ Response should return error message:
...
... ``Response should return error message: Can`t find abstract product image sets.``
[Arguments] ${error_message}
IF '${tag}'=='bapi' or '${tag}'=='sapi'
${data}= Get Value From Json ${response_body} [errors][0][message]
ELSE
${data}= Get Value From Json ${response_body} [errors][0][detail]
FOR ${tag} IN @{Test Tags}
IF '${tag}'=='bapi' or '${tag}'=='sapi'
${data}= Get Value From Json ${response_body} [errors][0][message]
END
IF '${tag}'=='glue'
${data}= Get Value From Json ${response_body} [errors][0][detail]
END
END
${data}= Convert To String ${data}
${data}= Replace String ${data} ' ${EMPTY}
Expand Down Expand Up @@ -2238,3 +2285,24 @@ I get access token by user credentials:
Save value to a variable: [access_token] token
Log ${token}
RETURN ${token}

Switch to Glue
Remove Tags *
Set Tags glue
Overwrite api variables
Reset API Headers

Switch to BAPI
Remove Tags *
Set Tags bapi
Overwrite api variables
Reset API Headers

*** Keywords ***
Array Element Should Contain Nested Property With Value At Least Once
[Arguments] ${json_path} ${nested_path} ${property} ${expected_value}
${matches}= Get Value From Json ${response_body} ${json_path}
${exists}= Evaluate
... any(item.get('${nested_path}', {}).get('${property}', None) == ${expected_value} for item in ${matches})
Should Be True ${exists} Expected property '${property}' with value '${expected_value}' not found in any array element.

22 changes: 22 additions & 0 deletions resources/environments/environments_api_mp_b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,28 @@
"dummy_api_key":"eba8110c9f9bf5685e8b5f4eba9b17c2",
"dummy_key_hash":"f683f48de788d57cd396fc212ef33fd146e1ff0b51cde37ecb4ddd77eeed1706",
"servicePoints":{
"default_service_points":{
"sp1":{
"key":"sp1",
"name":"Spryker Main Store"
},
"sp2":{
"key":"sp2",
"name":"Spryker Berlin Store"
}
},
"dynamic_service":{
"service_point_name":"robot",
"service_point_key":"robot",
"service_point_address_line_1":"Park Avenue",
"service_point_address_line_2":"Building 22",
"service_point_address_city":"robot",
"service_point_address_zip_code":"12345",
"service_point_address_country":"DE",
"service_type_name":"robot",
"service_type_key":"robot",
"service_key":"robot"
},
"servicePoints":[
{
"uuid":"test-service-point",
Expand Down
22 changes: 22 additions & 0 deletions resources/environments/environments_api_suite.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,28 @@
]
},
"servicePoints":{
"default_service_points":{
"sp1":{
"key":"sp1",
"name":"Spryker Main Store"
},
"sp2":{
"key":"sp2",
"name":"Spryker Berlin Store"
}
},
"dynamic_service":{
"service_point_name":"robot",
"service_point_key":"robot",
"service_point_address_line_1":"Park Avenue",
"service_point_address_line_2":"Building 22",
"service_point_address_city":"robot",
"service_point_address_zip_code":"12345",
"service_point_address_country":"DE",
"service_type_name":"robot",
"service_type_key":"robot",
"service_key":"robot"
},
"servicePoints":[
{
"uuid":"test-service-point",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ Delete service point in DB
[Documentation] This keyword deletes the entry from the DB table `spy_service_point`. If `withRelations=true`, deletes with relations.
... *Example:*
...
... ``Get service point uuid by key: ${service_point_key}``
... `` Delete service point in DB ${servicePointUuid}``
... OR
... ``Delete service point in DB uuid=262feb9d-33a7-5c55-9b04-45b1fd22067e withRelations=true``
...
[Arguments] ${uuid} ${withRelations}=${True}
Deactivate service points ${uuid}
Deactivate service points in DB ${uuid}
IF ${withRelations}
${idServicePoint}= Get id service point by uuid ${uuid}
Connect to Spryker DB
Expand All @@ -217,7 +220,6 @@ Delete service point in DB
Connect to Spryker DB
Execute Sql String DELETE FROM spy_service_point WHERE uuid = '${uuid}';
Disconnect From Database
Trigger publish trigger-events service_point timeout=1s

Delete service point address in DB
[Documentation] This keyword deletes the entry from the DB table `spy_service_point_address`.
Expand All @@ -230,7 +232,6 @@ Delete service point address in DB
Execute Sql String DELETE FROM spy_service_point_address WHERE uuid = '${uuid}';
Disconnect From Database


Delete service type in DB
[Documentation] This keyword deletes the entry from the DB table `spy_service_type`.
... *Example:*
Expand All @@ -242,7 +243,7 @@ Delete service type in DB
Execute Sql String DELETE FROM spy_service_type WHERE uuid = '${uuid}';
Disconnect From Database

Deactivate service points
Deactivate service points in DB
[Documentation] This keyword deactivates service points. If `uuid` is provided, deactivates service point by uuid.
... *Example:*
...
Expand All @@ -257,4 +258,124 @@ Deactivate service points
Connect to Spryker DB
Execute Sql String ${query};
Disconnect From Database

Deactivate service point via BAPI
[Arguments] ${service_point_uuid}
${have_access_token} Run Keyword and return status Should Contain ${headers} Authorization
IF not ${have_access_token}
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=${default_header_content_type} Authorization=Bearer ${token}
END
I send a PATCH request: /service-points/${service_point_uuid} {"data": {"type": "service-points","attributes": {"isActive": "false"}}}
Response status code should be: 200

Deactivate service via BAPI
[Arguments] ${service_uuid}
${have_access_token} Run Keyword and return status Should Contain ${headers} Authorization
IF not ${have_access_token}
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=${default_header_content_type} Authorization=Bearer ${token}
END
I send a PATCH request: When I send a PATCH request: /services/${service_uuid} {"data": {"type": "services", "attributes": {"isActive": "false"}}}
Response status code should be: 200

Create dynamic service with all data via BAPI if doesn't exist
Connect to Spryker DB
# Check if 'robot' dynamic service point already exists
IF '${db_engine}' == 'pymysql'
${dynamic_service_point_uuid}= Query SELECT uuid FROM spy_service_point WHERE `key` LIKE '%${dynamic_service.service_point_key}%' ORDER BY id_service_point DESC LIMIT 1;
ELSE
${dynamic_service_point_uuid}= Query SELECT uuid FROM spy_service_point WHERE "key" ILIKE '%${dynamic_service.service_point_key}%' ORDER BY id_service_point DESC LIMIT 1;
END
${dynamic_service_point_exists}= Evaluate len(${dynamic_service_point_uuid}) > 0
VAR ${dynamic_service_point_exists} ${dynamic_service_point_exists} scope=SUITE

IF ${dynamic_service_point_exists}
VAR ${dynamic_service_point_uuid} ${dynamic_service_point_uuid}[0][0] scope=SUITE
IF '${db_engine}' == 'pymysql'
${dynamic_service_point_address_uuid}= Query SELECT uuid FROM spy_service_point_address WHERE city LIKE '%${dynamic_service.service_point_address_city}%' ORDER BY id_service_point_address DESC LIMIT 1;
VAR ${dynamic_service_point_address_uuid} ${dynamic_service_point_address_uuid}[0][0] scope=SUITE

${dynamic_service_type_uuid}= Query SELECT uuid FROM spy_service_type WHERE `key` LIKE '%${dynamic_service.service_type_key}%' ORDER BY id_service_type DESC LIMIT 1;
VAR ${dynamic_service_type_uuid} ${dynamic_service_type_uuid}[0][0] scope=SUITE

${dynamic_service_uuid}= Query SELECT uuid FROM spy_service WHERE `key` LIKE '%${dynamic_service.service_key}%' ORDER BY id_service DESC LIMIT 1;
VAR ${dynamic_service_uuid} ${dynamic_service_uuid}[0][0] scope=SUITE
ELSE
${dynamic_service_point_address_uuid}= Query SELECT uuid FROM spy_service_point_address WHERE city ILIKE '%${dynamic_service.service_point_address_city}%' ORDER BY id_service_point_address DESC LIMIT 1;
VAR ${dynamic_service_point_address_uuid} ${dynamic_service_point_address_uuid}[0][0] scope=SUITE

${dynamic_service_type_uuid}= Query SELECT uuid FROM spy_service_type WHERE "key" ILIKE '%${dynamic_service.service_type_key}%' ORDER BY id_service_type DESC LIMIT 1;
VAR ${dynamic_service_type_uuid} ${dynamic_service_type_uuid}[0][0] scope=SUITE

${dynamic_service_uuid}= Query SELECT uuid FROM spy_service WHERE "key" ILIKE '%${dynamic_service.service_key}%' ORDER BY id_service DESC LIMIT 1;
VAR ${dynamic_service_uuid} ${dynamic_service_uuid}[0][0] scope=SUITE
END
END

Disconnect From Database

IF not ${dynamic_service_point_exists}
# Create Service Point
Switch to BAPI
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=${default_header_content_type} Authorization=Bearer ${token}
I send a POST request: /service-points {"data": {"type": "service-points","attributes": {"name": "${dynamic_service.service_point_name}","key": "${dynamic_service.service_point_key}","isActive": "true","stores": ["DE"]}}}
Response status code should be: 201
Save value to a variable: [data][id] service_point_id

VAR ${dynamic_service_point_uuid} ${service_point_id} scope=SUITE

# Create Service Point Address
I send a POST request: /service-points/${service_point_id}/service-point-addresses {"data":{"type":"service-point-addresses","attributes":{"address1":"${dynamic_service.service_point_address_line_1}","address2":"${dynamic_service.service_point_address_line_2}","city":"${dynamic_service.service_point_address_city}","zipCode":"${dynamic_service.service_point_address_zip_code}","countryIso2Code":"${dynamic_service.service_point_address_country}"}}}
Response status code should be: 201
Save value to a variable: [data][id] service_point_address_id

VAR ${dynamic_service_point_address_uuid} ${service_point_address_id} scope=SUITE

# Create Service Type
I send a POST request: /service-types {"data": {"type": "service-types", "attributes": {"name": "${dynamic_service.service_type_name}", "key": "${dynamic_service.service_type_key}"}}}
Response status code should be: 201
Save value to a variable: [data][id] service_type_id

VAR ${dynamic_service_type_uuid} ${service_type_id} scope=SUITE

# Create Service
I send a POST request: /services {"data": {"type": "services", "attributes": {"serviceTypeUuid": "${service_type_id}", "servicePointUuid": "${service_point_id}", "isActive":"true", "key": "${dynamic_service.service_key}"}}}
Response status code should be: 201
Save value to a variable: [data][id] service_id

VAR ${dynamic_service_uuid} ${service_id} scope=SUITE

# Publish to Redis and ES
Trigger p&s
END

Delete all non-default service points from DB with p&s
[Documentation] This keyword deletes all non-default service points from the `spy_service_point` table.
... It also deletes related entries from `spy_service_point_store`, `spy_service_point_address`, and `spy_service`.
... It processes all service points where `id_service_point > 3`.
...
[Tags] Database Cleanup
Connect to Spryker DB
${service_point_uuids}= Query SELECT uuid FROM spy_service_point WHERE id_service_point > 2;

FOR ${row} IN @{service_point_uuids}
${uuid}= Set Variable ${row}[0]
${idServicePoint}= Get id service point by uuid ${uuid}
Connect to Spryker DB
Execute Sql String DELETE FROM spy_service_point_store WHERE fk_service_point = ${idServicePoint};
Execute Sql String DELETE FROM spy_service_point_address WHERE fk_service_point = ${idServicePoint};
Execute Sql String DELETE FROM spy_service WHERE fk_service_point = ${idServicePoint};
Execute Sql String DELETE FROM spy_service_point WHERE uuid = '${uuid}';
END

${service_types_uuids}= Query SELECT uuid FROM spy_service_type WHERE id_service_type > 2;
FOR ${row} IN @{service_types_uuids}
${uuid}= Set Variable ${row}[0]
Execute Sql String DELETE FROM spy_service_type WHERE uuid = '${uuid}';
END

Disconnect From Database
Trigger publish trigger-events service_point timeout=1s
Loading

0 comments on commit 22d1f86

Please sign in to comment.