From ab9a73075408ced3822f6d8a1b97f8f06c3e615b Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 13 Feb 2023 16:25:53 +0000 Subject: [PATCH] tests: add tests for year dependent behaviour --- .../sales/questions/living_before_purchase.rb | 2 +- db/schema.rb | 1 - .../pages/living_before_purchase_spec.rb | 20 ++- .../questions/living_before_purchase_spec.rb | 42 ++++++ .../living_before_purchase_years_spec.rb | 127 +++++++++++++----- 5 files changed, 153 insertions(+), 39 deletions(-) create mode 100644 spec/models/form/sales/questions/living_before_purchase_spec.rb diff --git a/app/models/form/sales/questions/living_before_purchase.rb b/app/models/form/sales/questions/living_before_purchase.rb index 18b8fae37..f631220dc 100644 --- a/app/models/form/sales/questions/living_before_purchase.rb +++ b/app/models/form/sales/questions/living_before_purchase.rb @@ -2,7 +2,7 @@ class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question def initialize(id, hsh, page) super @id = "proplen_asked" - @check_answer_label = "Did the buyer live in the property before purchasing it?" + @check_answer_label = "Buyer lived in the property before purchasing" @header = "Did the buyer live in the property before purchasing it?" @hint_text = nil @type = "radio" diff --git a/db/schema.rb b/db/schema.rb index 25af4951f..1c8e30afd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -524,7 +524,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_140932) do t.integer "details_known_5" t.integer "details_known_6" t.integer "saledate_check" - t.integer "staircasesale" t.integer "prevshared" t.integer "proplen_asked" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" diff --git a/spec/models/form/sales/pages/living_before_purchase_spec.rb b/spec/models/form/sales/pages/living_before_purchase_spec.rb index 435229831..76dbd7609 100644 --- a/spec/models/form/sales/pages/living_before_purchase_spec.rb +++ b/spec/models/form/sales/pages/living_before_purchase_spec.rb @@ -11,8 +11,24 @@ RSpec.describe Form::Sales::Pages::LivingBeforePurchase, type: :model do expect(page.subsection).to eq(subsection) end - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[proplen]) + describe "questions" do + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + + context "when 2022" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[proplen]) + end + end + + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[proplen_asked proplen]) + end + end end it "has the correct id" do diff --git a/spec/models/form/sales/questions/living_before_purchase_spec.rb b/spec/models/form/sales/questions/living_before_purchase_spec.rb new file mode 100644 index 000000000..530bb151a --- /dev/null +++ b/spec/models/form/sales/questions/living_before_purchase_spec.rb @@ -0,0 +1,42 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::LivingBeforePurchase, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("proplen_asked") + end + + it "has the correct header" do + expect(question.header).to eq("Did the buyer live in the property before purchasing it?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer lived in the property before purchasing") + 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 + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq("0" => { "value" => "Yes" }, + "1" => { "value" => "No" }) + end +end diff --git a/spec/models/form/sales/questions/living_before_purchase_years_spec.rb b/spec/models/form/sales/questions/living_before_purchase_years_spec.rb index 0176eb96c..5fdb5ccba 100644 --- a/spec/models/form/sales/questions/living_before_purchase_years_spec.rb +++ b/spec/models/form/sales/questions/living_before_purchase_years_spec.rb @@ -5,53 +5,110 @@ RSpec.describe Form::Sales::Questions::LivingBeforePurchaseYears, type: :model d let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:page) { instance_double(Form::Page, subsection:) } - it "has correct page" do - expect(question.page).to eq(page) - end + context "when 2022" do + let(:start_date) { Time.utc(2022, 2, 8) } - it "has the correct id" do - expect(question.id).to eq("proplen") - end + it "has correct page" do + expect(question.page).to eq(page) + end - it "has the correct header" do - expect(question.header).to eq("How long did the buyer(s) live in the property before purchase?") - end + it "has the correct id" do + expect(question.id).to eq("proplen") + end - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Number of years living in the property before purchase") - end + it "has the correct header" do + expect(question.header).to eq("How long did the buyer(s) live in the property before purchase?") + end - it "has the correct type" do - expect(question.type).to eq("numeric") - end + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Number of years living in the property before purchase") + end - it "is not marked as derived" do - expect(question.derived?).to be false - end + it "has the correct type" do + expect(question.type).to eq("numeric") + end - it "has the correct hint" do - expect(question.hint_text).to eq("You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'") - end + it "is not marked as derived" do + expect(question.derived?).to be false + end - it "has correct width" do - expect(question.width).to eq(5) - end + it "has the correct hint" do + expect(question.hint_text).to eq("You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'") + end - it "has correct step" do - expect(question.step).to eq(1) - end + it "has correct width" do + expect(question.width).to eq(5) + end - it "has correct suffix" do - expect(question.suffix).to eq(" years") - end + it "has correct step" do + expect(question.step).to eq(1) + end + + it "has correct suffix" do + expect(question.suffix).to eq(" years") + end + + it "has correct min" do + expect(question.min).to eq(0) + end - it "has correct min" do - expect(question.min).to eq(0) + it "has correct max" do + expect(question.max).to eq(80) + end end - it "has correct max" do - expect(question.max).to eq(80) + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("proplen") + end + + it "has the correct header" do + expect(question.header).to eq("How long did they live there?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Number of years living in the property before purchase") + end + + it "has the correct type" do + expect(question.type).to eq("numeric") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to eq("You should round up to the nearest year") + end + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct step" do + expect(question.step).to eq(1) + end + + it "has correct suffix" do + expect(question.suffix).to eq(" years") + end + + it "has correct min" do + expect(question.min).to eq(0) + end + + it "has correct max" do + expect(question.max).to eq(80) + end end end