Skip to content

test: delete e2e merchant accounts after each run - #348

Merged
cbetta merged 2 commits into
mainfrom
test/e2e-delete-merchant-accounts
Nov 4, 2026
Merged

cbetta merged 2 commits into
mainfrom
test/e2e-delete-merchant-accounts

Conversation

@cbetta

@cbetta cbetta commented Nov 4, 2026 •

Copy link
Copy Markdown
Member
Reviewer check This PR
Auth / permissions No
Data access widened No
New secret, env var or key No
CI, deploy or infra No
Dependencies added or bumped No
Copilot Pending
Security review Pending

Every e2e run left its merchant accounts behind on api.sandbox.e2e.gr4vy.app now that it is no longer reset. This deletes them with core-api's new DELETE /merchant-accounts/{id} (gr4vy/core-api#9999, TA-19741). It isn't in the public spec, so the call is a raw request signed with the existing PRIVATE_KEY. A failed delete is logged and never fails the run (204 and 404 both count as done).

# tests/conftest.py
def merchant_fixture() -> Iterator[TestMerchant]:
    merchant = setup_merchant()
    yield merchant
    delete_merchant_account(merchant.private_key, merchant.merchant_account_id)

setup_merchant also deletes the account if the mock-card service fails to create, and test_merchant_accounts.py deletes its extra account with request.addfinalizer.

Cleanup is armed before the create call, so an account whose create response is lost still gets deleted (a never-created id just returns 404).

Verified: pylint tests is 10/10. Not yet run live against e2e.

🤖 Generated with Claude Code

cbetta and others added 2 commits November 4, 2026 15:02
Calls core-api's DELETE /merchant-accounts/{id} (gr4vy/core-api#9999)
directly, since it is not in the public spec. Failures are logged and
never fail the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A create whose response is lost still leaves the account on the server;
deleting an id that was never created returns 404, which cleanup already
treats as done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Approval should wait until the undocumented destructive DELETE endpoint is exercised in the live e2e environment to verify authorization, response behavior, and complete resource teardown.

No open issues 🎉

What changed in this PR

Updates the E2E test harness to clean up merchant accounts created during test runs, preventing sandbox data from accumulating.

Changes:

  • Adds an authenticated merchant-account deletion helper that treats 204 and 404 responses as successful cleanup.
  • Cleans up the module-scoped merchant fixture after each test module.
  • Handles setup failures and registers cleanup for the additional account created by the merchant-account CRUD test.
File Description
tests/​utils/​environment.py Adds merchant-account deletion and setup-failure cleanup.
tests/​conftest.py Converts the merchant fixture to generator-based teardown cleanup.
tests/​backoffice/​test_merchant_accounts.py Registers cleanup for the extra merchant account created by the CRUD test.

Review effort: Lite

@cbetta
cbetta marked this pull request as ready for review November 4, 2026 16:02
@cbetta
cbetta merged commit 93572b5 into main Nov 4, 2026
11 checks passed
@cbetta
cbetta deleted the test/e2e-delete-merchant-accounts branch November 4, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants