use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendantFrame {
pub name: String,
pub value: String,
pub position: i32,
pub desc: String,
pub area: i32,
pub area_old: i32,
pub bg_color: String,
pub bg_pic: String,
pub use_old_area: bool,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendantBadge {
pub name: String,
pub position: i32,
pub value: String,
pub desc: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomPendants {
pub frame: RoomPendantFrame,
pub mobile_frame: Option<RoomPendantFrame>,
pub badge: RoomPendantBadge,
pub mobile_badge: Option<RoomPendantBadge>,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomStudioInfo {
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RoomInfoData {
pub uid: i64,
pub room_id: i64,
pub short_id: i64,
pub attention: i64,
pub online: i64,
pub is_portrait: bool,
pub description: String,
pub live_status: i32,
pub area_id: i32,
pub parent_area_id: i32,
pub parent_area_name: String,
pub old_area_id: i32,
pub background: String,
pub title: String,
pub user_cover: String,
pub keyframe: String,
pub live_time: String,
pub tags: String,
pub room_silent_type: String,
pub room_silent_level: i32,
pub room_silent_second: i64,
pub area_name: String,
pub hot_words: Vec<String>,
pub hot_words_status: i32,
pub new_pendants: RoomPendants,
pub pk_status: i32,
pub pk_id: i64,
pub allow_change_area_time: i64,
pub allow_upload_cover_time: i64,
pub studio_info: Option<RoomStudioInfo>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::probe::contract::HttpMethod;
use crate::probe::endpoint_contract::EndpointContract;
use crate::{ApiEnvelope, BpiClient, BpiError, BpiResult};
fn contract() -> BpiResult<EndpointContract> {
EndpointContract::from_slice(include_bytes!(
"../../tests/contracts/live/public-core/room-info/contract.json"
))
}
#[ignore = "legacy live API test; requires explicit BPI_LIVE_TEST review"]
#[tokio::test]
async fn test_get_room_info() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new().expect("client should build");
let data = bpi.live().room_info(23174842).await?;
assert_eq!(data.room_id, 23174842);
Ok(())
}
#[test]
fn live_room_info_contract_matches_endpoint_request() -> BpiResult<()> {
let contract = contract()?;
assert_eq!(contract.name, "live.room_info");
assert_eq!(contract.request.method, HttpMethod::Get);
assert_eq!(
contract.request.url.as_str(),
"https://api.live.bilibili.com/room/v1/Room/get_info"
);
assert_eq!(
contract.request.query.get("room_id").map(String::as_str),
Some("23174842")
);
assert_eq!(contract.cases.len(), 3);
assert_eq!(
contract.cases[0].response.rust_model.as_deref(),
Some("RoomInfoData")
);
Ok(())
}
#[test]
fn live_room_info_response_fixture_parses_declared_model() -> BpiResult<()> {
let payload = ApiEnvelope::<RoomInfoData>::from_slice(include_bytes!(
"../../tests/contracts/live/public-core/room-info/responses/success.json"
))?
.into_payload()?;
assert_eq!(payload.room_id, 23174842);
assert_eq!(payload.live_status, 1);
Ok(())
}
fn local_probe_body(profile: &str) -> Option<serde_json::Value> {
let path =
format!("target/bpi-probe-runs/live/public-core/room-info/{profile}.response.json");
let bytes = std::fs::read(path).ok()?;
let value: serde_json::Value = serde_json::from_slice(&bytes).ok()?;
value
.get("response")
.and_then(|response| response.get("body"))
.cloned()
}
#[test]
fn live_room_info_model_matches_local_probe_outputs_when_available() -> BpiResult<()> {
for profile in ["anonymous", "normal", "vip"] {
if let Some(body) = local_probe_body(profile) {
let payload =
serde_json::from_value::<ApiEnvelope<RoomInfoData>>(body)?.into_payload()?;
assert_eq!(payload.room_id, 23174842);
}
}
Ok(())
}
}