diff --git a/app/models/travel_advice.rb b/app/models/travel_advice.rb index 2bd2f1e34f..d32d8277e5 100644 --- a/app/models/travel_advice.rb +++ b/app/models/travel_advice.rb @@ -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 @@ -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 diff --git a/spec/models/travel_advice_spec.rb b/spec/models/travel_advice_spec.rb new file mode 100644 index 0000000000..4db748aec8 --- /dev/null +++ b/spec/models/travel_advice_spec.rb @@ -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