[
  {
    "comment": "create a user account",
    "request": {
      "uri": "users",
      "method": "put",
      "entity": {
        "name": "test_plan_apps_user@example.com",
        "password": "password1!",
        "agreeToTerms": true
      }
    }
  },

  {
    "before": "sleep 22s",  // wait for account objects to be created
    "comment": "login as new user",
    "request": {
      "session": "new",
      "uri": "auth/login",
      "entity": {
        "name": "test_plan_apps_user@example.com",
        "password": "password1!"
      }
    },
    "response": {
      "store": "testAccount",
      "sessionName": "userSession",
      "session": "token"
    }
  },

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

  {
    "comment": "get plan apps for a system plan, we actually see our apps underneath",
    "request": { "uri": "plans/{{plans.[0].name}}/apps" },
    "response": {
      "store": "planApps",
      "check": [
        {"condition": "json.length === 1"},
        {"condition": "json[0].getAppObject().getTemplateApp() !== null"},
        {"condition": "json[0].getAppObject().template() === false"},
        {"condition": "json[0].getAppObject().getUuid() !== json[0].getApp()"},
        {"condition": "json[0].getAppObject().getTemplateApp() === json[0].getApp()"}
      ]
    }
  },

  {
    "comment": "add basic 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": "get plan apps, should be 1 and should have templateApp",
    "request": { "uri": "me/plans/{{accountPlan.uuid}}/apps" },
    "response": {
      "check": [
        {"condition": "json.length === 1"},
        {"condition": "json[0].getAppObject().getTemplateApp() !== null"},
        {"condition": "json[0].getAppObject().getName() === 'UserBlocker'"},
        {"condition": "json[0].getAppObject().getUuid() !== json[0].getApp()"},
        {"condition": "json[0].getAppObject().getTemplateApp() === json[0].getApp()"},
        {"condition": "json[0].getAppObject().template() === false"}
      ]
    }
  },

  {
    "comment": "add plus 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.[1].name}}",
        "footprint": "US",
        "paymentMethodObject": {
          "paymentMethodType": "free",
          "paymentInfo": "free"
        }
      }
    },
    "response": {
      "store": "accountPlan2"
    }
  },

  {
    "comment": "get plan apps, should be 2",
    "request": { "uri": "me/plans/{{accountPlan2.uuid}}/apps" },
    "response": {
      "check": [{"condition": "json.length === 2"}]
    }
  }

]