Browse Source

Fix specs

pull/1025/head
Jack S 4 years ago
parent
commit
2b8ce1cab9
  1. 15
      app/models/form/sales/pages/buyer1_mortgage.rb
  2. 16
      app/models/form/sales/questions/buyer1_mortgage.rb
  3. 1
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  4. 33
      spec/models/form/sales/pages/buyer1_mortgage_spec.rb
  5. 40
      spec/models/form/sales/questions/buyer1_mortgage_spec.rb
  6. 2
      spec/models/form/sales/sections/finances_spec.rb
  7. 1
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  8. 4
      spec/models/form_handler_spec.rb

15
app/models/form/sales/pages/buyer1_mortgage.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer1Mortgage < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_mortgage"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1Mortgage.new(nil, nil, self),
]
end
end

16
app/models/form/sales/questions/buyer1_mortgage.rb

@ -0,0 +1,16 @@
class Form::Sales::Questions::Buyer1Mortgage < ::Form::Question
def initialize(id, hsh, page)
super
@id = "inc1mort"
@check_answer_label = "Buyer 1's income used for mortgage application"
@header = "Was buyer 1's income used for a mortgage application"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

1
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -10,6 +10,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
Form::Sales::Pages::Buyer1Income.new(nil, nil, self), Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self),
] ]
end end
end end

33
spec/models/form/sales/pages/buyer1_mortgage_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1Mortgage, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[inc1mort])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_mortgage")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

40
spec/models/form/sales/questions/buyer1_mortgage_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1Mortgage, 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("inc1mort")
end
it "has the correct header" do
expect(question.header).to eq("Was buyer 1's income used for a mortgage application")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's income used for mortgage application")
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 answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
end

2
spec/models/form/sales/sections/finances_spec.rb

@ -14,7 +14,7 @@ RSpec.describe Form::Sales::Sections::Finances, type: :model do
it "has correct subsections" do it "has correct subsections" do
expect(section.subsections.map(&:id)).to eq( expect(section.subsections.map(&:id)).to eq(
%w[ %w[
income_benefits_and_outgoings income_benefits_and_savings
], ],
) )
end end

1
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.pages.map(&:id)).to eq( expect(subsection.pages.map(&:id)).to eq(
%w[ %w[
buyer_1_income buyer_1_income
buyer_1_mortgage
], ],
) )
end end

4
spec/models/form_handler_spec.rb

@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(44) expect(form.pages.count).to eq(45)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(44) expect(form.pages.count).to eq(45)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

Loading…
Cancel
Save