Browse Source

tests: add tests for year dependent behaviour

pull/1296/head
natdeanlewissoftwire 3 years ago
parent
commit
ab9a730754
  1. 2
      app/models/form/sales/questions/living_before_purchase.rb
  2. 1
      db/schema.rb
  3. 20
      spec/models/form/sales/pages/living_before_purchase_spec.rb
  4. 42
      spec/models/form/sales/questions/living_before_purchase_spec.rb
  5. 127
      spec/models/form/sales/questions/living_before_purchase_years_spec.rb

2
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"

1
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"

20
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

42
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

127
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

Loading…
Cancel
Save