From fd0de714a439dc4b5a297ca32669b87fca093cd4 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 29 Mar 2026 12:28:27 +0200 Subject: [PATCH] fix(loyalty): update delete tests for soft-delete behavior Delete program tests now verify soft-delete (deleted_at set, record hidden from normal queries) instead of expecting hard deletion. Uses db.query() instead of db.get() since the soft-delete filter only applies to ORM queries, not identity map lookups. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../loyalty/tests/integration/test_admin_api.py | 17 ++++++++++++++--- .../tests/integration/test_merchant_api.py | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/modules/loyalty/tests/integration/test_admin_api.py b/app/modules/loyalty/tests/integration/test_admin_api.py index 01f8cb3e..9d331e6c 100644 --- a/app/modules/loyalty/tests/integration/test_admin_api.py +++ b/app/modules/loyalty/tests/integration/test_admin_api.py @@ -213,7 +213,7 @@ class TestAdminDeleteProgram: def test_delete_program( self, client, super_admin_headers, admin_program, db ): - """Admin can delete any program.""" + """Admin can soft-delete any program.""" program_id = admin_program.id response = client.delete( @@ -222,10 +222,21 @@ class TestAdminDeleteProgram: ) assert response.status_code == 204 - # Verify deleted - deleted = db.get(LoyaltyProgram, program_id) + # Verify soft-deleted (hidden from normal queries) + db.expire_all() + deleted = db.query(LoyaltyProgram).filter(LoyaltyProgram.id == program_id).first() assert deleted is None + # But visible with include_deleted + visible = ( + db.query(LoyaltyProgram) + .execution_options(include_deleted=True) + .filter(LoyaltyProgram.id == program_id) + .first() + ) + assert visible is not None + assert visible.deleted_at is not None + def test_delete_nonexistent_program( self, client, super_admin_headers ): diff --git a/app/modules/loyalty/tests/integration/test_merchant_api.py b/app/modules/loyalty/tests/integration/test_merchant_api.py index 605918ae..fe4c2007 100644 --- a/app/modules/loyalty/tests/integration/test_merchant_api.py +++ b/app/modules/loyalty/tests/integration/test_merchant_api.py @@ -233,7 +233,7 @@ class TestMerchantDeleteProgram: def test_delete_program_success( self, client, loyalty_merchant_headers, loyalty_store_setup, db ): - """Delete the merchant's loyalty program.""" + """Soft-delete the merchant's loyalty program.""" program_id = loyalty_store_setup["program"].id response = client.delete( @@ -241,12 +241,23 @@ class TestMerchantDeleteProgram: ) assert response.status_code == 204 - # Verify program is deleted + # Verify soft-deleted (hidden from normal queries) from app.modules.loyalty.models import LoyaltyProgram - deleted = db.get(LoyaltyProgram, program_id) + db.expire_all() + deleted = db.query(LoyaltyProgram).filter(LoyaltyProgram.id == program_id).first() assert deleted is None + # But visible with include_deleted + visible = ( + db.query(LoyaltyProgram) + .execution_options(include_deleted=True) + .filter(LoyaltyProgram.id == program_id) + .first() + ) + assert visible is not None + assert visible.deleted_at is not None + def test_delete_program_not_found( self, client, loyalty_merchant_headers_no_program ):