Skip to content

Commit

Permalink
Set temperature in API fixtures for forecasts
Browse files Browse the repository at this point in the history
  • Loading branch information
edavey committed Oct 7, 2024
1 parent 41a8645 commit fe168d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
15 changes: 9 additions & 6 deletions spec/feature_steps/forecast_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ def given_a_forecast_for_today
forecasts << Fixtures::API.build_forecast(
day: :today,
air_pollution_status: :high,
pollen: 4
pollen: 4,
temperature: :cold
)
end

def and_a_forecast_for_tomorrow
forecasts << Fixtures::API.build_forecast(
day: :tomorrow,
air_pollution_status: :moderate,
pollen: 5
pollen: 5,
temperature: :normal
)
end

def and_a_forecast_for_the_day_after_tomorrow
forecasts << Fixtures::API.build_forecast(
day: :day_after_tomorrow,
air_pollution_status: :very_high,
pollen: 6
pollen: 6,
temperature: :hot
)
end

Expand Down Expand Up @@ -63,9 +66,9 @@ def and_i_see_predicted_pollen_level_for_each_day
end

def and_i_see_predicted_temperature_for_each_day
expect_prediction(day: :today, category: :temperature, value: "1-2°C")
expect_prediction(day: :tomorrow, category: :temperature, value: "3-4°C")
expect_prediction(day: :day_after_tomorrow, category: :temperature, value: "5-6°C")
expect_prediction(day: :today, category: :temperature, value: "-5-4°C")
expect_prediction(day: :tomorrow, category: :temperature, value: "9-16°C")
expect_prediction(day: :day_after_tomorrow, category: :temperature, value: "27-31°C")
end

def expect_prediction(day:, category:, value:)
Expand Down
32 changes: 29 additions & 3 deletions spec/fixtures/api/forecasts.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fixtures
module API
class << self
def build_forecast(day:, air_pollution_status:, pollen: 4)
def build_forecast(day:, air_pollution_status:, pollen: 4, temperature: :normal)
<<~JSON
{
"NO2": 1,
Expand All @@ -14,8 +14,8 @@ def build_forecast(day:, air_pollution_status:, pollen: 4)
"pollution_version": 202410011407,
"rain_am": 1.31,
"rain_pm": 3.01,
"temp_max": 14.0,
"temp_min": 10.4,
"temp_max": #{max_temp_for(temperature)},
"temp_min": #{min_temp_for(temperature)},
"total": "#{total_for(air_pollution_status)}",
"total_status": "#{total_status_for(air_pollution_status)}",
"uv": 1,
Expand All @@ -25,6 +25,32 @@ def build_forecast(day:, air_pollution_status:, pollen: 4)
JSON
end

def min_temp_for(temperature)
case temperature
when :cold
-5.2
when :normal
8.9
when :hot
26.9
else
raise "temperature: #{temperature} not expected"
end
end

def max_temp_for(temperature)
case temperature
when :cold
3.6
when :normal
16.4
when :hot
31.1
else
raise "temperature: #{temperature} not expected"
end
end

def forecast_date_for(day)
date = case day
when :today
Expand Down

0 comments on commit fe168d0

Please sign in to comment.