From a15743bd6530007ab4711c0cdca9f86cff4d9d34 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 3 Jul 2022 18:52:16 +0200 Subject: [PATCH] Fix episodes being optional Signed-off-by: trivernis --- Cargo.toml | 2 +- src/includes.rs | 20 ++++++++++++++++++-- src/models.rs | 2 +- src/tests/test_client.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 45315af..792f277 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "animethemes-rs" -version = "0.4.3" +version = "0.4.4" authors = ["trivernis "] edition = "2021" readme = "README.md" diff --git a/src/includes.rs b/src/includes.rs index 490fa63..a1fff80 100644 --- a/src/includes.rs +++ b/src/includes.rs @@ -10,6 +10,11 @@ macro_rules! theme_include { } impl $name { + pub fn all() -> Self { + Self { + $($field: true),+ + } + } $(pub fn $field(mut self) -> Self { self.$field = true; @@ -149,7 +154,7 @@ theme_include!( #[derive(Clone, Copy, Default, Debug)] pub struct SearchIncludes { pub anime: AnimeInclude, - pub animethemes: ThemeInclude, + pub themes: ThemeInclude, pub artists: ArtistInclude, pub series: SeriesInclude, pub songs: SongInclude, @@ -157,10 +162,21 @@ pub struct SearchIncludes { } impl SearchIncludes { + pub fn all() -> Self { + Self { + anime: AnimeInclude::all(), + themes: ThemeInclude::all(), + artists: ArtistInclude::all(), + series: SeriesInclude::all(), + songs: SongInclude::all(), + videos: VideoInclude::all(), + } + } + pub fn indo_includes(self) -> Vec<(String, String)> { let mut includes = Vec::new(); let anime_includes = self.anime.includes(); - let animetheme_includes = self.animethemes.includes(); + let animetheme_includes = self.themes.includes(); let artist_includes = self.artists.includes(); let series_includes = self.series.includes(); let song_includes = self.songs.includes(); diff --git a/src/models.rs b/src/models.rs index f0c9908..115e579 100644 --- a/src/models.rs +++ b/src/models.rs @@ -91,7 +91,7 @@ pub struct ThemeEntry { pub meta: EntryMetadata, #[serde(deserialize_with = "crate::utils::empty_string_as_none")] pub version: Option, - pub episodes: String, + pub episodes: Option, pub nsfw: bool, pub spoiler: bool, pub notes: Option, diff --git a/src/tests/test_client.rs b/src/tests/test_client.rs index 03874fc..b8361ad 100644 --- a/src/tests/test_client.rs +++ b/src/tests/test_client.rs @@ -1,6 +1,22 @@ use crate::client::AnimeThemesClient; use crate::includes::*; +const TEST_QUERIES: &[&str] = &[ + "vivy", + "papiri koumei", + "re:zero", + "demon slayer", + "spirited away", + "classroom of the elite", + "tower of god", + "made in abyss", + "wonder egg priority", + "spider", + "bookworm", + "slime", + "kaguya", +]; + #[tokio::test] async fn it_searches() { let client = AnimeThemesClient::default(); @@ -26,6 +42,25 @@ async fn it_searches() { assert!(result.videos.is_some()); } +#[tokio::test] +async fn all_models_are_correct() { + let client = AnimeThemesClient::default(); + + for query in TEST_QUERIES { + println!("testing query '{query}'"); + let result = client + .search(query, &[], SearchIncludes::all()) + .await + .unwrap(); + assert!(result.artists.is_some()); + assert!(result.songs.is_some()); + assert!(result.anime.is_some()); + assert!(result.series.is_some()); + assert!(result.themes.is_some()); + assert!(result.videos.is_some()); + } +} + #[tokio::test] async fn it_returns_anime_by_slug() { let client = AnimeThemesClient::default();