Browse Source
* feat: add max value check for buyer 1 * feat: add tests and refactor * feat: add buyer 2 value check * feat: combined income value check * feat: add combined validation everywhere and add tests * feat: add max value check for buyer 1 * feat: add tests and refactor * feat: add buyer 2 value check * feat: combined income value check * feat: add combined validation everywhere and add tests * db:update * refactor: lint * db: update * feat: update copy for single validations * feat: add correct answer card numbers * feat: add tests * feat: fix tests * feat: correct uprn address routing not to show when uprn_confirmed is nil * refactor: lint * feat: update tests * feat: make combined_income nil safe * feat: merge with main * test: update * feat: update to new soft val designs * feat: replace la with uprn, postoce_full, la in all interruption_screen_question_ids * feat: update testspull/1630/head
natdeanlewissoftwire
2 years ago
committed by
GitHub
34 changed files with 490 additions and 39 deletions
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Pages::Buyer1IncomeMaxValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection, check_answers_card_number:) |
||||
super(id, hsh, subsection) |
||||
@depends_on = [ |
||||
{ |
||||
"income1_over_soft_max?" => true, |
||||
}, |
||||
] |
||||
@title_text = { |
||||
"translation" => "soft_validations.income.over_soft_max_for_la_buyer_1", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "income1", |
||||
"i18n_template" => "income", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = {} |
||||
@check_answers_card_number = check_answers_card_number |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::Buyer1IncomeValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[uprn postcode_full la income1] |
||||
end |
||||
end |
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Pages::Buyer2IncomeMaxValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection, check_answers_card_number:) |
||||
super(id, hsh, subsection) |
||||
@depends_on = [ |
||||
{ |
||||
"income2_over_soft_max?" => true, |
||||
}, |
||||
] |
||||
@title_text = { |
||||
"translation" => "soft_validations.income.over_soft_max_for_la_buyer_2", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "income2", |
||||
"i18n_template" => "income", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = {} |
||||
@check_answers_card_number = check_answers_card_number |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::Buyer2IncomeValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[uprn postcode_full la income2] |
||||
end |
||||
end |
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Pages::CombinedIncomeMaxValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection, check_answers_card_number:) |
||||
super(id, hsh, subsection) |
||||
@depends_on = [ |
||||
{ |
||||
"combined_income_over_soft_max?" => true, |
||||
}, |
||||
] |
||||
@title_text = { |
||||
"translation" => "soft_validations.income.over_soft_max_for_la_combined", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "combined_income", |
||||
"i18n_template" => "combined_income", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = {} |
||||
@check_answers_card_number = check_answers_card_number |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::CombinedIncomeValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[uprn postcode_full la income1 income2] |
||||
end |
||||
end |
@ -0,0 +1,25 @@
|
||||
class Form::Sales::Questions::CombinedIncomeValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page, check_answers_card_number:) |
||||
super(id, hsh, page) |
||||
@id = "combined_income_value_check" |
||||
@check_answer_label = "Combined income confirmation" |
||||
@header = "Are you sure this is correct?" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"combined_income_value_check" => 0, |
||||
}, |
||||
{ |
||||
"combined_income_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
@check_answers_card_number = check_answers_card_number |
||||
@page = page |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddCombinedIncomeValueCheckToSalesLog < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :sales_logs, :combined_income_value_check, :integer |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer1IncomeMaxValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, check_answers_card_number: 1) } |
||||
|
||||
let(:page_id) { "prefix_buyer_1_income_max_value_check" } |
||||
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[income1_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("prefix_buyer_1_income_max_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"income1_over_soft_max?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer2IncomeMaxValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, check_answers_card_number: 2) } |
||||
|
||||
let(:page_id) { "prefix_buyer_2_income_max_value_check" } |
||||
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[income2_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("prefix_buyer_2_income_max_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"income2_over_soft_max?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer2IncomeMinValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection) } |
||||
|
||||
let(:page_id) { "prefix_buyer_2_income_min_value_check" } |
||||
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[income2_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("prefix_buyer_2_income_min_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"income2_under_soft_min?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::CombinedIncomeMaxValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, check_answers_card_number: nil) } |
||||
|
||||
let(:page_id) { "prefix_combined_income_max_value_check" } |
||||
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[combined_income_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("prefix_combined_income_max_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"combined_income_over_soft_max?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,61 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::Buyer2IncomeValueCheck, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, check_answers_card_number: 2) } |
||||
|
||||
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("income2_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Are you sure this is correct?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Buyer 2 income confirmation") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
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 a correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq({ |
||||
"depends_on" => [ |
||||
{ |
||||
"income2_value_check" => 0, |
||||
}, |
||||
{ |
||||
"income2_value_check" => 1, |
||||
}, |
||||
], |
||||
}) |
||||
end |
||||
end |
@ -0,0 +1,61 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::CombinedIncomeValueCheck, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, check_answers_card_number: nil) } |
||||
|
||||
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("combined_income_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Are you sure this is correct?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Combined income confirmation") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
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 a correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq({ |
||||
"depends_on" => [ |
||||
{ |
||||
"combined_income_value_check" => 0, |
||||
}, |
||||
{ |
||||
"combined_income_value_check" => 1, |
||||
}, |
||||
], |
||||
}) |
||||
end |
||||
end |
Loading…
Reference in new issue