Commit 89abff56 authored by Peter van der meulen's avatar Peter van der meulen

Fix up the specs a bit

parent 5e1d79bf
locals_without_parens = [
## Test setup
before: 1,
configure: 1,
before_all: 1,
after_all: 1,
finally: 1,
......
......@@ -3,10 +3,11 @@ defmodule AuroraBot.Forecast do
Day Forecasts
This module downloads data from [WIP] and checks at what time the likelyhood
of seeing an aurora is the best and at which time bigger auroral activity
of seeing an aurora is the best and at which time bigger auroral activity
would start.
"""
alias AuroraBot.Cache
alias AuroraBot.Forecast.NOAAPlanetaryKForecast
alias __MODULE__
......@@ -23,6 +24,15 @@ defmodule AuroraBot.Forecast do
"""
def get! do
Cache.fetch!(
:base,
"noaa-planetary-k-forecast",
fn -> get_uncached!() end,
ttl: :timer.seconds(30)
)
end
defp get_uncached! do
NOAAPlanetaryKForecast.get!()
|> Enum.filter(&in_timezone_and_strong?(&1))
|> group_per_day()
......
......@@ -2,6 +2,8 @@ defmodule ForecastSpec do
use ESpec
alias AuroraBot.Forecast
before do: mock_cache()
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")
......@@ -31,6 +33,10 @@ defmodule ForecastSpec do
end
end
def mock_cache do
allow(AuroraBot.Cache |> to(accept(:fetch!, fn _, _, fallback, _ -> fallback.() end)))
end
def mock_noaa_request(kp1, kp2, time_tag1, time_tag2) do
response = %HTTPoison.Response{
status_code: 200,
......
......@@ -2,9 +2,7 @@ defmodule LiveMetricsSpec do
use ESpec
alias AuroraBot.LiveMetrics
before do
mock_cache()
end
before do: mock_cache()
describe "get_kiruna_mag_graph" do
it "returns a block of numbers" do
......
......@@ -21,11 +21,11 @@ defmodule ReportSpec do
end
end
def mock_cache do
defp mock_cache do
allow(AuroraBot.Cache |> to(accept(:fetch!, fn _, _, fallback, _ -> fallback.() end)))
end
def mock_requests do
defp mock_requests do
mag_graph_response = %HTTPoison.Response{
status_code: 200,
body: "9.458 610.0 -4.5 30.4\n9.458 610.0 -4.5 30.4\n9.458 610.0 -4.5 30.4\n"
......@@ -57,7 +57,7 @@ defmodule ReportSpec do
)
end
def mock_file_store do
defp mock_file_store do
allow File
|> to(
accept(:write!, fn
......@@ -67,15 +67,15 @@ defmodule ReportSpec do
)
end
def mock_slack_report_cache_get do
defp mock_slack_report_cache_get do
allow Cachex |> to(accept(:get!, fn :base, "slack-report" -> nil end))
end
def mock_slack_report_cache_put do
defp mock_slack_report_cache_put do
allow Cachex |> to(accept(:put!, fn :base, "slack-report", _, _ -> true end))
end
def mock_time do
defp mock_time do
allow Timex
|> to(
accept(:now, fn :utc ->
......
......@@ -2,9 +2,7 @@ defmodule WeatherSpec do
use ESpec
alias AuroraBot.Weather
before do
mock_cache()
end
before do: mock_cache()
describe "get_clouds_in_city" do
it "returns the percentage of clouds for a city" do
......@@ -33,6 +31,6 @@ defmodule WeatherSpec do
end
def mock_cache do
allow(AuroraBot.Cache |> to(accept(:fetch!, fn _, _, fallback, _ -> fallback.() end)))
allow AuroraBot.Cache |> to(accept(:fetch!, fn _, _, fallback, _ -> fallback.() end))
end
end
ESpec.configure(fn _config ->
nil
# config.before fn(tags) ->
# {:shared, hello: :world, tags: tags}
# end
# config.finally fn(_shared) ->
# :ok
# end
ESpec.configure(fn config ->
config.before(fn ->
nil
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