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. 16
      spec/models/form/sales/pages/living_before_purchase_spec.rb
  4. 42
      spec/models/form/sales/questions/living_before_purchase_spec.rb
  5. 59
      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) def initialize(id, hsh, page)
super super
@id = "proplen_asked" @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?" @header = "Did the buyer live in the property before purchasing it?"
@hint_text = nil @hint_text = nil
@type = "radio" @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_5"
t.integer "details_known_6" t.integer "details_known_6"
t.integer "saledate_check" t.integer "saledate_check"
t.integer "staircasesale"
t.integer "prevshared" t.integer "prevshared"
t.integer "proplen_asked" t.integer "proplen_asked"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"

16
spec/models/form/sales/pages/living_before_purchase_spec.rb

@ -11,9 +11,25 @@ RSpec.describe Form::Sales::Pages::LivingBeforePurchase, type: :model do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
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 it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[proplen]) expect(page.questions.map(&:id)).to eq(%w[proplen])
end 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 it "has the correct id" do
expect(page.id).to eq(nil) expect(page.id).to eq(nil)

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

59
spec/models/form/sales/questions/living_before_purchase_years_spec.rb

@ -5,7 +5,11 @@ RSpec.describe Form::Sales::Questions::LivingBeforePurchaseYears, type: :model d
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { 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:) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -55,3 +59,56 @@ RSpec.describe Form::Sales::Questions::LivingBeforePurchaseYears, type: :model d
expect(question.max).to eq(80) expect(question.max).to eq(80)
end end
end end
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