Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility endpoint for e2e cypress testing #2297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/dao/service_callback_api_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def resign_service_callbacks(resign: bool, unsafe: bool = False):
@transactional
@version_class(ServiceCallbackApi)
def save_service_callback_api(service_callback_api):
service_callback_api.id = create_uuid()
service_callback_api.id = create_uuid() if not service_callback_api.id else service_callback_api.id
service_callback_api.created_at = datetime.utcnow()
db.session.add(service_callback_api)

Expand Down Expand Up @@ -95,6 +95,18 @@ def delete_service_callback_api(service_callback_api):
db.session.delete(service_callback_api)


# Used by Cypress to clean up test data
@transactional
def delete_service_callback_api_history(service_callback_api: ServiceCallbackApi):
callback_history = (
service_callback_api.get_history_model()
.query.filter_by(service_id=service_callback_api.service_id, id=service_callback_api.id)
.all()
)
for history in callback_history:
db.session.delete(history)


@transactional
@version_class(ServiceCallbackApi)
def suspend_unsuspend_service_callback_api(service_callback_api, updated_by_id, suspend=False):
Expand Down
23 changes: 22 additions & 1 deletion app/service/callback_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from app.dao.service_callback_api_dao import (
delete_service_callback_api,
delete_service_callback_api_history,
get_service_callback_api,
get_service_callback_api_with_service_id,
reset_service_callback_api,
Expand Down Expand Up @@ -77,7 +78,7 @@ def remove_service_inbound_api(service_id, inbound_api_id):
error = "Service inbound API not found"
raise InvalidRequest(error, status_code=404)

delete_service_inbound_api(inbound_api)
delete_service_inbound_api(inbound_api) # this is inline
return "", 204


Expand Down Expand Up @@ -172,3 +173,23 @@ def handle_sql_error(e, table_name):
return jsonify(result="error", message="No result found"), 404
else:
raise e


# Utility endpoints for Cypress UI tests
@service_callback_blueprint.route("/delivery-receipt-api/cleanup/<uuid:callback_api_id>", methods=["DELETE"])
def cleanup_service_callback_api(service_id, callback_api_id):
"""
This utility endpoint cleans up service callback api data by service and callback api id.
It deletes the data in the service_callback_api and service_callback_api_history tables
to make end-to-end Cypress tests to be repeated reliably and predictably.
"""
callback_api = get_service_callback_api(callback_api_id, service_id)

if not callback_api:
error = "Service delivery receipt callback API not found"
raise InvalidRequest(error, status_code=404)

delete_service_callback_api_history(callback_api)
delete_service_callback_api(callback_api)

return "", 204
1 change: 1 addition & 0 deletions app/service/service_callback_api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "object",
"title": "Create service callback/inbound api",
"properties": {
"id": uuid,
"url": https_url,
"bearer_token": {"type": "string", "minLength": 10},
"updated_by_id": uuid,
Expand Down
Loading