diff --git a/test/get_current_weather_test.exs b/test/get_current_weather_test.exs index fc5e25a..9c346cb 100644 --- a/test/get_current_weather_test.exs +++ b/test/get_current_weather_test.exs @@ -1,185 +1,161 @@ defmodule GetCurrentWeatherTest do use ExUnit.Case - test ": can get weather data with get_current_weather/1 by city name" do - # given - city = %{city: "Bengaluru"} - # when - result = ExOwm.get_current_weather(city) - # then - # check whether a list of maps is returned - assert is_list(result) + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test ":get_current_weather/1 with a city name" do + result = ExOwm.get_current_weather(%{city: "Bengaluru"}) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Bengaluru" end - test ": can get weather data with get_current_weather/1 by city name list" do - # given - city = %{city: "Lucerne"} - # when - result = ExOwm.get_current_weather([city]) - # then - # check whether a list of maps is returned + test ":get_current_weather/1 with a list of cities" do + result = ExOwm.get_current_weather([%{city: "Lucerne"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Lucerne" end - test ": can get weather data with get_current_weather/1 by city name and country code" do - # given - city = %{city: "Munich", countr_code: "de"} - # when - result = ExOwm.get_current_weather([city]) - # then - # check whether a list of maps is returned + test "get_current_weather/1 with a city name and a country code" do + result = ExOwm.get_current_weather([%{city: "Munich", countr_code: "de"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Munich" end - test ": can get weather data with get_current_weather/1 by city id" do - # given - city = %{id: 2_759_794} - # when - result = ExOwm.get_current_weather([city]) - # then - # check whether a list of maps is returned + test ":get_current_weather/1 with a city id" do + result = ExOwm.get_current_weather([%{id: 2_759_794}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end - test ": can get weather data with get_current_weather/1 by latitude and longitude" do - # given - city = %{lat: 52.374031, lon: 4.88969} - # when - result = ExOwm.get_current_weather([city]) - # then - # check whether a list of maps is returned + test "get_current_weather/1 with a latitude and a longitude" do + result = ExOwm.get_current_weather([%{lat: 52.374031, lon: 4.88969}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end - test ": can get weather data with get_current_weather/1 by zip and country code" do - # given - city = %{zip: "94040", country_code: "us"} - # when - result = ExOwm.get_current_weather([city]) - # then - # check whether a list of maps is returned + test "get_current_weather/1 with a zip and a country code" do + result = ExOwm.get_current_weather([%{zip: "94040", country_code: "us"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Mountain View" end - test ": can get weather data with get_current_weather/1 by city name with options" do - # given + test "get_current_weather/1 with a city name and options" do city = %{city: "Warsaw"} options = [units: :metric, lang: :pl] - # when + result = ExOwm.get_current_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Warszawa" end - test ": can get weather data with get_current_weather/1 by city name and country code with options" do - # given + test "get_current_weather/1 with a city name and a country code and options" do city = %{city: "Warsaw", countr_code: "pl"} options = [units: :metric, lang: :pl] - # when + result = ExOwm.get_current_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Warszawa" end - test ": can get weather data with get_current_weather/1 by city id with options" do - # given + test "get_current_weather/1 with a city id and options" do city = %{id: 2_759_794} options = [units: :metric, lang: :pl] - # when + result = ExOwm.get_current_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end - test ": can get weather data with get_current_weather/1 by latitude and longitude with options" do - # given + test "get_current_weather/1 with a latitude and a longitude and options" do city = %{lat: 52.374031, lon: 4.88969} options = [units: :metric, lang: :pl] - # when + result = ExOwm.get_current_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end - test ": can get weather data with get_current_weather/1 by zip and country code with options" do - # given + test "get_current_weather/1 with a zip code, a country code and options" do city = %{zip: "94040", country_code: "us"} options = [units: :metric, lang: :pl] - # when + result = ExOwm.get_current_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful assert Map.get(map, "name") == "Mountain View" end - test ": Parses errors correctly" do - # given - city = %{city: "unknown city, yes, really unknown"} - # when - result = ExOwm.get_current_weather(city) - # then - # check whether a list of maps is returned - assert is_list(result) - assert result != [] - {:error, :not_found, %{"cod" => "404", "message" => "city not found"}} = List.first(result) + test "get_current_weather/1 with non-existing city" do + result = ExOwm.get_current_weather(%{city: "Bonkersville"}) + + assert result == [ + {:error, :not_found, {:ok, %{"cod" => "404", "message" => "city not found"}}} + ] end end diff --git a/test/get_five_day_forecast_test.exs b/test/get_five_day_forecast_test.exs index 6e873a9..9a0490a 100644 --- a/test/get_five_day_forecast_test.exs +++ b/test/get_five_day_forecast_test.exs @@ -1,18 +1,22 @@ defmodule GetFiveDayForecastTest do use ExUnit.Case - test ": can get weather data with get_five_day_forecast/1 by single city name" do - # given - city = %{city: "Sochi"} - # when - result = ExOwm.get_five_day_forecast(city) - # then - # check whether a list of maps is returned + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test "get_five_day_forecast/1 with a single city" do + result = ExOwm.get_five_day_forecast(%{city: "Sochi"}) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -21,18 +25,16 @@ defmodule GetFiveDayForecastTest do assert city_name == "Sochi" end - test ": can get weather data with get_five_day_forecast/1 by city name" do - # given - city = %{city: "Sochi"} - # when - result = ExOwm.get_five_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with city a list of cities" do + result = ExOwm.get_five_day_forecast([%{city: "Sochi"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -41,18 +43,16 @@ defmodule GetFiveDayForecastTest do assert city_name == "Sochi" end - test ": can get weather data with get_five_day_forecast/1 by city name and country code" do - # given - city = %{city: "Warsaw", countr_code: "pl"} - # when - result = ExOwm.get_five_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of cities and country codes" do + result = ExOwm.get_five_day_forecast([%{city: "Warsaw", countr_code: "pl"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -61,18 +61,16 @@ defmodule GetFiveDayForecastTest do assert city_name == "Warsaw" end - test ": can get weather data with get_five_day_forecast/1 by city id" do - # given - city = %{id: 2_759_794} - # when - result = ExOwm.get_five_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of city ids" do + result = ExOwm.get_five_day_forecast([%{id: 2_759_794}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -81,18 +79,16 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_five_day_forecast/1 by latitude and longitude" do - # given - city = %{lat: 4.3942822222, lon: 18.558442503} - # when - result = ExOwm.get_five_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of latitudes and longitudes" do + result = ExOwm.get_five_day_forecast([%{lat: 4.3942822222, lon: 18.558442503}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -101,18 +97,16 @@ defmodule GetFiveDayForecastTest do assert city_name == "Kolongo" end - test ": can get weather data with get_five_day_forecast/1 by zip and country code" do - # given - city = %{zip: "94040", country_code: "us"} - # when - result = ExOwm.get_five_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of zip codes and country codes" do + result = ExOwm.get_five_day_forecast([%{zip: "94040", country_code: "us"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -121,63 +115,58 @@ defmodule GetFiveDayForecastTest do assert city_name == "Mountain View" end - test ": can get weather data with get_five_day_forecast/1 by city name with options" do - # given - city = %{city: "Moscow"} - options = [units: :metric, lang: :ru] - # when - result = ExOwm.get_five_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of city names and options" do + result = ExOwm.get_five_day_forecast([%{city: "Zurich"}], units: :metric, lang: :ch) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") |> Map.get("name") - assert city_name == "Москва" + assert city_name == "Zurich" end - test ": can get weather data with get_five_day_forecast/1 by city name and country code with options" do - # given - city = %{city: "Freiburg", countr_code: "ch"} - options = [units: :metric, lang: :fr] - # when - result = ExOwm.get_five_day_forecast([city], options) - # then - # check whether a list of maps is returned + # Fribourg or Freiburg is a city which exists in multiple countries + test "get_five_day_forecast/1 with a list of city names, country codes and options" do + result = + ExOwm.get_five_day_forecast([%{city: "Freiburg", countr_code: "ch"}], + units: :metric, + lang: :fr + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") |> Map.get("name") - # Fribourg or Freiburg is a city which exists in multiple countries and in multiple languages assert city_name == "Fribourg" assert %{"city" => %{"country" => "CH"}} = map end - test ": can get weather data with get_five_day_forecast/1 by city id with options" do - # given - city = %{id: 2_759_794} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_five_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of city ids and options" do + result = ExOwm.get_five_day_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -186,19 +175,17 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_five_day_forecast/1 by latitude and longitude with options" do - # given - city = %{lat: 52.374031, lon: 4.88969} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_five_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of latitudes, longitudes and options" do + result = + ExOwm.get_five_day_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -207,19 +194,20 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_five_day_forecast/1 by zip and country code with options" do - # given - city = %{zip: "94040", country_code: "us"} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_five_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_five_day_forecast/1 with a list of zip codes, country codes and options" do + result = + ExOwm.get_five_day_forecast([%{zip: "94040", country_code: "us"}], + units: :metric, + lang: :pl + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") diff --git a/test/get_historical_weather_test.exs b/test/get_historical_weather_test.exs index 941ba35..0b5369b 100644 --- a/test/get_historical_weather_test.exs +++ b/test/get_historical_weather_test.exs @@ -1,21 +1,22 @@ defmodule GetHistoricalWeatherTest do use ExUnit.Case - test ": can get historical one call weather data by latitude and longitude" do - # given + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test "get_historical_weather/1 with a list of latitudes and longitudes" do yesterday = DateTime.utc_now() |> DateTime.add(24 * 60 * 60 * -1, :second) |> DateTime.to_unix() - city = %{lat: 52.374031, lon: 4.88969, dt: yesterday} - # when - result = ExOwm.get_historical_weather([city]) - # then - # check whether a list of maps is returned + result = ExOwm.get_historical_weather([%{lat: 52.374031, lon: 4.88969, dt: yesterday}]) + assert is_list(result) assert result != [] {:ok, map} = List.first(result) assert is_map(map) - # check whether map has specific keys to confirm that request was successful # kelvin, we should be fine here assert Map.get(map, "current") |> Map.get("temp") > 200 # The first entry should be smaller than what we asked for because it's midnight. @@ -23,34 +24,33 @@ defmodule GetHistoricalWeatherTest do assert Map.get(map, "hourly") |> Enum.count() == 24 end - test ": can get historical weather data with get_historical_weather/2 by latitude and longitude with options" do - # given + test "get_historical_weather/2 with a list of latitudes and longitudes and options" do yesterday = DateTime.utc_now() |> DateTime.add(24 * 60 * 60 * -1, :second) |> DateTime.to_unix() - city = %{lat: 46.514098, lon: 8.326755, dt: yesterday} - options = [units: :metric, lang: :de] - # when - result = ExOwm.get_historical_weather([city], options) - # then - # check whether a list of maps is returned + result = + ExOwm.get_historical_weather([%{lat: 46.514098, lon: 8.326755, dt: yesterday}], + units: :metric, + lang: :de + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful # Celsius, we should be fine here assert Map.get(map, "current") |> Map.get("temp") < 100 # The first entry should be smaller than what we asked for because it's midnight. assert Map.get(map, "hourly") |> List.first() |> Map.get("dt") < yesterday end - test ": Parses errors correctly" do - # given + test "get_historical_weather/2 with an incorrect coordinates" do city = %{lat: "15", lon: "-2", dt: -200} - # when + result = ExOwm.get_historical_weather(city) - # then + # check whether a list of maps is returned assert is_list(result) assert result != [] diff --git a/test/get_hourly_forecast_test.exs b/test/get_hourly_forecast_test.exs index d442147..0f3cc16 100644 --- a/test/get_hourly_forecast_test.exs +++ b/test/get_hourly_forecast_test.exs @@ -1,18 +1,22 @@ defmodule GetHourlyForecastTest do use ExUnit.Case - test ": can get weather data with get_hourly_forecast/1 by single city name" do - # given - city = %{city: "Sochi"} - # when - result = ExOwm.get_hourly_forecast(city) - # then - # check whether a list of maps is returned + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test "get_hourly_forecast/1 with a city name" do + result = ExOwm.get_hourly_forecast(%{city: "Sochi"}) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -21,18 +25,16 @@ defmodule GetHourlyForecastTest do assert city_name == "Sochi" end - test ": can get weather data with get_hourly_forecast/1 by city name" do - # given - city = %{city: "Sochi"} - # when - result = ExOwm.get_hourly_forecast([city]) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of cities" do + result = ExOwm.get_hourly_forecast([%{city: "Sochi"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -41,18 +43,18 @@ defmodule GetHourlyForecastTest do assert city_name == "Sochi" end - test ": can get weather data with get_hourly_forecast/1 by city name and country code" do - # given + test "get_hourly_forecast/1 with a list of cities and country codes" do city = %{city: "Warsaw", countr_code: "pl"} - # when + result = ExOwm.get_hourly_forecast([city]) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -61,18 +63,16 @@ defmodule GetHourlyForecastTest do assert city_name == "Warsaw" end - test ": can get weather data with get_hourly_forecast/1 by city id" do - # given - city = %{id: 2_759_794} - # when - result = ExOwm.get_hourly_forecast([city]) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of city ids" do + result = ExOwm.get_hourly_forecast([%{id: 2_759_794}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -81,18 +81,16 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_hourly_forecast/1 by latitude and longitude" do - # given - city = %{lat: 4.3942822222, lon: 18.558442503} - # when - result = ExOwm.get_hourly_forecast([city]) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of coordinates" do + result = ExOwm.get_hourly_forecast([%{lat: 4.3942822222, lon: 18.558442503}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -102,18 +100,16 @@ defmodule GetHourlyForecastTest do assert map |> Map.get("list") |> Enum.count() == 96 end - test ": can get weather data with get_hourly_forecast/1 by zip and country code" do - # given - city = %{zip: "94040", country_code: "us"} - # when - result = ExOwm.get_hourly_forecast([city]) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of zip codes and country codes" do + result = ExOwm.get_hourly_forecast([%{zip: "94040", country_code: "us"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -122,40 +118,38 @@ defmodule GetHourlyForecastTest do assert city_name == "Mountain View" end - test ": can get weather data with get_hourly_forecast/1 by city name with options" do - # given - city = %{city: "Moscow"} - options = [units: :metric, lang: :ru] - # when - result = ExOwm.get_hourly_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of cities and options" do + result = ExOwm.get_hourly_forecast([%{city: "Zurich"}], units: :metric, lang: :ch) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") |> Map.get("name") - assert city_name == "Москва" + assert city_name == "Zurich" end - test ": can get weather data with get_hourly_forecast/1 by city name and country code with options" do - # given - city = %{city: "Freiburg", countr_code: "ch"} - options = [units: :metric, lang: :fr] - # when - result = ExOwm.get_hourly_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of cities, country codes and options" do + result = + ExOwm.get_hourly_forecast([%{city: "Freiburg", countr_code: "ch"}], + units: :metric, + lang: :fr + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -166,19 +160,16 @@ defmodule GetHourlyForecastTest do assert %{"city" => %{"country" => "CH"}} = map end - test ": can get weather data with get_hourly_forecast/1 by city id with options" do - # given - city = %{id: 2_759_794} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_hourly_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of city ids and options" do + result = ExOwm.get_hourly_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -187,19 +178,17 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_hourly_forecast/1 by latitude and longitude with options" do - # given - city = %{lat: 52.374031, lon: 4.88969} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_hourly_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of coordinates and options" do + result = + ExOwm.get_hourly_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -208,19 +197,17 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end - test ": can get weather data with get_hourly_forecast/1 by zip and country code with options" do - # given - city = %{zip: "94040", country_code: "us"} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_hourly_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_hourly_forecast/1 with a list of zip codes, country codes and options" do + result = + ExOwm.get_hourly_forecast([%{zip: "94040", country_code: "us"}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") diff --git a/test/get_one_call_weather_test.exs b/test/get_one_call_weather_test.exs index 049b7fb..2011026 100644 --- a/test/get_one_call_weather_test.exs +++ b/test/get_one_call_weather_test.exs @@ -1,46 +1,46 @@ defmodule GetOneCallWeatherTest do use ExUnit.Case - test ": can get one call weather data by latitude and longitude" do - # given - city = %{lat: 52.374031, lon: 4.88969} - # when - result = ExOwm.get_weather([city]) - # then - # check whether a list of maps is returned + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test "get_weather/1 with a list of coordinates" do + result = ExOwm.get_weather([%{lat: 52.374031, lon: 4.88969}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful # kelvin, we should be fine here assert Map.get(map, "current") |> Map.get("temp") > 200 end - test ": can get weather data with get_weather/1 by latitude and longitude with options" do - # given + test "get_weather/1 with a list of coordinates and options" do city = %{lat: 46.514098, lon: 8.326755} options = [units: :metric, lang: :ru] - # when + result = ExOwm.get_weather([city], options) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific keys to confirm that request was successful # Celsius, we should be fine here assert Map.get(map, "current") |> Map.get("temp") < 100 end - test ": Parses errors correctly" do - # given + test "get_weather/1 with an incorrect coordinates" do city = %{lat: "800", lon: "-2"} - # when + result = ExOwm.get_weather(city) - # then - # check whether a list of maps is returned + assert is_list(result) assert result != [] {:error, :not_found, %{"cod" => "400", "message" => "wrong latitude"}} = List.first(result) diff --git a/test/get_sixteen_day_forecast_test.exs b/test/get_sixteen_day_forecast_test.exs index 6bb8b2d..d272763 100644 --- a/test/get_sixteen_day_forecast_test.exs +++ b/test/get_sixteen_day_forecast_test.exs @@ -1,19 +1,22 @@ defmodule GetSixteenDayForecastTest do use ExUnit.Case - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by single city name" do - # given - city = %{city: "Warsaw"} - # when - result = ExOwm.get_sixteen_day_forecast(city) - # then - # check whether a list of maps is returned + setup do + # Introduce a delay of 1 second between each test due to free API key restriction of 60 calls/minute + :timer.sleep(1000) + :ok + end + + test "get_sixteen_day_forecast/1 with a city name" do + result = ExOwm.get_sixteen_day_forecast(%{city: "Warsaw"}) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -22,19 +25,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city name" do - # given - city = %{city: "Warsaw"} - # when - result = ExOwm.get_sixteen_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of cities" do + result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -43,19 +43,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city name and country code" do - # given - city = %{city: "Warsaw", countr_code: "pl"} - # when - result = ExOwm.get_sixteen_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of city names and country codes" do + result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw", countr_code: "pl"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -64,19 +61,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city id" do - # given - city = %{id: 2_759_794} - # when - result = ExOwm.get_sixteen_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of city ids" do + result = ExOwm.get_sixteen_day_forecast([%{id: 2_759_794}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -85,19 +79,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by latitude and longitude" do - # given - city = %{lat: 52.374031, lon: 4.88969} - # when - result = ExOwm.get_sixteen_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of coordinates" do + result = ExOwm.get_sixteen_day_forecast([%{lat: 52.374031, lon: 4.88969}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -106,19 +97,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by zip and country code" do - # given - city = %{zip: "94040", country_code: "us"} - # when - result = ExOwm.get_sixteen_day_forecast([city]) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of zip does and country codes" do + result = ExOwm.get_sixteen_day_forecast([%{zip: "94040", country_code: "us"}]) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -127,20 +115,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Mountain View" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city name with options" do - # given - city = %{city: "Warsaw"} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_sixteen_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of city names and options" do + result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw"}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -149,20 +133,20 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city name and country code with options" do - # given - city = %{city: "Warsaw", countr_code: "pl"} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_sixteen_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of city names, country codes and options" do + result = + ExOwm.get_sixteen_day_forecast([%{city: "Warsaw", countr_code: "pl"}], + units: :metric, + lang: :pl + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -171,20 +155,16 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by city id with options" do - # given - city = %{id: 2_759_794} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_sixteen_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of city ids and options" do + result = ExOwm.get_sixteen_day_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -193,20 +173,17 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by latitude and longitude with options" do - # given - city = %{lat: 52.374031, lon: 4.88969} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_sixteen_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of coordinates and options" do + result = + ExOwm.get_sixteen_day_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city") @@ -215,20 +192,20 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end - @tag :skip - test ": can get weather data with get_sixteen_day_forecast/1 by zip and country code with options" do - # given - city = %{zip: "94040", country_code: "us"} - options = [units: :metric, lang: :pl] - # when - result = ExOwm.get_sixteen_day_forecast([city], options) - # then - # check whether a list of maps is returned + test "get_sixteen_day_forecast/1 with a list of zip codes, country codes and options" do + result = + ExOwm.get_sixteen_day_forecast([%{zip: "94040", country_code: "us"}], + units: :metric, + lang: :pl + ) + assert is_list(result) assert result != [] + {:ok, map} = List.first(result) + assert is_map(map) - # check whether map has specific value to confirm that request was successful + city_name = map |> Map.get("city")