Browse Source

Filter out active periods

pull/1007/head
Kat 4 years ago
parent
commit
3877e48649
  1. 3
      app/helpers/locations_helper.rb
  2. 13
      spec/helpers/locations_helper_spec.rb

3
app/helpers/locations_helper.rb

@ -52,8 +52,9 @@ module LocationsHelper
active_periods << ActivePeriod.new(deactivation.reactivation_date, nil)
end
filtered_active_periods = active_periods.select {|period| period.to.nil? || (period.from.present? && period.from <= period.to)}
availability = ""
active_periods.each do |period|
filtered_active_periods.each do |period|
if period.from.present?
availability << "\nActive from #{period.from.to_formatted_s(:govuk_date)}"
availability << " to #{(period.to - 1.day).to_formatted_s(:govuk_date)}\nDeactivated on #{period.to.to_formatted_s(:govuk_date)}" if period.to.present?

13
spec/helpers/locations_helper_spec.rb

@ -154,6 +154,19 @@ RSpec.describe LocationsHelper do
end
end
end
context "with intersecting deactivations" do
before do
location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1))
location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11))
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end
end
end
end
end

Loading…
Cancel
Save