From d459ca4a18a1b31ff2801a8b69efcae9fcbd43cc Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Fri, 30 Jun 2017 10:21:22 -0400 Subject: [PATCH] Separate idv_form from Idv::Step classes **Why**: This will let us break submission in to two steps and into two controller actions which will further help us when we move the call to our vendors to background jobs. --- .reek | 1 + .../concerns/idv_failure_concern.rb | 6 ++- app/controllers/verify/finance_controller.rb | 28 +++++++++++--- app/controllers/verify/phone_controller.rb | 23 +++++++++--- app/controllers/verify/sessions_controller.rb | 28 ++++++++++---- app/forms/idv/profile_form.rb | 12 +++--- app/services/analytics.rb | 9 +++-- app/services/idv/financials_step.rb | 17 +-------- app/services/idv/phone_step.rb | 16 +------- app/services/idv/profile_step.rb | 36 ++---------------- app/services/idv/session.rb | 4 +- app/services/idv/step.rb | 37 +++++-------------- .../verify/finance_controller_spec.rb | 13 +++++-- .../verify/phone_controller_spec.rb | 20 ++++++---- .../verify/sessions_controller_spec.rb | 26 ++++++++----- spec/services/idv/financials_step_spec.rb | 26 ++++--------- spec/services/idv/phone_step_spec.rb | 23 +++--------- spec/services/idv/profile_step_spec.rb | 34 ++++------------- 18 files changed, 157 insertions(+), 202 deletions(-) diff --git a/.reek b/.reek index fdb463ebd0c..5dd7ff3513f 100644 --- a/.reek +++ b/.reek @@ -74,6 +74,7 @@ TooManyMethods: - OpenidConnect::AuthorizationController - Idv::Session - User + - Verify::SessionsController UncommunicativeMethodName: exclude: - PhoneConfirmationFlow diff --git a/app/controllers/concerns/idv_failure_concern.rb b/app/controllers/concerns/idv_failure_concern.rb index 689a3e61205..be6348ad420 100644 --- a/app/controllers/concerns/idv_failure_concern.rb +++ b/app/controllers/concerns/idv_failure_concern.rb @@ -5,7 +5,7 @@ def render_failure if step_attempts_exceeded? @view_model = view_model(error: 'fail') flash_message(type: :error) - elsif step.form_valid_but_vendor_validation_failed? + elsif form_valid_but_vendor_validation_failed? @view_model = view_model(error: 'warning') flash_message(type: :warning) else @@ -13,6 +13,10 @@ def render_failure end end + def form_valid_but_vendor_validation_failed? + idv_form.valid? && !step.vendor_validation_passed? + end + def flash_message(type:) flash.now[type.to_sym] = @view_model.flash_message end diff --git a/app/controllers/verify/finance_controller.rb b/app/controllers/verify/finance_controller.rb index e41a5af7c4f..7150a79cf1d 100644 --- a/app/controllers/verify/finance_controller.rb +++ b/app/controllers/verify/finance_controller.rb @@ -5,6 +5,7 @@ class FinanceController < ApplicationController before_action :confirm_step_needed before_action :confirm_step_allowed + before_action :submit_idv_form, only: [:create] def new @view_model = view_model @@ -13,7 +14,7 @@ def new def create result = step.submit - analytics.track_event(Analytics::IDV_FINANCE_CONFIRMATION, result.to_h) + analytics.track_event(Analytics::IDV_FINANCE_CONFIRMATION_VENDOR, result.to_h) increment_step_attempts if result.success? @@ -26,6 +27,16 @@ def create private + def submit_idv_form + result = idv_form.submit(step_params) + analytics.track_event(Analytics::IDV_FINANCE_CONFIRMATION_FORM, result.to_h) + + return if result.success? + + @view_model = view_model + render_form + end + def step_name :financials end @@ -38,12 +49,12 @@ def view_model(error: nil) Verify::FinancialsNew.new( error: error, remaining_attempts: remaining_step_attempts, - idv_form: idv_finance_form + idv_form: idv_form ) end - def idv_finance_form - @_idv_finance_form ||= Idv::FinanceForm.new(idv_session.params) + def idv_form + @_idv_form ||= Idv::FinanceForm.new(idv_session.params) end def handle_success @@ -53,9 +64,9 @@ def handle_success def step @_step ||= Idv::FinancialsStep.new( - idv_form: idv_finance_form, + idv_form_params: idv_form.idv_params, idv_session: idv_session, - params: step_params + vendor_params: vendor_params ) end @@ -70,5 +81,10 @@ def render_form render 'verify/finance_other/new' end end + + def vendor_params + finance_type = idv_form.finance_type + { finance_type => idv_form.idv_params[finance_type] } + end end end diff --git a/app/controllers/verify/phone_controller.rb b/app/controllers/verify/phone_controller.rb index 0a941349b2f..2a0a0999cbd 100644 --- a/app/controllers/verify/phone_controller.rb +++ b/app/controllers/verify/phone_controller.rb @@ -5,6 +5,7 @@ class PhoneController < ApplicationController before_action :confirm_step_needed before_action :confirm_step_allowed + before_action :submit_idv_form, only: [:create] def new @view_model = view_model @@ -13,7 +14,7 @@ def new def create result = step.submit - analytics.track_event(Analytics::IDV_PHONE_CONFIRMATION, result.to_h) + analytics.track_event(Analytics::IDV_PHONE_CONFIRMATION_VENDOR, result.to_h) increment_step_attempts if result.success? @@ -26,15 +27,25 @@ def create private + def submit_idv_form + result = idv_form.submit(step_params) + analytics.track_event(Analytics::IDV_PHONE_CONFIRMATION_FORM, result.to_h) + + return if result.success? + + @view_model = view_model + render :new + end + def step_name :phone end def step @_step ||= Idv::PhoneStep.new( - idv_form: idv_phone_form, idv_session: idv_session, - params: step_params + idv_form_params: idv_form.idv_params, + vendor_params: idv_form.phone ) end @@ -42,7 +53,7 @@ def view_model(error: nil) Verify::PhoneNew.new( error: error, remaining_attempts: remaining_step_attempts, - idv_form: idv_phone_form + idv_form: idv_form ) end @@ -54,8 +65,8 @@ def confirm_step_needed redirect_to verify_review_path if idv_session.phone_confirmation == true end - def idv_phone_form - @_idv_phone_form ||= Idv::PhoneForm.new(idv_session.params, current_user) + def idv_form + @_idv_form ||= Idv::PhoneForm.new(idv_session.params, current_user) end end end diff --git a/app/controllers/verify/sessions_controller.rb b/app/controllers/verify/sessions_controller.rb index 6d944c73fea..3be7548c016 100644 --- a/app/controllers/verify/sessions_controller.rb +++ b/app/controllers/verify/sessions_controller.rb @@ -7,6 +7,8 @@ class SessionsController < ApplicationController before_action :confirm_idv_attempts_allowed before_action :confirm_idv_needed before_action :confirm_step_needed, except: [:destroy] + before_action :initialize_idv_session, only: [:create] + before_action :submit_idv_form, only: [:create] delegate :attempts_exceeded?, to: :step, prefix: true @@ -18,7 +20,7 @@ def new def create result = step.submit - analytics.track_event(Analytics::IDV_BASIC_INFO_SUBMITTED, result.to_h) + analytics.track_event(Analytics::IDV_BASIC_INFO_SUBMITTED_VENDOR, result.to_h) if result.success? process_success @@ -35,6 +37,13 @@ def destroy private + def submit_idv_form + result = idv_form.submit(profile_params) + analytics.track_event(Analytics::IDV_BASIC_INFO_SUBMITTED_FORM, result.to_h) + + process_failure unless result.success? + end + def step_name :sessions end @@ -45,9 +54,9 @@ def confirm_step_needed def step @_step ||= Idv::ProfileStep.new( - idv_form: idv_profile_form, + idv_form_params: profile_params, idv_session: idv_session, - params: profile_params + vendor_params: idv_session.vendor_params ) end @@ -68,7 +77,7 @@ def process_success end def process_failure - if step.duplicate_ssn? + if idv_form.duplicate_ssn? flash[:error] = t('idv.errors.duplicate_ssn') redirect_to verify_session_dupe_path else @@ -81,7 +90,7 @@ def view_model(error: nil) Verify::SessionsNew.new( error: error, remaining_attempts: remaining_idv_attempts, - idv_form: idv_profile_form + idv_form: idv_form ) end @@ -89,8 +98,13 @@ def remaining_idv_attempts Idv::Attempter.idv_max_attempts - current_user.idv_attempts end - def idv_profile_form - @_idv_profile_form ||= Idv::ProfileForm.new((idv_session.params || {}), current_user) + def idv_form + @_idv_form ||= Idv::ProfileForm.new((idv_session.params || {}), current_user) + end + + def initialize_idv_session + idv_session.params.merge!(profile_params) + idv_session.applicant = idv_session.vendor_params end def profile_params diff --git a/app/forms/idv/profile_form.rb b/app/forms/idv/profile_form.rb index 3824376e6a0..7d2912f44b5 100644 --- a/app/forms/idv/profile_form.rb +++ b/app/forms/idv/profile_form.rb @@ -44,6 +44,11 @@ def submit(params) FormResponse.new(success: valid?, errors: errors.messages) end + def duplicate_ssn? + return true if any_matching_ssn_signatures?(ssn_signature) + return true if ssn_is_duplicate_with_old_key? + end + private attr_writer(*Pii::Attributes.members) @@ -61,12 +66,7 @@ def ssn_signature(key = Pii::Fingerprinter.current_key) end def ssn_is_unique - errors.add :ssn, I18n.t('idv.errors.duplicate_ssn') if ssn_is_duplicate? - end - - def ssn_is_duplicate? - return true if any_matching_ssn_signatures?(ssn_signature) - return true if ssn_is_duplicate_with_old_key? + errors.add :ssn, I18n.t('idv.errors.duplicate_ssn') if duplicate_ssn? end def ssn_is_duplicate_with_old_key? diff --git a/app/services/analytics.rb b/app/services/analytics.rb index 96811367afd..6d59735fcbe 100644 --- a/app/services/analytics.rb +++ b/app/services/analytics.rb @@ -38,14 +38,17 @@ def uuid EMAIL_CONFIRMATION = 'Email Confirmation'.freeze EMAIL_CONFIRMATION_RESEND = 'Email Confirmation requested due to invalid token'.freeze IDV_BASIC_INFO_VISIT = 'IdV: basic info visited'.freeze - IDV_BASIC_INFO_SUBMITTED = 'IdV: basic info submitted'.freeze + IDV_BASIC_INFO_SUBMITTED_FORM = 'IdV: basic info form submitted'.freeze + IDV_BASIC_INFO_SUBMITTED_VENDOR = 'IdV: basic info vendor submitted'.freeze IDV_MAX_ATTEMPTS_EXCEEDED = 'IdV: max attempts exceeded'.freeze IDV_FINAL = 'IdV: final resolution'.freeze IDV_FINANCE_CCN_VISIT = 'IdV: finance ccn visited'.freeze - IDV_FINANCE_CONFIRMATION = 'IdV: finance confirmation'.freeze + IDV_FINANCE_CONFIRMATION_FORM = 'IdV: finance confirmation form'.freeze + IDV_FINANCE_CONFIRMATION_VENDOR = 'IdV: finance confirmation vendor'.freeze IDV_FINANCE_OTHER_VISIT = 'IdV: finance other visited'.freeze IDV_INTRO_VISIT = 'IdV: intro visited'.freeze - IDV_PHONE_CONFIRMATION = 'IdV: phone confirmation'.freeze + IDV_PHONE_CONFIRMATION_FORM = 'IdV: phone confirmation form'.freeze + IDV_PHONE_CONFIRMATION_VENDOR = 'IdV: phone confirmation vendor'.freeze IDV_PHONE_RECORD_VISIT = 'IdV: phone of record visited'.freeze IDV_REVIEW_COMPLETE = 'IdV: review complete'.freeze IDV_REVIEW_VISIT = 'IdV: review info visited'.freeze diff --git a/app/services/idv/financials_step.rb b/app/services/idv/financials_step.rb index 5dc601c25ef..e3deec1b95b 100644 --- a/app/services/idv/financials_step.rb +++ b/app/services/idv/financials_step.rb @@ -4,7 +4,7 @@ def submit if complete? @success = true idv_session.financials_confirmation = true - idv_session.params = idv_form.idv_params + idv_session.params = idv_form_params else @success = false idv_session.financials_confirmation = false @@ -13,29 +13,16 @@ def submit FormResponse.new(success: success, errors: errors) end - def form_valid_but_vendor_validation_failed? - form_valid? && !vendor_validation_passed? - end - private attr_reader :success def complete? - form_valid? && vendor_validation_passed? + vendor_validation_passed? end def vendor_validator_class Idv::FinancialsValidator end - - def vendor_reasons - vendor_validator_result.reasons if form_valid? - end - - def vendor_params - finance_type = idv_form.finance_type - { finance_type => idv_form.idv_params[finance_type] } - end end end diff --git a/app/services/idv/phone_step.rb b/app/services/idv/phone_step.rb index c0973a7cec6..4345e56b8ed 100644 --- a/app/services/idv/phone_step.rb +++ b/app/services/idv/phone_step.rb @@ -10,32 +10,20 @@ def submit FormResponse.new(success: complete?, errors: errors) end - def form_valid_but_vendor_validation_failed? - form_valid? && !vendor_validation_passed? - end - private def complete? - form_valid? && vendor_validation_passed? + vendor_validation_passed? end def vendor_validator_class Idv::PhoneValidator end - def vendor_params - idv_form.phone - end - - def vendor_reasons - vendor_validator_result.reasons if form_valid? - end - def update_idv_session idv_session.phone_confirmation = true idv_session.address_verification_mechanism = :phone - idv_session.params = idv_form.idv_params + idv_session.params = idv_form_params end end end diff --git a/app/services/idv/profile_step.rb b/app/services/idv/profile_step.rb index 4f7ff1c51cf..cccbc0be87c 100644 --- a/app/services/idv/profile_step.rb +++ b/app/services/idv/profile_step.rb @@ -1,12 +1,9 @@ module Idv class ProfileStep < Step def submit - initialize_idv_session - submit_idv_form - @success = complete? - increment_attempts_count if form_valid? + increment_attempts_count update_idv_session if success FormResponse.new(success: success, errors: errors, extra: extra_analytics_attributes) @@ -16,47 +13,22 @@ def attempts_exceeded? attempter.exceeded? end - def duplicate_ssn? - errors.key?(:ssn) && errors[:ssn].include?(I18n.t('idv.errors.duplicate_ssn')) - end - - def form_valid_but_vendor_validation_failed? - form_valid? && !vendor_validation_passed? - end - private attr_reader :success - def initialize_idv_session - idv_session.params.merge!(params) - idv_session.applicant = vendor_params - end - - def vendor_params - idv_session.vendor_params - end - - def submit_idv_form - idv_form.submit(params) - end - def complete? - !attempts_exceeded? && form_valid? && vendor_validation_passed? + !attempts_exceeded? && vendor_validation_passed? end def attempter - @_idv_attempter ||= Idv::Attempter.new(idv_form.user) + @_idv_attempter ||= Idv::Attempter.new(idv_session.current_user) end def increment_attempts_count attempter.increment end - def form_valid? - @_form_valid ||= idv_form.valid? - end - def vendor_validator_class Idv::ProfileValidator end @@ -76,7 +48,7 @@ def extra_analytics_attributes end def vendor_reasons - vendor_validator_result.reasons if form_valid? + vendor_validator_result.reasons end end end diff --git a/app/services/idv/session.rb b/app/services/idv/session.rb index 188ef878467..a0baa6894a9 100644 --- a/app/services/idv/session.rb +++ b/app/services/idv/session.rb @@ -17,6 +17,8 @@ class Session vendor_session_id ].freeze + attr_reader :current_user + def initialize(user_session:, current_user:, issuer:) @user_session = user_session @current_user = current_user @@ -96,7 +98,7 @@ def address_mechanism_chosen? private - attr_accessor :user_session, :current_user, :issuer + attr_accessor :user_session, :issuer def new_idv_session { params: {}, step_attempts: { financials: 0, phone: 0 } } diff --git a/app/services/idv/step.rb b/app/services/idv/step.rb index 96aef281a05..ad5c3d11b42 100644 --- a/app/services/idv/step.rb +++ b/app/services/idv/step.rb @@ -1,28 +1,20 @@ # abstract base class for Idv Steps module Idv class Step - def initialize(idv_form:, idv_session:, params:) - @idv_form = idv_form + def initialize(idv_session:, idv_form_params:, vendor_params:) + @idv_form_params = idv_form_params @idv_session = idv_session - @params = params + @vendor_params = vendor_params end - def form_valid? - form_validate(params).success? + def vendor_validation_passed? + vendor_validator_result.success? end private attr_accessor :idv_session - attr_reader :idv_form, :params - - def form_validate(params) - @form_result ||= idv_form.submit(params) - end - - def vendor_validation_passed? - vendor_validator_result.success? - end + attr_reader :idv_form_params, :vendor_params def vendor_validator_result @_vendor_validator_result ||= extract_vendor_result(vendor_validator.result) @@ -41,15 +33,10 @@ def extract_vendor_result(result) end def errors - errors = idv_form.errors.messages.dup - return errors unless form_valid? && vendor_errors - merge_vendor_errors(errors) - end - - def merge_vendor_errors(errors) - vendor_errors.each_with_object(errors) do |(key, value), errs| - value = [value] unless value.is_a?(Array) - errs[key] = value + @_errors ||= begin + vendor_validator_result.errors.each_with_object({}) do |(key, value), errs| + errs[key] = Array(value) + end end end @@ -57,10 +44,6 @@ def idv_vendor @_idv_vendor ||= Idv::Vendor.new end - def vendor_errors - @_vendor_errors ||= vendor_validator_result.errors - end - def vendor_validator @_vendor_validator ||= vendor_validator_class.new( applicant: idv_session.applicant, diff --git a/spec/controllers/verify/finance_controller_spec.rb b/spec/controllers/verify/finance_controller_spec.rb index 4ae70d9091c..335e4f2cc93 100644 --- a/spec/controllers/verify/finance_controller_spec.rb +++ b/spec/controllers/verify/finance_controller_spec.rb @@ -141,7 +141,10 @@ } expect(@analytics).to have_received(:track_event).with( - Analytics::IDV_FINANCE_CONFIRMATION, result + Analytics::IDV_FINANCE_CONFIRMATION_FORM, result + ) + expect(@analytics).to have_received(:track_event).with( + Analytics::IDV_FINANCE_CONFIRMATION_VENDOR, result ) end end @@ -156,7 +159,9 @@ } expect(@analytics).to have_received(:track_event). - with(Analytics::IDV_FINANCE_CONFIRMATION, result) + with(Analytics::IDV_FINANCE_CONFIRMATION_FORM, success: true, errors: {}) + expect(@analytics).to have_received(:track_event). + with(Analytics::IDV_FINANCE_CONFIRMATION_VENDOR, result) end end @@ -172,8 +177,8 @@ } expect(@analytics).to have_received(:track_event). - with(Analytics::IDV_FINANCE_CONFIRMATION, result) - expect(subject.idv_session.financials_confirmation).to eq false + with(Analytics::IDV_FINANCE_CONFIRMATION_FORM, result) + expect(subject.idv_session.financials_confirmation).to be_falsy expect(Idv::FinancialsValidator).to_not have_received(:new) end end diff --git a/spec/controllers/verify/phone_controller_spec.rb b/spec/controllers/verify/phone_controller_spec.rb index 5f20d7df012..8631d32ae97 100644 --- a/spec/controllers/verify/phone_controller_spec.rb +++ b/spec/controllers/verify/phone_controller_spec.rb @@ -1,7 +1,8 @@ require 'rails_helper' -include Features::LocalizationHelper describe Verify::PhoneController do + include Features::LocalizationHelper + let(:max_attempts) { Idv::Attempter.idv_max_attempts } let(:good_phone) { '+1 (555) 555-0000' } let(:bad_phone) { '+1 (555) 555-5555' } @@ -57,7 +58,7 @@ end it 'tracks form error and does not make a vendor API call' do - allow(Idv::PhoneValidator).to receive(:new) + expect(Idv::PhoneValidator).to_not receive(:new) put :create, idv_phone_form: { phone: '703' } @@ -69,10 +70,9 @@ } expect(@analytics).to have_received(:track_event).with( - Analytics::IDV_PHONE_CONFIRMATION, result + Analytics::IDV_PHONE_CONFIRMATION_FORM, result ) - expect(subject.idv_session.phone_confirmation).to eq false - expect(Idv::PhoneValidator).to_not have_received(:new) + expect(subject.idv_session.phone_confirmation).to be_falsy end end @@ -91,7 +91,10 @@ result = { success: true, errors: {} } expect(@analytics).to have_received(:track_event).with( - Analytics::IDV_PHONE_CONFIRMATION, result + Analytics::IDV_PHONE_CONFIRMATION_FORM, result + ) + expect(@analytics).to have_received(:track_event).with( + Analytics::IDV_PHONE_CONFIRMATION_VENDOR, result ) end @@ -111,7 +114,10 @@ expect(flash[:warning]).to match t('idv.modal.phone.heading') expect(flash[:warning]).to match t('idv.modal.attempts', count: max_attempts - 1) expect(@analytics).to have_received(:track_event).with( - Analytics::IDV_PHONE_CONFIRMATION, result + Analytics::IDV_PHONE_CONFIRMATION_FORM, success: true, errors: {} + ) + expect(@analytics).to have_received(:track_event).with( + Analytics::IDV_PHONE_CONFIRMATION_VENDOR, result ) end diff --git a/spec/controllers/verify/sessions_controller_spec.rb b/spec/controllers/verify/sessions_controller_spec.rb index b0e90722b48..67ff7dc8888 100644 --- a/spec/controllers/verify/sessions_controller_spec.rb +++ b/spec/controllers/verify/sessions_controller_spec.rb @@ -104,13 +104,11 @@ result = { success: false, - idv_attempts_exceeded: false, errors: { ssn: [t('idv.errors.duplicate_ssn')] }, - vendor: { reasons: nil }, } expect(@analytics).to receive(:track_event). - with(Analytics::IDV_BASIC_INFO_SUBMITTED, result) + with(Analytics::IDV_BASIC_INFO_SUBMITTED_FORM, result) post :create, profile: user_attrs.merge(ssn: '666-66-1234') @@ -129,15 +127,21 @@ end context 'missing fields' do - it 'checks for required fields' do - partial_attrs = user_attrs.dup - partial_attrs.delete :first_name + let(:partial_attrs) do + user_attrs.tap { |attrs| attrs.delete :first_name } + end + it 'checks for required fields' do post :create, profile: partial_attrs expect(response).to render_template(:new) expect(flash[:warning]).to be_nil end + + it 'does not increment attempts count' do + expect { post :create, profile: partial_attrs }. + to_not change(user, :idv_attempts) + end end context 'un-resolvable attributes' do @@ -164,7 +168,7 @@ } expect(@analytics).to have_received(:track_event). - with(Analytics::IDV_BASIC_INFO_SUBMITTED, result) + with(Analytics::IDV_BASIC_INFO_SUBMITTED_VENDOR, result) end end @@ -189,7 +193,7 @@ } expect(@analytics).to have_received(:track_event). - with(Analytics::IDV_BASIC_INFO_SUBMITTED, result) + with(Analytics::IDV_BASIC_INFO_SUBMITTED_VENDOR, result) expect(response).to render_template(:new) end end @@ -206,7 +210,11 @@ } expect(@analytics).to have_received(:track_event). - with(Analytics::IDV_BASIC_INFO_SUBMITTED, result) + with(Analytics::IDV_BASIC_INFO_SUBMITTED_VENDOR, result) + end + + it 'increments attempts count' do + expect { post :create, profile: user_attrs }.to change(user, :idv_attempts).by(1) end end diff --git a/spec/services/idv/financials_step_spec.rb b/spec/services/idv/financials_step_spec.rb index 9f675b75fe4..b20fbd952fc 100644 --- a/spec/services/idv/financials_step_spec.rb +++ b/spec/services/idv/financials_step_spec.rb @@ -7,31 +7,19 @@ idvs.vendor = :mock idvs end - let(:idv_finance_form) { Idv::FinanceForm.new(idv_session.params) } + let(:idv_form_params) { idv_session.params } - def build_step(params) + def build_step(vendor_params) described_class.new( - idv_form: idv_finance_form, + idv_form_params: idv_form_params, idv_session: idv_session, - params: params + vendor_params: vendor_params ) end describe '#submit' do - it 'returns FormResponse with success: false for invalid params' do - step = build_step(finance_type: :ccn, ccn: '1234') - errors = { ccn: [t('idv.errors.invalid_ccn')] } - - result = step.submit - expect(result).to be_kind_of(FormResponse) - expect(result.success?).to eq(false) - expect(result.errors).to eq(errors) - - expect(idv_session.financials_confirmation).to eq false - end - it 'returns FormResponse with success: true for mock-happy CCN' do - step = build_step(finance_type: :ccn, ccn: '12345678') + step = build_step(ccn: '12345678') result = step.submit expect(result).to be_kind_of(FormResponse) @@ -39,11 +27,11 @@ def build_step(params) expect(result.errors).to be_empty expect(idv_session.financials_confirmation).to eq true - expect(idv_session.params).to eq idv_finance_form.idv_params + expect(idv_session.params).to eq idv_form_params end it 'returns FormResponse with success: false for mock-sad CCN' do - step = build_step(finance_type: :ccn, ccn: '00000000') + step = build_step(ccn: '00000000') errors = { ccn: ['The ccn could not be verified.'] } diff --git a/spec/services/idv/phone_step_spec.rb b/spec/services/idv/phone_step_spec.rb index 3e5ccd84af3..7dacb2ace6c 100644 --- a/spec/services/idv/phone_step_spec.rb +++ b/spec/services/idv/phone_step_spec.rb @@ -12,30 +12,17 @@ end let(:idv_phone_form) { Idv::PhoneForm.new(idv_session.params, user) } - def build_step(params) + def build_step(phone) described_class.new( - idv_form: idv_phone_form, idv_session: idv_session, - params: params + idv_form_params: { phone: phone }, + vendor_params: phone ) end describe '#submit' do - it 'returns false for invalid-looking phone' do - step = build_step(phone: '555') - - errors = { phone: [invalid_phone_message] } - - result = step.submit - - expect(result).to be_kind_of(FormResponse) - expect(result.success?).to eq(false) - expect(result.errors).to eq(errors) - expect(idv_session.phone_confirmation).to eq false - end - it 'returns true for mock-happy phone' do - step = build_step(phone: '555-555-0000') + step = build_step('555-555-0000') result = step.submit @@ -47,7 +34,7 @@ def build_step(params) end it 'returns false for mock-sad phone' do - step = build_step(phone: '555-555-5555') + step = build_step('555-555-5555') errors = { phone: ['The phone number could not be verified.'] } diff --git a/spec/services/idv/profile_step_spec.rb b/spec/services/idv/profile_step_spec.rb index 03ec4ca0ee1..3906d020b1d 100644 --- a/spec/services/idv/profile_step_spec.rb +++ b/spec/services/idv/profile_step_spec.rb @@ -19,10 +19,13 @@ end def build_step(params) + idv_session.params.merge!(params) + idv_session.applicant = idv_session.vendor_params + described_class.new( - idv_form: idv_profile_form, - idv_session: idv_session, - params: params + idv_form_params: params, + vendor_params: idv_session.vendor_params, + idv_session: idv_session ) end @@ -62,24 +65,6 @@ def build_step(params) expect(idv_session.profile_confirmation).to be_nil end - it 'fails when form validation fails' do - step = build_step(user_attrs.merge(ssn: '6666')) - - errors = { ssn: [t('idv.errors.pattern_mismatch.ssn')] } - extra = { - idv_attempts_exceeded: false, - vendor: { reasons: nil }, - } - - result = step.submit - - expect(result).to be_kind_of(FormResponse) - expect(result.success?).to eq(false) - expect(result.errors).to eq(errors) - expect(result.extra).to eq(extra) - expect(idv_session.profile_confirmation).to be_nil - end - it 'fails with invalid first name' do step = build_step(user_attrs.merge(first_name: 'Bad')) @@ -134,16 +119,11 @@ def build_step(params) expect(idv_session.profile_confirmation).to be_nil end - it 'increments attempts count if the form is valid' do + it 'increments attempts count' do step = build_step(user_attrs) expect { step.submit }.to change(user, :idv_attempts).by(1) end - it 'does not increment the attempts count if the form is not valid' do - step = build_step(user_attrs.merge(ssn: '666')) - expect { step.submit }.to change(user, :idv_attempts).by(0) - end - it 'initializes the idv_session' do step = build_step(user_attrs) step.submit