Skip to content

Commit

Permalink
Fix up to: Add alert statuses to TravelAdvice model
Browse files Browse the repository at this point in the history
  • Loading branch information
leenagupte committed Sep 10, 2024
1 parent 759bf03 commit 24854fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/models/travel_advice.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class TravelAdvice < ContentItem
ALERT_STATUSES = %w[
avoid_all_but_essential_travel_to_parts
avoid_all_travel_to_parts
avoid_all_but_essential_travel_to_whole_country
avoid_all_travel_to_whole_country
].freeze

def country_name
content_store_response["details"]["country"]["name"]
end
Expand All @@ -23,14 +30,7 @@ def alert_status
alert_statuses = content_store_response["details"]["alert_status"]
return [] if alert_statuses.blank?

allowed_statuses = %w[
avoid_all_but_essential_travel_to_parts
avoid_all_travel_to_parts
avoid_all_but_essential_travel_to_whole_country
avoid_all_travel_to_whole_country
]

alert_statuses.filter_map { |alert| alert if allowed_statuses.include?(alert) }
alert_statuses.filter_map { |alert| alert if ALERT_STATUSES.include?(alert) }
end

def change_description
Expand Down
22 changes: 22 additions & 0 deletions spec/models/travel_advice_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
RSpec.describe TravelAdvice do
before do
@content_store_response = GovukSchemas::Example.find("travel_advice", example_name: "full-country")
@base_path = @content_store_response.fetch("base_path")
end

describe "#alert_status" do
it "adds allowed statuses" do
@content_store_response["details"]["alert_status"] = [described_class::ALERT_STATUSES.first]

alert_statuses = described_class.new(@content_store_response).alert_status
expect(alert_statuses).to eq([described_class::ALERT_STATUSES.first])
end

it "removes unexpected statuses" do
@content_store_response["details"]["alert_status"] = %w[unexpected-status]

alert_statuses = described_class.new(@content_store_response).alert_status
expect(alert_statuses).to be_empty
end
end
end

0 comments on commit 24854fe

Please sign in to comment.