|
| 1 | +use modrinth_api::ModrinthAPI; |
| 2 | +use modrinth_api::structs::projects::ProjectType; |
| 3 | +use modrinth_api::structs::search::{ExtendedSearch, Facet, Sort}; |
| 4 | + |
| 5 | +#[tokio::test] |
| 6 | +async fn get_valid_project() -> modrinth_api::Result<()> { |
| 7 | + let api = ModrinthAPI::default(); |
| 8 | + // HVnmMxH1 -> Complementary Shaders - Reimagined |
| 9 | + let response = api.get_project_by_id("HVnmMxH1").await?; |
| 10 | + assert_eq!(response.title, "Complementary Shaders - Reimagined"); |
| 11 | + Ok(()) |
| 12 | +} |
| 13 | + |
| 14 | +#[tokio::test] |
| 15 | +async fn asrt_slug_error() -> modrinth_api::Result<()> { |
| 16 | + let api = ModrinthAPI::default(); |
| 17 | + let response = api.get_project_by_id("dffdsfdsfsdfdsf").await; |
| 18 | + assert!(response.is_err()); |
| 19 | + Ok(()) |
| 20 | +} |
| 21 | + |
| 22 | +#[tokio::test] |
| 23 | +async fn search_project() -> modrinth_api::Result<()> { |
| 24 | + let api = ModrinthAPI::default(); |
| 25 | + let response = api |
| 26 | + .search( |
| 27 | + "xaeros", |
| 28 | + &Sort::Downloads, |
| 29 | + None, |
| 30 | + Some(ExtendedSearch { |
| 31 | + offset: None, |
| 32 | + facets: vec![vec![Facet::ProjectType(ProjectType::Mod)]], |
| 33 | + }), |
| 34 | + ) |
| 35 | + .await?; |
| 36 | + |
| 37 | + let response = response.hits.first().unwrap(); |
| 38 | + let title = response.slug.as_ref(); |
| 39 | + |
| 40 | + assert!(title.is_some()); |
| 41 | + assert_eq!(title.ok_or(0), Ok(&String::from("xaeros-minimap"))); |
| 42 | + Ok(()) |
| 43 | +} |
| 44 | + |
| 45 | +#[tokio::test] |
| 46 | +async fn test_fetching_project_with_mut() -> modrinth_api::Result<()> { |
| 47 | + let api = ModrinthAPI::default(); |
| 48 | + let response = api |
| 49 | + .search( |
| 50 | + "xaeros", |
| 51 | + &Sort::Downloads, |
| 52 | + None, |
| 53 | + Some(ExtendedSearch { |
| 54 | + offset: None, |
| 55 | + facets: vec![vec![Facet::ProjectType(ProjectType::Mod)]], |
| 56 | + }), |
| 57 | + ) |
| 58 | + .await?; |
| 59 | + |
| 60 | + let response = response.hits.first().unwrap(); |
| 61 | + let title = response.slug.as_ref(); |
| 62 | + |
| 63 | + assert!(title.is_some()); |
| 64 | + assert_eq!(title.ok_or(0), Ok(&String::from("xaeros-minimap"))); |
| 65 | + |
| 66 | + let hit = response.to_owned().fetch_project(&api).await?; |
| 67 | + |
| 68 | + assert_eq!(hit.slug.as_ref().unwrap(), &String::from("xaeros-minimap")); |
| 69 | + Ok(()) |
| 70 | +} |
| 71 | + |
| 72 | +#[tokio::test] |
| 73 | +async fn test_fetching_project_without_mut() -> modrinth_api::Result<()> { |
| 74 | + let api = ModrinthAPI::default(); |
| 75 | + let response = api |
| 76 | + .search( |
| 77 | + "xaeros", |
| 78 | + &Sort::Downloads, |
| 79 | + None, |
| 80 | + Some(ExtendedSearch { |
| 81 | + offset: None, |
| 82 | + facets: vec![vec![Facet::ProjectType(ProjectType::Mod)]], |
| 83 | + }), |
| 84 | + ) |
| 85 | + .await?; |
| 86 | + |
| 87 | + let response = response.hits.first().unwrap(); |
| 88 | + let title = response.slug.as_ref(); |
| 89 | + |
| 90 | + assert!(title.is_some()); |
| 91 | + assert_eq!(title.ok_or(0), Ok(&String::from("xaeros-minimap"))); |
| 92 | + |
| 93 | + let hit = response.get_full_project(&api).await?; |
| 94 | + |
| 95 | + assert_eq!(hit.slug, String::from("xaeros-minimap")); |
| 96 | + Ok(()) |
| 97 | +} |
0 commit comments