Browse Source

feat: add tests for displayed_answer_options

pull/1739/head
natdeanlewissoftwire 3 years ago
parent
commit
4bdc0f9d02
  1. 12
      spec/models/form/lettings/questions/location_id_spec.rb
  2. 34
      spec/models/form/lettings/questions/scheme_id_spec.rb

12
spec/models/form/lettings/questions/location_id_spec.rb

@ -80,6 +80,18 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do
end end
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 context "and the locations have no startdate" do
before do before do
FactoryBot.create(:location, scheme:, startdate: nil) FactoryBot.create(:location, scheme:, startdate: nil)

34
spec/models/form/lettings/questions/scheme_id_spec.rb

@ -90,13 +90,37 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
end end
context "when a scheme with at least 1 location exists" do context "when a scheme with at least 1 location exists" do
before do context "when the location is active" do
FactoryBot.create(:location, scheme:) 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 end
it "has the correct answer_options based on the schemes the user's organisation owns or manages" do context "when the location is activating soon" do
expected_answer = { "" => "Select an option", scheme.id.to_s => scheme } before do
expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer) 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
end end

Loading…
Cancel
Save