Browse Source
			
			
			
			
				
		* Add buyer_livein_value_check column * Add validation form elements * Add validations * Add error messageand update import * Setup fixes * Typos * Add missing translation * Rename soft validation methods * Downcase ownership schemepull/1541/head
				 17 changed files with 406 additions and 4 deletions
			
			
		| @ -0,0 +1,21 @@ | ||||
| class Form::Sales::Pages::BuyerLiveInValueCheck < Form::Sales::Pages::Person | ||||
|   def initialize(id, hsh, subsection, person_index:) | ||||
|     super | ||||
|     @depends_on = [ | ||||
|       { | ||||
|         "buyer#{person_index}_livein_wrong_for_ownership_type?" => true, | ||||
|       }, | ||||
|     ] | ||||
|     @title_text = { | ||||
|       "translation" => "soft_validations.buyer#{person_index}_livein_wrong_for_ownership_type.title_text", | ||||
|       "arguments" => [{ "key" => "ownership_scheme", "label" => false, "i18n_template" => "ownership_scheme" }], | ||||
|     } | ||||
|     @informative_text = {} | ||||
|   end | ||||
| 
 | ||||
|   def questions | ||||
|     @questions ||= [ | ||||
|       Form::Sales::Questions::BuyerLiveInValueCheck.new(nil, nil, self, person_index: @person_index), | ||||
|     ] | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,24 @@ | ||||
| class Form::Sales::Questions::BuyerLiveInValueCheck < ::Form::Question | ||||
|   def initialize(id, hsh, page, person_index:) | ||||
|     super(id, hsh, page) | ||||
|     @id = "buyer_livein_value_check" | ||||
|     @check_answer_label = "Buyer live in confirmation" | ||||
|     @type = "interruption_screen" | ||||
|     @answer_options = { | ||||
|       "0" => { "value" => "Yes" }, | ||||
|       "1" => { "value" => "No" }, | ||||
|     } | ||||
|     @hidden_in_check_answers = { | ||||
|       "depends_on" => [ | ||||
|         { | ||||
|           "buyer_livein_value_check" => 0, | ||||
|         }, | ||||
|         { | ||||
|           "buyer_livein_value_check" => 1, | ||||
|         }, | ||||
|       ], | ||||
|     } | ||||
|     @check_answers_card_number = person_index | ||||
|     @header = "Are you sure this is correct?" | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,5 @@ | ||||
| class AddBuyerLivinValueCheck < ActiveRecord::Migration[7.0] | ||||
|   def change | ||||
|     add_column :sales_logs, :buyer_livein_value_check, :integer | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,64 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Pages::BuyerLiveInValueCheck, type: :model do | ||||
|   subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } | ||||
| 
 | ||||
|   let(:page_id) { "buyer_1_live_in_value_check" } | ||||
|   let(:page_definition) { nil } | ||||
|   let(:person_index) { 1 } | ||||
|   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[buyer_livein_value_check]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(page.id).to eq("buyer_1_live_in_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([ | ||||
|       { | ||||
|         "buyer1_livein_wrong_for_ownership_type?" => true, | ||||
|       }, | ||||
|     ]) | ||||
|   end | ||||
| 
 | ||||
|   it "is interruption screen page" do | ||||
|     expect(page.interruption_screen?).to eq(true) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct title_text" do | ||||
|     expect(page.title_text).to eq({ | ||||
|       "translation" => "soft_validations.buyer1_livein_wrong_for_ownership_type.title_text", | ||||
|       "arguments" => [{ "key" => "ownership_scheme", "label" => false, "i18n_template" => "ownership_scheme" }], | ||||
|     }) | ||||
|   end | ||||
| 
 | ||||
|   context "with buyer 2" do | ||||
|     let(:person_index) { 2 } | ||||
| 
 | ||||
|     it "has correct depends_on" do | ||||
|       expect(page.depends_on).to eq([ | ||||
|         { | ||||
|           "buyer2_livein_wrong_for_ownership_type?" => true, | ||||
|         }, | ||||
|       ]) | ||||
|     end | ||||
| 
 | ||||
|     it "has the correct title_text" do | ||||
|       expect(page.title_text).to eq({ | ||||
|         "translation" => "soft_validations.buyer2_livein_wrong_for_ownership_type.title_text", | ||||
|         "arguments" => [{ "key" => "ownership_scheme", "label" => false, "i18n_template" => "ownership_scheme" }], | ||||
|       }) | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,62 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::BuyerLiveInValueCheck, type: :model do | ||||
|   subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } | ||||
| 
 | ||||
|   let(:question_id) { nil } | ||||
|   let(:question_definition) { nil } | ||||
|   let(:person_index) { 1 } | ||||
|   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("buyer_livein_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 live in 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(1) | ||||
|   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" => [ | ||||
|         { | ||||
|           "buyer_livein_value_check" => 0, | ||||
|         }, | ||||
|         { | ||||
|           "buyer_livein_value_check" => 1, | ||||
|         }, | ||||
|       ], | ||||
|     }) | ||||
|   end | ||||
| end | ||||
					Loading…
					
					
				
		Reference in new issue