1pub mod openweather;
2pub mod models;
3pub mod units;
4
5pub use openweather::OpenWeather;
6pub use models::*;
7pub use units::Units;
8
9#[cfg(test)]
10mod test {
11 use super::openweather::{OpenWeather, Units};
12 use std::env;
13 use dotenv::dotenv;
14
15 #[tokio::test]
16 async fn get_by_city() -> Result<(), Box<dyn std::error::Error>> {
17 dotenv().expect("No env file found");
18 let token = env::var("OPENWEATHER_API_KEY").unwrap();
19 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
20 let temp = weather.get_by_city("Tokyo").await?;
21 Ok(())
22 }
23
24 #[tokio::test]
25 async fn get_by_city_and_country() -> Result<(), Box<dyn std::error::Error>> {
26 dotenv().expect("No env file found");
27 let token = env::var("OPENWEATHER_API_KEY").unwrap();
28 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
29 let temp = weather.get_by_city_and_country("Tokyo", "Japan").await?;
30 Ok(())
31 }
32
33 #[tokio::test]
34 async fn get_by_coordinates() -> Result<(), Box<dyn std::error::Error>> {
35 dotenv().expect("No env file found");
36 let token = env::var("OPENWEATHER_API_KEY").unwrap();
37 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
38 let temp = weather.get_by_coordinates(56.0, 12.0).await?;
39 Ok(())
40 }
41
42 #[tokio::test]
43 async fn get_by_zipcode() -> Result<(), Box<dyn std::error::Error>> {
44 dotenv().expect("No env file found");
45 let token = env::var("OPENWEATHER_API_KEY").unwrap();
46 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
47 let temp = weather.get_by_zipcode(80918, "US").await?;
48 Ok(())
49 }
50
51 #[tokio::test]
52 async fn get_by_cities_in_zone() -> Result<(), Box<dyn std::error::Error>> {
53 dotenv().expect("No env file found");
54 let token = env::var("OPENWEATHER_API_KEY").unwrap();
55 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
56 weather.get_by_cities_in_zone(12.0, 32.0, 15.0, 37.0, 10).await?;
57 Ok(())
58 }
59
60 #[tokio::test]
61 async fn get_by_cities_in_cycle() -> Result<(), Box<dyn std::error::Error>> {
62 dotenv().expect("No env file found");
63 let token = env::var("OPENWEATHER_API_KEY").unwrap();
64 let weather: OpenWeather = OpenWeather::new(&token, Units::Metric).await?;
65 weather.get_by_cities_in_cycle(12.0, 32.0, 3).await?;
66 Ok(())
67 }
68
69}