25 lines
1.5 KiB
C++
25 lines
1.5 KiB
C++
// Route: POST /ai/openrouter/plan (validation only, no credential, no network)
|
|
#include "support/Assert.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
Fixture f;
|
|
auto post = [&](const std::string& body) { return f.client->post("/ai/openrouter/plan", body, "application/json"); };
|
|
auto ok = post("{\"call\":\"getModels\",\"query\":{\"limit\":5,\"sort\":\"newest\"}}");
|
|
check(ok.status == 200, "valid plan 200");
|
|
check(contains(ok.body, "/models?limit=5&sort=newest"), "target carries the query");
|
|
auto key = post("{\"call\":\"getKey\",\"args\":{\"hash\":\"abc\"}}");
|
|
check(key.status == 200 && contains(key.body, "/keys/abc") && contains(key.body, "\"key\":\"mgmt\""), "management call planned");
|
|
check(post("{\"call\":\"nope\"}").status == 422, "unknown call 422");
|
|
check(post("{}").status == 422, "missing call 422");
|
|
check(post("{\"call\":\"getKey\"}").status == 422, "missing path argument 422");
|
|
check(post("{\"call\":\"getKey\",\"args\":{\"hash\":\"a/b\"}}").status == 422, "bad path argument 422");
|
|
check(post("{\"call\":\"getModels\",\"query\":{\"bogus\":1}}").status == 422, "undeclared query 422");
|
|
check(post("{\"call\":\"sendChatCompletionRequest\",\"body\":{\"nonsense\":1}}").status == 422, "undeclared body field 422");
|
|
check(post("not json").status == 422, "invalid JSON 422");
|
|
check(post("[1]").status == 422, "non-object body 422");
|
|
check(f.client->get("/ai/openrouter/plan").status == 405, "get is 405");
|
|
return finish("ai/openrouter/plan");
|
|
}
|