Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/services/idv/financials_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ module Idv
class FinancialsValidator < VendorValidator
private

def session_id
idv_session.vendor_session_id
end

def try_submit
try_agent_action do
idv_agent.submit_financials(vendor_params, session_id)
idv_agent.submit_financials(vendor_params, vendor_session_id)
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions app/services/idv/phone_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ module Idv
class PhoneValidator < VendorValidator
private

def session_id
idv_session.vendor_session_id
end

def try_submit
try_agent_action do
idv_agent.submit_phone(vendor_params, session_id)
idv_agent.submit_phone(vendor_params, vendor_session_id)
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions app/services/idv/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ def merge_vendor_errors(errors)
end
end

def idv_vendor
@_idv_vendor ||= Idv::Vendor.new
end

def vendor_errors
@_vendor_errors ||= vendor_validator.errors
end

def vendor_validator
@_vendor_validator ||= vendor_validator_class.new(
idv_session: idv_session,
vendor_params: vendor_params
applicant: idv_session.applicant,
vendor: (idv_session.vendor || idv_vendor.pick),
vendor_params: vendor_params,
vendor_session_id: idv_session.vendor_session_id
)
end
end
Expand Down
16 changes: 7 additions & 9 deletions app/services/idv/vendor_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
module Idv
class VendorValidator
delegate :success?, :errors, to: :result
attr_reader :idv_session, :vendor_params
attr_reader :applicant, :vendor, :vendor_params, :vendor_session_id

def initialize(idv_session:, vendor_params:)
@idv_session = idv_session
def initialize(applicant:, vendor:, vendor_params:, vendor_session_id:)
@applicant = applicant
@vendor = vendor
@vendor_params = vendor_params
@vendor_session_id = vendor_session_id
end

def reasons
Expand All @@ -15,14 +17,10 @@ def reasons

private

def idv_vendor
@_idv_vendor ||= Idv::Vendor.new
end

def idv_agent
@_agent ||= Idv::Agent.new(
applicant: idv_session.applicant,
vendor: (idv_session.vendor || idv_vendor.pick)
applicant: applicant,
vendor: vendor
)
end

Expand Down
23 changes: 13 additions & 10 deletions spec/services/idv/financials_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
describe Idv::FinancialsValidator do
let(:user) { build(:user) }

let(:idv_session) do
idvs = Idv::Session.new(user_session: {}, current_user: user, issuer: nil)
idvs.vendor = :mock
idvs
end

let(:session_id) { idv_session.vendor_session_id }
let(:applicant) { Proofer::Applicant.new({}) }
let(:vendor) { :mock }
let(:vendor_session_id) { SecureRandom.uuid }

let(:params) do
{ ccn: '123-45-6789' }
end

let(:confirmation) { instance_double(Proofer::Confirmation) }

subject { Idv::FinancialsValidator.new(idv_session: idv_session, vendor_params: params) }
subject do
Idv::FinancialsValidator.new(
applicant: applicant,
vendor: vendor,
vendor_params: params,
vendor_session_id: vendor_session_id
)
end

def stub_agent_calls
agent = instance_double(Idv::Agent)
allow(Idv::Agent).to receive(:new).
with(applicant: idv_session.applicant, vendor: :mock).
with(applicant: applicant, vendor: vendor).
and_return(agent)
expect(agent).to receive(:submit_financials).
with(params, idv_session.vendor_session_id).and_return(confirmation)
with(params, vendor_session_id).and_return(confirmation)
end

describe '#success?' do
Expand Down
23 changes: 13 additions & 10 deletions spec/services/idv/phone_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
describe Idv::PhoneValidator do
let(:user) { build(:user) }

let(:idv_session) do
idvs = Idv::Session.new(user_session: {}, current_user: user, issuer: nil)
idvs.vendor = :mock
idvs
end

let(:session_id) { idv_session.vendor_session_id }
let(:applicant) { Proofer::Applicant.new({}) }
let(:vendor) { :mock }
let(:vendor_session_id) { SecureRandom.uuid }

let(:params) do
{ phone: '202-555-1212' }
end

let(:confirmation) { instance_double(Proofer::Confirmation) }

subject { Idv::PhoneValidator.new(idv_session: idv_session, vendor_params: params) }
subject do
Idv::PhoneValidator.new(
applicant: applicant,
vendor: vendor,
vendor_params: params,
vendor_session_id: vendor_session_id
)
end

def stub_agent_calls
agent = instance_double(Idv::Agent)
allow(Idv::Agent).to receive(:new).
with(applicant: idv_session.applicant, vendor: :mock).
with(applicant: applicant, vendor: vendor).
and_return(agent)
expect(agent).to receive(:submit_phone).
with(params, idv_session.vendor_session_id).and_return(confirmation)
with(params, vendor_session_id).and_return(confirmation)
end

describe '#success?' do
Expand Down