Files
moloapp/tests/example/data/migrations_test.cpp
T

29 lines
1.5 KiB
C++
Raw Normal View History

// Route: /data/migrations (check preview, apply, drift, heal)
#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;
auto page = f.client->get("/data/migrations");
check(page.status == 200, "status 200");
check(contains(page.body, "CREATE TABLE users") && contains(page.body, "CREATE TABLE posts"), "preview lists pending sql");
check(contains(page.body, "none"), "nothing applied by viewing");
auto one = f.client->post("/data/migrations/apply", "limit=1", kForm);
check(contains(one.body, "1 migration(s) applied"), "apply one step");
check(!contains(one.body, "CREATE TABLE users"), "applied step leaves the preview");
check(contains(one.body, "CREATE TABLE posts"), "later steps still pending");
auto rest = f.client->post("/data/migrations/apply", "limit=3", kForm);
check(contains(rest.body, "2 migration(s) applied"), "rest applied");
check(contains(rest.body, "table posts"), "side effect: table exists");
f.client->post("/data/migrations/drift", "", kForm);
check(contains(f.client->get("/data/migrations").body, "003 posts"), "drift detected");
check(contains(f.client->post("/data/migrations/heal", "", kForm).body, "1 table(s) healed"), "healer repairs drift");
auto bad = f.client->post("/data/migrations/apply", "limit=9", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 3"), "422 step limit");
return finish("data/migrations");
}