From 4bdc0f9d024dec7c94974a130465aeff8b9601e3 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 30 Jun 2023 15:40:51 +0100 Subject: [PATCH] feat: add tests for displayed_answer_options --- .../lettings/questions/location_id_spec.rb | 12 +++++++ .../form/lettings/questions/scheme_id_spec.rb | 34 ++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/spec/models/form/lettings/questions/location_id_spec.rb b/spec/models/form/lettings/questions/location_id_spec.rb index dae6db3f1..ba3358e02 100644 --- a/spec/models/form/lettings/questions/location_id_spec.rb +++ b/spec/models/form/lettings/questions/location_id_spec.rb @@ -80,6 +80,18 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do end end + context "and all but one of the locations have a startdate more than 2 weeks in the future" do + before do + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 13)) + FactoryBot.create(:location, scheme:, startdate: Time.utc(2023, 1, 1)) + lettings_log.update!(scheme:) + end + + it "the displayed_answer_options shows the locations" do + expect(question.displayed_answer_options(lettings_log).count).to eq(1) + end + end + context "and the locations have no startdate" do before do FactoryBot.create(:location, scheme:, startdate: nil) diff --git a/spec/models/form/lettings/questions/scheme_id_spec.rb b/spec/models/form/lettings/questions/scheme_id_spec.rb index 0b7c8da96..140b23020 100644 --- a/spec/models/form/lettings/questions/scheme_id_spec.rb +++ b/spec/models/form/lettings/questions/scheme_id_spec.rb @@ -90,13 +90,37 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do end context "when a scheme with at least 1 location exists" do - before do - FactoryBot.create(:location, scheme:) + context "when the location is active" do + before do + FactoryBot.create(:location, startdate: Time.zone.yesterday, scheme:) + end + + it "has the correct answer_options based on the schemes the user's organisation owns or manages" do + expected_answer = { "" => "Select an option", scheme.id.to_s => scheme } + expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer) + end end - it "has the correct answer_options based on the schemes the user's organisation owns or manages" do - expected_answer = { "" => "Select an option", scheme.id.to_s => scheme } - expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer) + context "when the location is activating soon" do + before do + FactoryBot.create(:location, startdate: Time.zone.tomorrow, scheme:) + end + + it "has the correct answer_options based on the schemes the user's organisation owns or manages" do + expected_answer = { "" => "Select an option", scheme.id.to_s => scheme } + expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer) + end + end + + context "when the location is activating more than 2 weeks in the future" do + before do + FactoryBot.create(:location, startdate: Time.zone.today + 3.weeks, scheme:) + end + + it "has the correct answer_options based on the schemes the user's organisation owns or manages" do + expected_answer = { "" => "Select an option" } + expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer) + end end end