diff --git a/bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java b/bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java index 6919aabe..c9a650a0 100644 --- a/bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java +++ b/bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java @@ -4,9 +4,18 @@ */ package bubble.test.system; +import bubble.dao.account.AccountDAO; +import bubble.model.bill.AccountPayment; +import bubble.model.bill.AccountPaymentMethod; +import bubble.model.bill.Bill; import bubble.test.ActivatedBubbleModelTestBase; +import org.cobbzilla.wizard.model.HashedPassword; import org.junit.Test; +import java.util.List; + +import static org.junit.Assert.*; + public class AccountDeletionTest extends ActivatedBubbleModelTestBase { @Override protected String getManifest() { return "manifest-test"; } @@ -15,8 +24,33 @@ public class AccountDeletionTest extends ActivatedBubbleModelTestBase { @Test public void testBlockAccountDeletion() throws Exception { modelTest("account_deletion/block_delete_account"); } @Test public void testDeleteAccountWithPayments() throws Exception { + final var archivedInfoDAO = getBean(bubble.dao.bill.AccountPaymentArchivedDAO.class); + assertEquals("Starting database contains some archived payments", 0, archivedInfoDAO.countAll().intValue()); + modelTest("account_deletion/delete_account_with_payments"); - // TODO: Check if all payment data is archived for the deleted user + assertEquals("Archived payments record not created for deleted user", 1, archivedInfoDAO.countAll().intValue()); + + final var accountDAO = getBean(AccountDAO.class); + // there should be just 1 deleted account - finding it by corresponding hashed password value: + final var deletedAccount = accountDAO.findByUniqueField("hashedPassword", HashedPassword.DELETED); + // just in case: + assertTrue("Account found with 'deleted' password is not marked as deleted", deletedAccount.deleted()); + + final var archivedInfo = archivedInfoDAO.findByAccountUuid(deletedAccount.getUuid()); + assertNotNull("Archived payment info not found for deleted user", archivedInfo); + + final List archivedBills = archivedInfo.getBills(); + assertEquals("Only 1 bill should be in for deleted account", archivedBills.size()); + + final List archivedPayments = archivedInfo.getPayments(); + assertEquals("Only 1 bill should be in for deleted account", archivedPayments.size()); + assertEquals("Archived payment should be for archived bill", + archivedBills.get(0).getUuid(), archivedPayments.get(0).getBill()); + + final List archivedPaymentMethods = archivedInfo.getpaymentMethods(); + assertEquals("Only 1 bill should be in for deleted account", archivedPaymentMethods.size()); + assertEquals("Archived payment method should be for used within archived payment", + archivedPayments.get(0).getPaymentMethod(), archivedPaymentMethods.get(0).getUuid()); } }