From 5b27b6fff48915657820759a42d6965a345351cb Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 27 Nov 2023 16:50:28 +0000 Subject: [PATCH] feat: add tests for availability text --- spec/helpers/locations_helper_spec.rb | 29 +++++++++++++++++++++++++++ spec/helpers/schemes_helper_spec.rb | 11 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index da4b17322..56e805c8a 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -214,6 +214,35 @@ RSpec.describe LocationsHelper do expect(availability_attribute).to eq("Active from 1 April 2022") end + + context "when location was merged" do + context "when there is no startdate" do + it "displays merge date as availability date" do + location.update!(merge_date: Time.zone.local(2022, 4, 16)) + availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Active from 16 April 2022") + end + end + + context "when the startdate is before the merge date" do + it "displays merge date as availability date" do + location.update!(startdate: Time.zone.local(2022, 4, 3), merge_date: Time.zone.local(2022, 4, 16)) + availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Active from 16 April 2022") + end + end + + context "when the startdate is after the merge date" do + it "displays startdate as availability date" do + location.update!(startdate: Time.zone.local(2022, 5, 3), merge_date: Time.zone.local(2022, 4, 16)) + availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Active from 3 May 2022") + end + end + end end context "with previous deactivations" do diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index 6aaa10260..7a52230ab 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -303,6 +303,17 @@ RSpec.describe SchemesHelper do expect(display_scheme_attributes(scheme)).to eq(attributes) end end + + context "when scheme was merged from another organisation" do + before do + FactoryBot.create(:location, scheme:) + scheme.merge_date = Time.zone.local(2023, 1, 5) + end + + it "returns correct availability" do + expect(display_scheme_attributes(scheme)).to include({ name: "Availability", value: "Active from 5 January 2023" }) + end + end end describe "edit_scheme_text" do