Browse Source
* initial spec file refactor remove create for build, extract form to own variable, remove non-valuable tests run time from 0.29s to0.11s * refactor to ensure that the questions ownershipsch instance variable and the value of ownershipsch on the log is the same in tests * delete page test file which is not testing anything meaningful * add error messages to the I18n yml * update tests for the validations * update validation logic * update tests for the mortgage used question * update the mortgage used question displayed answer options * update bulk upload specs to reflect error message updates * make use of brackets consistent within validation methodpull/2462/head
Arthur Campbell
7 months ago
committed by
GitHub
8 changed files with 193 additions and 145 deletions
@ -1,29 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Mortgageused, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1) } |
||||
|
||||
let(:page_id) { "mortgage_used" } |
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } |
||||
|
||||
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[mortgageused]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("mortgage_used") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
end |
@ -1,85 +1,106 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) } |
||||
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch:) } |
||||
|
||||
let(:ownershipsch) { 1 } |
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } |
||||
let(:log) { create(:sales_log) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } |
||||
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:)) } |
||||
let(:stairowned) { nil } |
||||
let(:staircase) { nil } |
||||
let(:saledate) { Time.zone.today } |
||||
let(:log) { build(:sales_log, :in_progress, ownershipsch:, stairowned:, staircase:) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No" }, |
||||
"3" => { "value" => "Don’t know" }, |
||||
}) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("mortgageused") |
||||
end |
||||
describe "the displayed answer options" do |
||||
context "when it is a discounted ownership sale" do |
||||
let(:ownershipsch) { 2 } |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Was a mortgage used for the purchase of this property?") |
||||
it "does not show the don't know option" do |
||||
expect_the_question_not_to_show_dont_know |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Mortgage used") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("radio") |
||||
context "when it is an outright sale" do |
||||
let(:ownershipsch) { 3 } |
||||
|
||||
context "and the saledate is before 24/25" do |
||||
before do |
||||
allow(form).to receive(:start_year_after_2024?).and_return false |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?(nil)).to be false |
||||
it "does not show the don't know option" do |
||||
expect_the_question_not_to_show_dont_know |
||||
end |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No" }, |
||||
"3" => { "value" => "Don’t know" }, |
||||
}) |
||||
context "and the saledate is 24/25 or after" do |
||||
before do |
||||
allow(form).to receive(:start_year_after_2024?).and_return true |
||||
end |
||||
|
||||
it "has correct conditional for" do |
||||
expect(question.conditional_for).to eq(nil) |
||||
it "shows the don't know option" do |
||||
expect_the_question_to_show_dont_know |
||||
end |
||||
end |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
context "when it is a shared ownership scheme" do |
||||
let(:ownershipsch) { 1 } |
||||
|
||||
context "and it is a staircasing transaction" do |
||||
let(:staircase) { 1 } |
||||
|
||||
context "and stairowned is less that 100" do |
||||
let(:stairowned) { 50 } |
||||
|
||||
it "does not show the don't know option" do |
||||
expect_the_question_not_to_show_dont_know |
||||
end |
||||
end |
||||
|
||||
context "when staircase owned percentage is 100%" do |
||||
let(:log) { build(:sales_log, stairowned: 100) } |
||||
context "and stairowned is 100" do |
||||
let(:stairowned) { 100 } |
||||
|
||||
it "shows the don't know option" do |
||||
expect(question.displayed_answer_options(log)).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No" }, |
||||
"3" => { "value" => "Don’t know" }, |
||||
}) |
||||
expect_the_question_to_show_dont_know |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when an outright sale" do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 3) } |
||||
context "and it is not a staircasing transaction" do |
||||
let(:staircase) { 2 } |
||||
|
||||
it "shows the don't know option" do |
||||
it "does not show the don't know option" do |
||||
expect_the_question_not_to_show_dont_know |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def expect_the_question_not_to_show_dont_know |
||||
expect(question.displayed_answer_options(log)).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No" }, |
||||
"3" => { "value" => "Don’t know" }, |
||||
}) |
||||
end |
||||
end |
||||
|
||||
context "when staircase owned percentage is less than 100%" do |
||||
let(:log) { build(:sales_log, stairowned: 99) } |
||||
|
||||
it "shows the don't know option" do |
||||
def expect_the_question_to_show_dont_know |
||||
expect(question.displayed_answer_options(log)).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No" }, |
||||
"3" => { "value" => "Don’t know" }, |
||||
}) |
||||
end |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue