// Route: GET /flash, POST /flash/set (cookie flash shown once) #include "support/Assert.hpp" using namespace molo::example::test; using molo::example::fw::Method; int main() { Fixture f; check(contains(f.client->get("/flash").body, "No flash message"), "empty at start"); auto bad = f.client->request(Method::Post, "/flash/set", "message=", {{"Content-Type", "application/x-www-form-urlencoded"}}); check(bad.status == 422 && contains(bad.body, "field-error"), "inline validation error"); auto set = f.client->request(Method::Post, "/flash/set", "message=Saved+%3Cb%3E", {{"Content-Type", "application/x-www-form-urlencoded"}}); check(set.status == 303 && set.headers.get("Location") == "/flash", "redirect"); check(contains(set.headers.get("Set-Cookie"), "flash="), "flash cookie set"); auto once = f.client->get("/flash"); check(contains(once.body, "Saved <b>"), "shown escaped"); check(contains(once.headers.get("Set-Cookie"), "Max-Age=0"), "cookie cleared"); check(contains(f.client->get("/flash").body, "No flash message"), "gone on next view"); auto too_long = f.client->request(Method::Post, "/flash/set", "message=" + std::string(300, 'a'), {{"Content-Type", "application/x-www-form-urlencoded"}}); check(too_long.status == 422, "length limit"); check(f.client->request(Method::Delete, "/flash").status == 405, "delete is 405"); return finish("flash/flash"); }