// Route: /data/query (query builder and has-many relation) #include "support/Assert.hpp" using namespace molo::example::test; using molo::example::fw::Method; static const char* kForm = "application/x-www-form-urlencoded"; int main() { Fixture f; check(f.client->get("/data/query").status == 200, "status 200"); auto all = f.client->post("/data/query/run", "limit=10&order=title", kForm); check(contains(all.body, "ORDER BY posts.title LIMIT 10"), "sql built"); check(contains(all.body, "5 row(s)"), "five posts"); check(contains(all.body, "Alpha by ada") && contains(all.body, "Beta by grace"), "relation joins author"); auto ada = f.client->post("/data/query/run", "user_id=1", kForm); check(contains(ada.body, "WHERE posts.user_id = 1") && contains(ada.body, "3 row(s)"), "where filter"); auto lim = f.client->post("/data/query/run", "limit=2", kForm); check(contains(lim.body, "2 row(s)"), "limit applied"); auto bad = f.client->post("/data/query/run", "order=name", kForm); check(bad.status == 422 && contains(bad.body, "must be one of: id, title"), "422 order whitelist"); check(f.client->post("/data/query/run", "limit=99", kForm).status == 422, "422 limit above cap"); return finish("data/query"); }