Commit dbafd0e2 authored by Peter van der meulen's avatar Peter van der meulen

Rename day_forecast to forecast

parent d19807cb
defmodule AuroraBot.DayForecast do
defmodule AuroraBot.Forecast do
@moduledoc """
Day Forecasts
......@@ -7,13 +7,13 @@ defmodule AuroraBot.DayForecast do
would start.
"""
alias AuroraBot.DayForecast.NOAAPlanetaryKForecast
alias AuroraBot.Forecast.NOAAPlanetaryKForecast
alias __MODULE__
defstruct datetime: nil, kp: nil
@doc """
Returns an array of DayForecast objects where for each day the highest kp is
Returns an array of Forecast objects where for each day the highest kp is
provided at a specific time between 19:00 and 00:00 UTC
"""
def get! do
......@@ -39,6 +39,6 @@ defmodule AuroraBot.DayForecast do
defp group_to_struct(records) do
selected = Enum.sort_by(records, fn record -> record.kp end, &>=/2) |> List.first()
struct(DayForecast, selected)
struct(Forecast, selected)
end
end
defmodule AuroraBot.DayForecast.NOAAPlanetaryKForecast do
defmodule AuroraBot.Forecast.NOAAPlanetaryKForecast do
@moduledoc """
NOAA Planetary forecasts
......
defmodule DayForecastSpec do
defmodule ForecastSpec do
use ESpec
alias AuroraBot.DayForecast
alias AuroraBot.Forecast
describe "get" do
it "returns no records when none have kp beyond 4" do
mock_noaa_request(4, 3, "2018-11-16 18:00:00", "2018-11-16 21:00:00")
expect DayForecast.get!() |> to(eq [])
expect Forecast.get!() |> to(eq [])
end
it "returns the highest kp when multiple have kp beyond 4 on same day" do
mock_noaa_request(5, 6, "2018-11-16 18:00:00", "2018-11-16 21:00:00")
expected = %DayForecast{datetime: ~N[2018-11-16 21:00:00], kp: 6}
expect DayForecast.get!() |> to(eq [expected])
expected = %Forecast{datetime: ~N[2018-11-16 21:00:00], kp: 6}
expect Forecast.get!() |> to(eq [expected])
end
it "returns 2 objects when 2 days have kp beyond 4" do
mock_noaa_request(5, 6, "2018-11-16 18:00:00", "2018-11-17 21:00:00")
expected1 = %DayForecast{datetime: ~N[2018-11-16 18:00:00], kp: 5}
expected2 = %DayForecast{datetime: ~N[2018-11-17 21:00:00], kp: 6}
expect DayForecast.get!() |> to(eq [expected1, expected2])
expected1 = %Forecast{datetime: ~N[2018-11-16 18:00:00], kp: 5}
expected2 = %Forecast{datetime: ~N[2018-11-17 21:00:00], kp: 6}
expect Forecast.get!() |> to(eq [expected1, expected2])
end
it "returns no records when times are before 18:00" do
mock_noaa_request(5, 6, "2018-11-16 17:00:00", "2018-11-17 16:00:00")
expect DayForecast.get!() |> to(eq [])
expect Forecast.get!() |> to(eq [])
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment