feat(clients): discovery: generic engine for all Google Discovery APIs
Directory and document cache with caps, parameter and body validation before traffic, path/query/repeated/regional handling, key-or-OAuth choice, paging, long-running wait, whole-directory checker script, demo at /google/discovery. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// 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");
|
||||
}
|
||||
Reference in New Issue
Block a user