use crate::client::Client;
use crate::error::ApiError;
const ENDPOINT_URL: &str = "/v1/wvw/objective_names";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Objective {
id: String,
name: String,
}
impl Objective {
pub fn get_all(client: &Client) -> Result<Vec<Objective>, 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::wvw::objective_names::*;
use crate::client::Client;
const JSON_OBJECTIVE: &str = r#"
{
"id": "95-103",
"name": "Border"
}"#;
#[test]
fn create_objective() {
match serde_json::from_str::<Objective>(JSON_OBJECTIVE) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_all_objectives() {
let client = Client::new();
let objective = serde_json::from_str::<Objective>(JSON_OBJECTIVE).unwrap();
assert!(Objective::get_all(&client).unwrap().contains(&objective))
}
}