#pragma once // Scripted Google backend for route tests: a GoogleClient over MockTransport // plus helpers that queue the three upstream replies a voice turn needs. // The real client, auth, request building and error mapping all run. #include #include #include "clients/transports/mock_transport.h" #include "google/credentials.h" #include "security/crypto/Base64.h" #include "support/Assert.hpp" namespace molo::example::test { inline const char* kTestKey = "AIzaTESTKEY-DO-NOT-LEAK"; struct GoogleRig { molo::clients::transports::MockTransport* mock = nullptr; std::shared_ptr client; explicit GoogleRig(bool with_key = true) { auto transport = std::make_unique(); mock = transport.get(); client = std::make_shared( std::move(transport), with_key ? molo::google::Credentials::api_key(kTestKey) : nullptr); } static molo::clients::ClientResponse json(const std::string& body, int status = 200) { molo::clients::HeaderMap h; h.set("Content-Type", "application/json"); return molo::clients::ClientResponse(status, h, body); } void tts(const std::string& audio) { mock->expect_response( molo::clients::Method::kPost, "/v1/text:synthesize", json("{\"audioContent\":\"" + molo::security::crypto::Base64::encode(audio) + "\"}")); } void stt(const std::string& text) { mock->expect_response( molo::clients::Method::kPost, "/v1/speech:recognize", text.empty() ? json("{}") : json("{\"results\":[{\"alternatives\":[{\"transcript\":\"" + text + "\",\"confidence\":0.95}]}]}")); } void gemini(const std::string& text) { mock->expect_response( molo::clients::Method::kPost, "/v1beta/models/rig-model:generateContent", json("{\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"" + text + "\"}]}}]}")); } void upstream_error(const std::string& path, int status, const std::string& google_status, const std::string& message) { mock->expect_response( molo::clients::Method::kPost, path, json("{\"error\":{\"code\":" + std::to_string(status) + ",\"message\":\"" + message + "\",\"status\":\"" + google_status + "\"}}", status)); } }; } // namespace molo::example::test