use crate::client::Client;
use crate::error::ApiError;
const ENDPOINT_URL: &str = "/v1/recipes";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Recipes {
recipes: Vec<u32>,
}
impl Recipes {
pub fn get_all(client: &Client) -> Result<Recipes, ApiError> {
client.request(ENDPOINT_URL)
}
pub fn recipes(&self) -> &Vec<u32> {
&self.recipes
}
}
#[cfg(test)]
mod tests {
use crate::v1::recipes::*;
use crate::client::Client;
const JSON_RECIPES: &str = r#"
{
"recipes": [
1275,
3147
]
}"#;
#[test]
fn create_recipes() {
match serde_json::from_str::<Recipes>(JSON_RECIPES) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_all_recipes() {
let client = Client::new();
assert!(Recipes::get_all(&client).unwrap().recipes().len() >= 2000)
}
}