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
23 changes: 18 additions & 5 deletions app/services/idv/profile_maker.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
module Idv
class ProfileMaker
attr_reader :pii_attributes, :profile
attr_reader :pii_attributes

def initialize(applicant:, user:, normalized_applicant:, vendor:, phone_confirmed:)
@profile = Profile.new(user: user, deactivation_reason: :verification_pending)
@pii_attributes = pii_from_applicant(applicant, normalized_applicant)
self.pii_attributes = pii_from_applicant(applicant, normalized_applicant)
self.user = user
self.vendor = vendor
self.phone_confirmed = phone_confirmed
end

def save_profile
profile = Profile.new(
deactivation_reason: :verification_pending,
phone_confirmed: phone_confirmed,
user: user,
vendor: vendor
)
profile.encrypt_pii(user.user_access_key, pii_attributes)
profile.vendor = vendor
profile.phone_confirmed = phone_confirmed
profile.save!
profile
end

private

attr_accessor :user, :vendor, :phone_confirmed
attr_writer :pii_attributes

# rubocop:disable MethodLength, AbcSize
# This method is single statement spread across many lines for readability
def pii_from_applicant(appl, norm_appl)
Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def proofing_started?
end

def cache_applicant_profile_id
profile = profile_maker.profile
profile = profile_maker.save_profile
self.pii = profile_maker.pii_attributes
self.profile_id = profile.id
self.personal_key = profile.personal_key
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/verify/confirmations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def stub_idv_session
vendor: :mock,
phone_confirmed: true
)
profile = profile_maker.profile
profile = profile_maker.save_profile
idv_session.pii = profile_maker.pii_attributes
idv_session.profile_id = profile.id
idv_session.personal_key = profile.personal_key
Expand Down
4 changes: 2 additions & 2 deletions spec/services/idv/profile_maker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

describe Idv::ProfileMaker do
describe '#new' do
describe '#save_profile' do
it 'creates Profile with encrypted PII' do
applicant = Proofer::Applicant.new first_name: 'Some', last_name: 'One'
normalized_applicant = Proofer::Applicant.new first_name: 'Somebody', last_name: 'Oneatatime'
Expand All @@ -16,7 +16,7 @@
phone_confirmed: false
)

profile = profile_maker.profile
profile = profile_maker.save_profile
pii = profile_maker.pii_attributes

expect(profile).to be_a Profile
Expand Down