[
  {
    "comment": "lookup networks",
    "request": { "uri": "me/networks?all=true" },
    "response": {
      "store": "networks",
      "check": [ {"condition": "json.length >= 1"} ]
    }
  },

  {
    "comment": "new session, register a user account, do not agree to terms, fails",
    "request": {
      "session": "new",
      "uri": "auth/register",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!"
      }
    },
    "response": {
      "status": 422,
      "check": [ {"condition": "json.has('err.terms.required')"} ]
    }
  },

  {
    "comment": "new session, register a user account, agree to terms, succeeds",
    "request": {
      "session": "new",
      "uri": "auth/register",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!",
        "agreeToTerms": true
      }
    },
    "response": {
      "sessionName": "user1session",
      "session": "token"
    }
  },

  {
    "comment": "view current user",
    "request": { "uri": "me" },
    "response": {
      "check": [ {"condition": "json.getName() == 'account_reg_user@example.com'"} ]
    }
  },

  {
    "comment": "log out user",
    "request": {
      "session": "user1session",
      "uri": "auth/logout"
    }
  },

  {
    "comment": "login as account_reg_user@example.com, works",
    "request": {
      "session": "new",
      "uri": "auth/login",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!"
      }
    },
    "response": {
      "sessionName": "user1session2",
      "session": "token"
    }
  },

  {
    "comment": "view current user",
    "request": { "uri":  "me" },
    "response": {
      "store": "user1",
      "check": [ {"condition": "json.getName() == 'account_reg_user@example.com'"} ]
    }
  },

  {
    "comment": "back to root session, list network tags",
    "request": {
      "session": "rootSession",
      "uri": "me/networks/{{networks.[0].uuid}}/tags"
    },
    "response": {
      "check": [
        {"condition": "json.hasTag('allowRegistration')"},
        {"condition": "json.getTag('allowRegistration') == 'true'"}
      ]
    }
  },

  {
    "comment": "disable account registration",
    "request": {
      "uri": "me/networks/{{networks.[0].uuid}}/tags/allowRegistration",
      "entity": { "value": "false" }
    }
  },

  {
    "comment": "re-list network tags, see updated value for allowRegistration",
    "request": {
      "session": "rootSession",
      "uri": "me/networks/{{networks.[0].uuid}}/tags"
    },
    "response": {
      "check": [
        {"condition": "json.hasTag('allowRegistration')"},
        {"condition": "json.getTag('allowRegistration') == 'false'"}
      ]
    }
  },

  {
    "comment": "in user session, try to re-enable registrations. fails.",
    "request": {
      "session": "user1session",
      "uri": "me/networks/{{networks.[0].uuid}}/tags"
    },
    "response": { "status": 401 }
  },

  {
    "comment": "fetch the user account created earlier",
    "request": {
      "session": "rootSession",
      "uri": "users/{{user1.uuid}}"
    },
    "response": {
      "check": [ {"condition": "json.getSuspended() == false"} ]
    }
  },

  {
    "comment": "suspend the user account created earlier",
    "request": {
      "session": "rootSession",
      "uri": "users/{{user1.uuid}}",
      "data": "user1",
      "entity": {
        "suspended": true
      }
    }
  },

  {
    "comment": "new session, try to register a user account, fails",
    "request": {
      "session": "new",
      "uri": "auth/register",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!",
        "agreeToTerms": true
      }
    },
    "response": {
      "status": 422,
      "check": [ {"condition": "json.has('err.registration.disabled')"} ]
    }
  },


  {
    "comment": "new session, try to login to previously registered user account, fails",
    "request": {
      "session": "new",
      "uri": "auth/login",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!"
      }
    },
    "response": {
      "status":  422,
      "check": [ {"condition": "json.has('err.account.suspended')"} ]
    }
  },


  {
    "comment": "as root, re-enable registration",
    "request": {
      "session": "rootSession",
      "uri": "me/networks/{{networks.[0].uuid}}/tags/allowRegistration",
      "entity": { "value": "true" }
    }
  },

  {
    "comment": "new session, register new user, fails because email is already used",
    "request": {
      "session": "new",
      "uri": "auth/register",
      "entity": {
        "name": "account_reg_user@example.com",
        "password": "password1!",
        "agreeToTerms": true
      }
    },
    "response": {
      "status": 422,
      "check": [ {"condition": "json.has('err.email.registered')"} ]
    }
  },

  {
    "comment": "new session, register new user with fresh username, succeeds",
    "request": {
      "session": "new",
      "uri": "auth/register",
      "entity": {
        "name": "another_account_reg_user@example.com",
        "password": "password2!",
        "agreeToTerms": true
      }
    },
    "response": {
      "sessionName": "user2session",
      "session": "token"
    }
  },

  {
    "comment": "view new user",
    "request": { "uri": "me" },
    "response": {
      "check": [ {"condition": "json.getName() == 'another_account_reg_user@example.com'"} ]
    }
  }
]