From 1fbfae7661a70fb896acdef6fba93673cb5f3046 Mon Sep 17 00:00:00 2001 From: Timothy Bradley Date: Fri, 4 Nov 2022 16:49:57 -0700 Subject: [PATCH 1/3] LG-7819: Modify enrollment creation CLI tool to create enrollments in USPS API changelog: Internal, In-Person Proofing, Update enrollment CLI tool to support enrollment creation in USPS IPPaaS API --- lib/tasks/dev.rake | 45 +++++++++++++++++++++++++-------- spec/lib/tasks/dev_rake_spec.rb | 34 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 24bf2ec4be5..f19e22d29e2 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -93,6 +93,8 @@ namespace :dev do enrollment_status = InPersonEnrollment.statuses[raw_enrollment_status] is_established = ['pending', 'passed', 'failed', 'expired'].include?(raw_enrollment_status) + create_in_usps = (!!ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] || false) + InPersonEnrollment.transaction do (0...num_users).each do |n| email_addr = "testuser#{n}@example.com" @@ -101,22 +103,45 @@ namespace :dev do if is_established unless raw_enrollment_status == 'pending' && !user.pending_in_person_enrollment.nil? profile = Profile.new(user: user) + usps_compatible_number_alternative = n.to_s.chars.map do |c| + ('a'.ord + c.to_i).chr + end.join('') pii = Pii::Attributes.new_from_hash( first_name: 'Test', - last_name: "User #{n}", + last_name: "User #{usps_compatible_number_alternative}", dob: '1970-05-01', ssn: "666-#{n}", # doesn't need to be legit 9 digits, just unique + address1: '1200 FORESTVILLE DR', + city: 'GREAT FALLS', + state: 'VA', + zipcode: '22066', ) personal_key = profile.encrypt_pii(pii, pw) - enrollment = InPersonEnrollment.create!( - user: user, - profile: profile, - status: enrollment_status, - enrollment_established_at: Time.zone.now - random.rand(0..5).days, - unique_id: SecureRandom.hex(9), - enrollment_code: SecureRandom.hex(16), - ) - enrollment.profile.activate if raw_enrollment_status == 'passed' + + if raw_enrollment_status === 'pending' && create_in_usps + enrollment = InPersonEnrollment.find_or_initialize_by( + user: user, + status: :establishing, + profile: profile, + ) + enrollment.save! + + UspsInPersonProofing::EnrollmentHelper.schedule_in_person_enrollment( + user, + pii, + ) + else + enrollment = InPersonEnrollment.create!( + user: user, + profile: profile, + status: enrollment_status, + enrollment_established_at: Time.zone.now - random.rand(0..5).days, + unique_id: SecureRandom.hex(9), + enrollment_code: SecureRandom.hex(16), + ) + + enrollment.profile.activate if raw_enrollment_status == 'passed' + end Rails.logger.warn "email=#{email_addr} personal_key=#{personal_key}" end else diff --git a/spec/lib/tasks/dev_rake_spec.rb b/spec/lib/tasks/dev_rake_spec.rb index 9f1bc3b6244..aab89907403 100644 --- a/spec/lib/tasks/dev_rake_spec.rb +++ b/spec/lib/tasks/dev_rake_spec.rb @@ -2,6 +2,8 @@ require 'rake' describe 'dev rake tasks' do + include UspsIppHelper + before do Rake.application.rake_require 'tasks/dev' Rake::Task.define_task(:environment) @@ -22,6 +24,7 @@ prev_enrollment_status = nil prev_verified = nil prev_scrypt_cost = nil + prev_pending_in_usps = nil before(:each) do prev_num_users = ENV['NUM_USERS'] @@ -29,6 +32,7 @@ prev_enrollment_status = ENV['ENROLLMENT_STATUS'] prev_verified = ENV['VERIFIED'] prev_scrypt_cost = ENV['SCRYPT_COST'] + prev_pending_in_usps = ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] ENV['PROGRESS'] = 'no' ENV['NUM_USERS'] = '10' @@ -43,6 +47,7 @@ ENV['ENROLLMENT_STATUS'] = prev_enrollment_status ENV['VERIFIED'] = prev_verified ENV['SCRYPT_COST'] = prev_scrypt_cost + ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] = prev_pending_in_usps end describe 'dev:random_users' do @@ -309,6 +314,35 @@ expect(last_record.profile).to be_instance_of(Profile) expect(last_record.profile.active).to be(true) end + + it 'creates the enrollment in USPS IPPaaS when CREATE_PENDING_ENROLLMENT_IN_USPS is truthy' do + ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] = '1' + stub_request_token + stub_request_enroll + + expect(User.count).to eq 0 + expect(InPersonEnrollment.count).to eq 0 + + Rake::Task['dev:random_in_person_users'].invoke + + expect(User.count).to eq 10 + expect(InPersonEnrollment.count).to eq 10 + expect(InPersonEnrollment.distinct.count('user_id')).to eq 10 + expect(InPersonEnrollment.pending.count).to eq 10 + + # Spot check attributes on last record + last_record = InPersonEnrollment.last + expect(last_record.attributes).to include( + 'status' => 'pending', + 'enrollment_established_at' => respond_to(:to_date), + 'unique_id' => an_instance_of(String), + + # Check for the enrollment code in the stubbed response + 'enrollment_code' => '2048702198804353', + ) + expect(last_record.profile).to be_instance_of(Profile) + expect(last_record.profile.active).to be(false) + end end end end From 31d67aa70ab41d6199a99ef6fa3d68dc46a427e9 Mon Sep 17 00:00:00 2001 From: Tim Bradley <90272033+NavaTim@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:49:49 -0700 Subject: [PATCH 2/3] Remove redundant falsy fallback Co-authored-by: Sheldon Bachstein --- lib/tasks/dev.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index f19e22d29e2..72a3c5a8bb5 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -93,7 +93,7 @@ namespace :dev do enrollment_status = InPersonEnrollment.statuses[raw_enrollment_status] is_established = ['pending', 'passed', 'failed', 'expired'].include?(raw_enrollment_status) - create_in_usps = (!!ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] || false) + create_in_usps = !!ENV['CREATE_PENDING_ENROLLMENT_IN_USPS'] InPersonEnrollment.transaction do (0...num_users).each do |n| From 48fcc9cbd126085d34d260fb5a12713b1b2b115b Mon Sep 17 00:00:00 2001 From: Timothy Bradley Date: Tue, 8 Nov 2022 11:54:42 -0700 Subject: [PATCH 3/3] LG-7819: Add comment describing reason for number conversion in last name --- lib/tasks/dev.rake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 72a3c5a8bb5..b59ee15299f 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -103,9 +103,12 @@ namespace :dev do if is_established unless raw_enrollment_status == 'pending' && !user.pending_in_person_enrollment.nil? profile = Profile.new(user: user) + + # Convert index to a string of letters to be a valid last name for the USPS API usps_compatible_number_alternative = n.to_s.chars.map do |c| ('a'.ord + c.to_i).chr end.join('') + pii = Pii::Attributes.new_from_hash( first_name: 'Test', last_name: "User #{usps_compatible_number_alternative}",