Parcourir la source

Add test for arhiciving payments on full account deletion

tags/v0.10.5
Kristijan Mitrovic il y a 4 ans
Parent
révision
a206eafb55
3 fichiers modifiés avec 152 ajouts et 13 suppressions
  1. +18
    -4
      bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java
  2. +5
    -9
      bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account_with_payments.json
  3. +129
    -0
      bubble-server/src/test/resources/models/tests/account_deletion/full_delete_account_with_payments.json

+ 18
- 4
bubble-server/src/test/java/bubble/test/system/AccountDeletionTest.java Voir le fichier

@@ -5,13 +5,18 @@
package bubble.test.system;

import bubble.dao.account.AccountDAO;
import bubble.dao.bill.AccountPaymentArchivedDAO;
import bubble.model.account.Account;
import bubble.model.bill.AccountPayment;
import bubble.model.bill.AccountPaymentMethod;
import bubble.model.bill.Bill;
import bubble.test.ActivatedBubbleModelTestBase;
import lombok.NonNull;
import org.junit.Before;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@@ -19,16 +24,25 @@ public class AccountDeletionTest extends ActivatedBubbleModelTestBase {

@Override protected String getManifest() { return "manifest-test"; }

@Before public void truncatePaymentArchive() {
final var archivedInfoDAO = getBean(AccountPaymentArchivedDAO.class);
archivedInfoDAO.delete(archivedInfoDAO.findAll());
}

@Test public void testFullAccountDeletion() throws Exception { modelTest("account_deletion/full_delete_account"); }
@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());
@Test public void testBlockDeleteAccountWithPayments() throws Exception {
checkArchivedPayments(modelTest("account_deletion/block_delete_account_with_payments"));
}

final var modelTestCtx = modelTest("account_deletion/delete_account_with_payments");
@Test public void testFullDeleteAccountWithPayments() throws Exception {
checkArchivedPayments(modelTest("account_deletion/full_delete_account_with_payments"));
}

private void checkArchivedPayments(@NonNull final Map<String, Object> modelTestCtx) {
final var accountDAO = getBean(AccountDAO.class);
final var archivedInfoDAO = getBean(AccountPaymentArchivedDAO.class);

final var deletedAccounts = accountDAO.findDeleted();
// the account was fully deleted at the end of the JSON test


bubble-server/src/test/resources/models/tests/account_deletion/delete_account_with_payments.json → bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account_with_payments.json Voir le fichier

@@ -1,31 +1,27 @@
[
{
"comment": "create a user account",
"comment": "create a user account to block delete later on",
"request": {
"uri": "users",
"method": "put",
"entity": {
"name": "user_with_payment_to_delete",
"name": "user_with_payment_to_block_delete",
"password": "password1!",
"agreeToTerms": true,
"contact": { "type": "email", "info": "user_with_payment_to_delete@example.com" }
"contact": { "type": "email", "info": "user_with_payment_to_block_delete@example.com" }
}
},
"response": { "store": "testAccount" }
},

{
"comment": "login as new user",
"comment": "login as that new user",
"request": {
"session": "new",
"uri": "auth/login",
"entity": { "name": "{{ testAccount.name }}", "password": "password1!" }
},
"response": {
"store": "testAccount",
"sessionName": "userSession",
"session": "token"
}
"response": { "store": "testAccount", "sessionName": "userSession", "session": "token" }
},

{

+ 129
- 0
bubble-server/src/test/resources/models/tests/account_deletion/full_delete_account_with_payments.json Voir le fichier

@@ -0,0 +1,129 @@
[
{
"comment": "create a user account",
"request": {
"uri": "users",
"method": "put",
"entity": {
"name": "user_with_payment_to_delete",
"password": "password1!",
"agreeToTerms": true,
"contact": { "type": "email", "info": "user_with_payment_to_delete@example.com" }
}
},
"response": { "store": "testAccount" }
},

{
"comment": "login as new user",
"request": {
"session": "new",
"uri": "auth/login",
"entity": { "name": "{{ testAccount.name }}", "password": "password1!" }
},
"response": {
"store": "testAccount",
"sessionName": "userSession",
"session": "token"
}
},

{
"comment": "get plans",
"request": { "uri": "plans" },
"response": { "store": "plans", "check": [{ "condition": "len(json) >= 1" }] }
},

{
"comment": "add plan, using 'free' payment method",
"request": {
"uri": "me/plans",
"method": "put",
"entity": {
"name": "test-net-{{rand 5}}",
"domain": "{{defaultDomain}}",
"locale": "en_US",
"timezone": "EST",
"plan": "{{plans.[0].name}}",
"footprint": "US",
"paymentMethodObject": { "paymentMethodType": "free", "paymentInfo": "free" }
}
},
"response": { "store": "accountPlan" }
},

{
"comment": "as root, verify bill exists and is paid",
"before": "sleep 15s",
"request": { "session": "rootSession", "uri": "users/{{testAccount.uuid}}/bills" },
"response": {
"store": "bills",
"check": [
{ "condition": "len(json) === 1" },
{ "condition": "json[0].getPlan() === plans[0].getUuid()" },
{ "condition": "json[0].getAccountPlan() === accountPlan.getUuid()" },
{ "condition": "json[0].getTotal() === plans[0].getPrice()" },
{ "condition": "json[0].getStatus().name() === 'paid'" }
]
}
},

{
"comment": "verify payment exists and is successful",
"request": { "uri": "users/{{testAccount.uuid}}/payments" },
"response": {
"store": "payments",
"check": [
{ "condition": "len(json) === 1" },
{ "condition": "json[0].getPlan() === plans[0].getUuid()" },
{ "condition": "json[0].getAccountPlan() === accountPlan.getUuid()" },
{ "condition": "json[0].getAmount() === plans[0].getPrice()" },
{ "condition": "json[0].getStatus().name() === 'success'" },
{ "condition": "json[0].getBill() === bills[0].getUuid()" }
]
}
},

{
"comment": "verify account payment methods, should be one",
"request": { "uri": "users/{{testAccount.uuid}}/paymentMethods" },
"response": {
"store": "paymentMethods",
"check": [
{ "condition": "len(json) === 1" },
{ "condition": "json[0].getPaymentMethodType().name() === 'free'" },
{ "condition": "json[0].getMaskedPaymentInfo() === 'XXXXXXXX'" },
{ "condition": "json[0].getUuid() === payments[0].getPaymentMethod()" }
]
}
},

{
"comment": "look up that account's policy",
"request": { "uri": "users/{{testAccount.uuid}}/policy" },
"response": { "store": "policy", "check": [{ "condition": "len(json.getAccountContacts()) == 1" }] }
},

{
"comment": "set deletion policy to full_delete for that account",
"request": {
"uri": "users/{{testAccount.uuid}}/policy",
"data": "policy",
"entity": { "deletionPolicy": "full_delete" }
},
"response": { "store": "policy", "check": [{ "condition": "json.getDeletionPolicy().name() == 'full_delete'" }] }
},

{
"comment": "now (full) delete the account",
"request": { "uri": "users/{{testAccount.uuid}}", "method": "delete" }
},

{
"comment": "lookup user, expect there's no such user now",
"request": { "uri": "users/{{testAccount.uuid}}" },
"response": { "status": 404 }
}

// test continues within Java's JUnit test as there are not resource methods implemented for archived payment data
]

Chargement…
Annuler
Enregistrer