use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct LiveSubArea {
pub id: String,
pub parent_id: String,
pub old_area_id: String,
pub name: String,
pub act_id: String,
pub pk_status: String,
pub hot_status: i32,
pub lock_status: String,
pub pic: String,
pub parent_name: String,
pub area_type: i32,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct LiveParentArea {
pub id: i32,
pub name: String,
pub list: Vec<LiveSubArea>,
}
#[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/area-list/contract.json"
))
}
#[ignore = "legacy live API test; requires explicit BPI_LIVE_TEST review"]
#[tokio::test]
async fn test_get_live_area_list() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new().expect("client should build");
let data = bpi.live().area_list().await?;
assert!(!data.is_empty());
Ok(())
}
#[test]
fn live_area_list_contract_matches_endpoint_request() -> BpiResult<()> {
let contract = contract()?;
assert_eq!(contract.name, "live.area_list");
assert_eq!(contract.request.method, HttpMethod::Get);
assert_eq!(
contract.request.url.as_str(),
"https://api.live.bilibili.com/room/v1/Area/getList"
);
assert!(contract.request.query.is_empty());
assert_eq!(contract.cases.len(), 3);
assert_eq!(
contract.cases[0].response.rust_model.as_deref(),
Some("Vec<LiveParentArea>")
);
Ok(())
}
#[test]
fn live_area_list_response_fixture_parses_declared_model() -> BpiResult<()> {
let payload = ApiEnvelope::<Vec<LiveParentArea>>::from_slice(include_bytes!(
"../../tests/contracts/live/public-core/area-list/responses/success.json"
))?
.into_payload()?;
assert_eq!(payload.len(), 1);
assert_eq!(payload[0].list.len(), 1);
Ok(())
}
fn local_probe_body(profile: &str) -> Option<serde_json::Value> {
let path =
format!("target/bpi-probe-runs/live/public-core/area-list/{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_area_list_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<Vec<LiveParentArea>>>(body)?
.into_payload()?;
assert!(!payload.is_empty());
}
}
Ok(())
}
}