Files
moloapp/tests/example/google/discovery/page_test.cpp
T

37 lines
1.8 KiB
C++
Raw Normal View History

// Routes: GET /google/discovery (page) and GET /google/discovery/status.
// Both answer without a credential and never touch the network.
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
{
GoogleRig rig(false);
Fixture f(rig.client);
auto page = f.client->get("/google/discovery");
check(page.status == 200, "page 200");
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
check(contains(page.body, "Google Discovery") && contains(page.body, "viewport"), "page and mobile viewport");
check(contains(page.body, "/embedded/google_discovery.js"), "script wired");
check(f.client->post("/google/discovery", "{}", "application/json").status == 405, "post to the page is 405");
auto st = f.client->get("/google/discovery/status");
check(st.status == 200, "status 200");
check(contains(st.headers.get("Content-Type"), "application/json"), "json");
check(contains(st.body, "\"configured\":false"), "not configured");
check(contains(st.body, "\"max_pages\":50") && contains(st.body, "\"max_items\":10000"), "caps shown");
check(contains(st.body, "https://discovery.googleapis.com/discovery/v1/apis"), "directory url shown");
check(f.client->post("/google/discovery/status", "{}", "application/json").status == 405, "post to status is 405");
check(rig.mock->send_count() == 0, "no upstream traffic");
}
{
GoogleRig rig(true);
Fixture f(rig.client);
auto st = f.client->get("/google/discovery/status");
check(contains(st.body, "\"configured\":true"), "configured with a key");
check(!contains(st.body, kTestKey), "credential never shown");
check(rig.mock->send_count() == 0, "status makes no upstream call");
}
return finish("google/discovery/page");
}