[
  {
    "comment": "create a user account to block delete later on",
    "request": {
      "uri": "users",
      "method": "put",
      "entity": {
        "name": "user_with_payment_to_block_delete@example.com",
        "password": "password1!",
        "agreeToTerms": true
      }
    },
    "response": { "store": "testAccount" }
  },

  {
    "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" }
  },

  {
    "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": "now (block) delete the account",
    "request": {
      "uri": "users/{{testAccount.uuid}}",
      "method": "delete"
    }
  },

  {
    "comment": "lookup user, expect that it is still there, just marked as deleted",
    "request": { "uri": "users/{{testAccount.uuid}}" },
    "response": {
      "check": [
        { "condition": "json.getUuid() === testAccount.getUuid()" },
        { "condition": "json.getName() === testAccount.getName()" },
        { "condition": "json.deleted()" }
      ]
    }
  },

  {
    "comment": "look up for deleted account's bills - none",
    "request": { "uri": "users/{{testAccount.uuid}}/bills" },
    "response": { "check": [{ "condition": "len(json) === 0" }] }
  },

  {
    "comment": "look up for deleted account's payments - none",
    "request": { "uri": "users/{{testAccount.uuid}}/payments" },
    "response": { "check": [{ "condition": "len(json) === 0" }] }
  },

  {
    "comment": "look up for deleted account's payment methods - none",
    "request": { "uri": "users/{{testAccount.uuid}}/paymentMethods" },
    "response": { "check": [{ "condition": "len(json) === 0" }] }
  },

  {
    "comment": "try deleting the same account again - expect fully deletion this time even without policy",
    "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
]
