Files
moloapp/tests/example/ai/perplexity/page_test.cpp
T
retoorandClaude Sonnet 5.5 3404392887 feat(clients): perplexity: Sonar, Search, Agent, embeddings, decisions, batches, skills, orchestrator
Package molo::perplexity covering all 39 operations of the five published
OpenAPI documents, PerplexityChatModel, demo routes under /ai/perplexity,
check_spec.py, SPEC.md, 46 unit cases and 111 route checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:01:55 +01:00

34 lines
1.7 KiB
C++

// Routes: GET /ai/perplexity (page), /status, /calls, /errors (no credential needed)
#include <cstdlib>
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
setenv("MOLO_ENV_FILES", "off", 1);
unsetenv("PERPLEXITY_API_KEY");
Fixture f;
auto page = f.client->get("/ai/perplexity");
check(page.status == 200, "page 200");
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
check(contains(page.body, "Perplexity API") && contains(page.body, "viewport"), "title and mobile viewport");
check(contains(page.body, "/embedded/ai_perplexity.js"), "script wired");
check(f.client->post("/ai/perplexity", "{}", "application/json").status == 405, "post page is 405");
auto st = f.client->get("/ai/perplexity/status");
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
check(contains(st.body, "PERPLEXITY_API_KEY") && contains(st.body, "sonar-pro") && contains(st.body, "sonar-deep-research"),
"status names credential env and models");
check(f.client->post("/ai/perplexity/status", "{}", "application/json").status == 405, "post status is 405");
auto calls = f.client->get("/ai/perplexity/calls");
check(calls.status == 200 && contains(calls.body, "/v1/sonar") && contains(calls.body, "/search") &&
contains(calls.body, "/v1/agent") && contains(calls.body, "/orchestrator/v1/chat/completions"),
"call table listed");
auto errors = f.client->get("/ai/perplexity/errors");
check(errors.status == 200 && contains(errors.body, "Payment Required") && contains(errors.body, "\"retryable\":true"),
"error table listed");
return finish("ai/perplexity/page");
}