mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-07 00:05:49 +00:00
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
#![allow(dead_code)]
|
|
// Each integration test crate imports this module independently, so a helper can be
|
|
// used by one route test and intentionally unused by another.
|
|
|
|
use axum::body::to_bytes;
|
|
use chrono::Utc;
|
|
use serde_json::Value;
|
|
|
|
pub mod admin_accounts;
|
|
pub mod upstream;
|
|
|
|
pub async fn seed_admin_session(pool: &sqlx::SqlitePool, session_id: &str) {
|
|
let now = Utc::now().to_rfc3339();
|
|
sqlx::query(
|
|
"insert into admin_users (id, password_hash, created_at, updated_at) values (?, ?, ?, ?)",
|
|
)
|
|
.bind("admin_1")
|
|
.bind("hash")
|
|
.bind(&now)
|
|
.bind(&now)
|
|
.execute(pool)
|
|
.await
|
|
.unwrap();
|
|
sqlx::query(
|
|
"insert into admin_sessions (id, user_id, expires_at, created_at) values (?, ?, ?, ?)",
|
|
)
|
|
.bind(session_id)
|
|
.bind("admin_1")
|
|
.bind("2999-01-01T00:00:00Z")
|
|
.bind(now)
|
|
.execute(pool)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
pub async fn response_json(response: axum::response::Response) -> Value {
|
|
let bytes = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
serde_json::from_slice(&bytes).unwrap()
|
|
}
|
|
|
|
pub async fn response_text(response: axum::response::Response) -> String {
|
|
let bytes = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
String::from_utf8(bytes.to_vec()).unwrap()
|
|
}
|
|
|
|
pub async fn response_sse_data(response: axum::response::Response) -> Vec<String> {
|
|
response_text(response)
|
|
.await
|
|
.lines()
|
|
.filter_map(|line| line.strip_prefix("data: ").map(ToString::to_string))
|
|
.collect()
|
|
}
|