pub mod client;
pub mod error;
pub mod models;
pub use client::{DEFAULT_BASE_URL, MindatClient, MindatClientBuilder};
pub use error::{MindatError, Result};
pub use models::*;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_client_creation() {
let client = MindatClient::new("test-token");
assert_eq!(client.base_url().as_str(), "https://api.mindat.org/v1/");
}
#[test]
fn test_anonymous_client() {
let client = MindatClient::anonymous();
assert_eq!(client.base_url().as_str(), "https://api.mindat.org/v1/");
}
#[test]
fn test_geomaterials_query_builder() {
let query = GeomaterialsQuery::new()
.name("quartz")
.ima_approved(true)
.with_elements("Si,O")
.hardness_range(6.0, 7.0)
.page(1)
.page_size(50);
assert_eq!(query.name, Some("quartz".to_string()));
assert_eq!(query.ima, Some(true));
assert_eq!(query.elements_inc, Some("Si,O".to_string()));
assert_eq!(query.hardness_min, Some(6.0));
assert_eq!(query.hardness_max, Some(7.0));
assert_eq!(query.page, Some(1));
assert_eq!(query.page_size, Some(50));
}
#[test]
fn test_localities_query_builder() {
let query = LocalitiesQuery::new()
.country("Brazil")
.with_elements("Au")
.select_fields("id,txt,country");
assert_eq!(query.country, Some("Brazil".to_string()));
assert_eq!(query.elements_inc, Some("Au".to_string()));
assert_eq!(query.fields, Some("id,txt,country".to_string()));
}
#[test]
fn test_paginated_response() {
let response: PaginatedResponse<i32> = PaginatedResponse {
count: Some(150),
next: Some("https://api.mindat.org/geomaterials/?page=2".to_string()),
previous: None,
results: vec![1, 2, 3],
};
assert!(response.has_next());
assert!(!response.has_previous());
assert_eq!(response.total_pages(50), Some(3));
}
#[test]
fn test_entry_type_from_u8() {
assert_eq!(EntryType::from(0), EntryType::Mineral);
assert_eq!(EntryType::from(1), EntryType::Synonym);
assert_eq!(EntryType::from(2), EntryType::Variety);
assert_eq!(EntryType::from(7), EntryType::Rock);
assert_eq!(EntryType::from(99), EntryType::Mineral); }
#[test]
fn test_geomaterials_ordering_display() {
assert_eq!(GeomaterialsOrdering::Id.to_string(), "id");
assert_eq!(GeomaterialsOrdering::IdDesc.to_string(), "-id");
assert_eq!(GeomaterialsOrdering::Name.to_string(), "name");
}
}