23 lines
1.4 KiB
C++
23 lines
1.4 KiB
C++
// Route: GET/POST /tenancy/provision (HTML form, inline errors)
|
|||
|
|
#include "support/Assert.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
using molo::example::fw::Method;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
Fixture f;
|
||
|
|
auto page = f.client->get("/tenancy/provision");
|
||
|
|
check(page.status == 200 && contains(page.headers.get("Content-Type"), "text/html"), "form page");
|
||
|
|
auto bad = f.client->post("/tenancy/provision", "id=Bad&name=&plan=gold", "application/x-www-form-urlencoded");
|
||
|
|
check(bad.status == 422 && contains(bad.headers.get("Content-Type"), "text/html"), "html 422");
|
||
|
|
check(contains(bad.body, "field-error") && !contains(bad.body, "\"failures\""), "inline errors, no raw json");
|
||
|
|
auto ok = f.client->post("/tenancy/provision", "id=initech&name=Initech&plan=pro", "application/x-www-form-urlencoded");
|
||
|
|
check(ok.status == 201 && contains(ok.body, "provisioned"), "created");
|
||
|
|
check(f.client->get("/tenancy/t/initech/whoami").status == 200, "side effect: tenant resolves");
|
||
|
|
auto dup = f.client->post("/tenancy/provision", "id=initech&name=X&plan=free", "application/x-www-form-urlencoded");
|
||
|
|
check(dup.status == 422 && contains(dup.body, "exists"), "duplicate rejected");
|
||
|
|
auto js = f.client->request(Method::Post, "/tenancy/provision", "{\"id\":\"b\"}", {{"Content-Type", "application/json"}});
|
||
|
|
check(js.status == 422 && contains(js.headers.get("Content-Type"), "application/json"), "json client gets json");
|
||
|
|
return finish("tenancy/provision");
|
||
|
|
}
|