From a4da39c498a6c6c667092a39038459de441655d4 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:36:52 +0000 Subject: [PATCH] feat: update answer options order and test (#2189) --- .../form/lettings/questions/is_carehome.rb | 15 ++++- .../lettings/questions/is_carehome_spec.rb | 67 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 spec/models/form/lettings/questions/is_carehome_spec.rb diff --git a/app/models/form/lettings/questions/is_carehome.rb b/app/models/form/lettings/questions/is_carehome.rb index 9011d35bb..34c40db50 100644 --- a/app/models/form/lettings/questions/is_carehome.rb +++ b/app/models/form/lettings/questions/is_carehome.rb @@ -7,10 +7,21 @@ class Form::Lettings::Questions::IsCarehome < ::Form::Question @type = "radio" @check_answers_card_number = 0 @hint_text = "" - @answer_options = ANSWER_OPTIONS @conditional_for = { "chcharge" => [1] } @question_number = 93 end - ANSWER_OPTIONS = { "0" => { "value" => "No" }, "1" => { "value" => "Yes" } }.freeze + def answer_options + if form.start_year_after_2024? + { + "1" => { "value" => "Yes" }, + "0" => { "value" => "No" }, + }.freeze + else + { + "0" => { "value" => "No" }, + "1" => { "value" => "Yes" }, + }.freeze + end + end end diff --git a/spec/models/form/lettings/questions/is_carehome_spec.rb b/spec/models/form/lettings/questions/is_carehome_spec.rb new file mode 100644 index 000000000..99f13aab0 --- /dev/null +++ b/spec/models/form/lettings/questions/is_carehome_spec.rb @@ -0,0 +1,67 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::IsCarehome, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("is_carehome") + end + + it "has the correct header" do + expect(question.header).to eq("Is this accommodation a care home?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Care home accommodation") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + context "with 2023/24 form" do + it "has the correct answer_options in the correct order" do + expect(question.answer_options.map { |k, v| [k, v["value"]] }).to eq([ + %w[0 No], + %w[1 Yes], + ]) + end + end + + context "with 2024/25 form" do + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has the correct answer_options in the correct order" do + expect(question.answer_options.map { |k, v| [k, v["value"]] }).to eq([ + %w[1 Yes], + %w[0 No], + ]) + end + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(0) + end +end