Files

35 lines
2.0 KiB
C++
Raw Permalink Normal View History

// Routes: GET /google/workspace/{status,apis,calls,scopes}
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
GoogleRig rig(false);
Fixture f(rig.client);
auto st = f.client->get("/google/workspace/status");
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without credential");
check(contains(st.body, "\"apis\":20"), "twenty apis");
auto apis = f.client->get("/google/workspace/apis");
check(apis.status == 200 && contains(apis.body, "\"name\":\"gmail\"") &&
contains(apis.body, "\"name\":\"vault\"") && contains(apis.body, "\"name\":\"directory\""),
"apis listed");
check(contains(apis.body, "gmail.googleapis.com"), "service to enable shown");
auto calls = f.client->get("/google/workspace/calls?api=gmail&kind=s");
check(calls.status == 200 && contains(calls.body, "gmail.users.messages.send") &&
!contains(calls.body, "gmail.users.messages.list"),
"calls filtered by api and kind");
check(f.client->get("/google/workspace/calls?api=nope").status == 422, "unknown api is 422");
check(f.client->get("/google/workspace/calls?kind=x").status == 422, "unknown kind is 422");
auto all = f.client->get("/google/workspace/calls");
check(all.status == 200 && contains(all.body, "\"truncated\":true"), "unfiltered listing is capped");
auto scopes = f.client->get("/google/workspace/scopes?apis=gmail,drive&readonly=true");
check(scopes.status == 200 && contains(scopes.body, "gmail.readonly") && contains(scopes.body, "drive.readonly"),
"readonly scopes");
check(!contains(scopes.body, "auth/gmail.send"), "no write scope in the readonly set");
check(f.client->get("/google/workspace/scopes").status == 422, "apis required");
check(f.client->get("/google/workspace/scopes?apis=gmail&readonly=maybe").status == 422, "readonly must be a bool");
check(f.client->post("/google/workspace/status", "{}", "application/json").status == 405, "post is 405");
check(rig.mock->send_count() == 0, "no network");
return finish("google/workspace/status");
}