use crate::client::Client;
use crate::error::ApiError;
const ENDPOINT_URL: &str = "/v1/world_names";
#[derive(Debug, Deserialize, PartialEq)]
pub struct World {
id: String,
name: String,
}
impl World {
pub fn get_all(client: &Client) -> Result<Vec<World>, ApiError> {
client.request(ENDPOINT_URL)
}
pub fn id(&self) -> &str {
&self.id
}
pub fn name(&self) -> &str {
&self.name
}
}
#[cfg(test)]
mod tests {
use crate::v1::world_names::*;
use crate::client::Client;
const JSON_WORLD: &str = r#"
{
"id": "2014",
"name": "Gunnar's Hold"
}"#;
#[test]
fn create_world() {
match serde_json::from_str::<World>(JSON_WORLD) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_all_worlds() {
let client = Client::new();
let world = serde_json::from_str::<World>(JSON_WORLD).unwrap(); assert!(World::get_all(&client).unwrap().contains(&world))
}
}