()
| 129 | |
| 130 | #[tokio::test] |
| 131 | async fn test_proxy_forward_success() { |
| 132 | let mock_server = MockServer::start().await; |
| 133 | |
| 134 | Mock::given(method("POST")) |
| 135 | .and(path("/v1/chat/completions")) |
| 136 | .and(header("authorization", "Bearer sk-real-1")) |
| 137 | .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({ |
| 138 | "id": "chatcmpl-abc", |
| 139 | "choices": [{"message": {"content": "Hello!"}}] |
| 140 | }))) |
| 141 | .mount(&mock_server) |
| 142 | .await; |
| 143 | |
| 144 | let app = make_app(&mock_server.uri()); |
| 145 | let body = r#"{"model":"gpt-4","messages":[{"role":"user","content":"Hi"}]}"#; |
| 146 | let req = Request::builder() |
| 147 | .method("POST") |
| 148 | .uri("/v1/chat/completions") |
| 149 | .header("authorization", "Bearer vk-test-1") |
| 150 | .header("content-type", "application/json") |
| 151 | .body(Body::from(body)) |
| 152 | .unwrap(); |
| 153 | |
| 154 | let resp = app.oneshot(req).await.unwrap(); |
| 155 | assert_eq!(resp.status(), StatusCode::OK); |
| 156 | |
| 157 | let body = resp.into_body().collect().await.unwrap().to_bytes(); |
| 158 | let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); |
| 159 | assert_eq!(json["id"], "chatcmpl-abc"); |
| 160 | } |
| 161 | |
| 162 | #[tokio::test] |
| 163 | async fn test_proxy_preserves_query_params() { |
nothing calls this directly
no test coverage detected