From c8354ff962b226343d4bb58fd3596313ede8183c Mon Sep 17 00:00:00 2001 From: Vanson Samuel <37637+binq@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:25:19 -0500 Subject: [PATCH] post database updates (#16500) --- .../vye/v1/verifications_controller.rb | 4 ++- modules/vye/app/models/vye/address_change.rb | 12 +++++++- modules/vye/app/models/vye/award.rb | 1 + modules/vye/app/models/vye/bdn_clone.rb | 4 +++ .../vye/app/models/vye/pending_document.rb | 2 +- modules/vye/app/models/vye/user_info.rb | 6 ++-- modules/vye/app/models/vye/user_profile.rb | 20 +++++-------- modules/vye/app/models/vye/verification.rb | 30 +++++++++++-------- modules/vye/spec/factories/vye/awards.rb | 2 ++ modules/vye/spec/factories/vye/bdn_clones.rb | 8 +++++ modules/vye/spec/factories/vye/user_infos.rb | 1 + .../vye/spec/factories/vye/user_profiles.rb | 2 +- .../vye/spec/factories/vye/verifications.rb | 3 ++ modules/vye/spec/models/vye/bdn_clone_spec.rb | 15 ++++++++++ .../vye/spec/models/vye/verification_spec.rb | 12 ++++---- .../requests/vye/v1/verify/create_spec.rb | 6 ++-- 16 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 modules/vye/app/models/vye/bdn_clone.rb create mode 100644 modules/vye/spec/factories/vye/bdn_clones.rb create mode 100644 modules/vye/spec/models/vye/bdn_clone_spec.rb diff --git a/modules/vye/app/controllers/vye/v1/verifications_controller.rb b/modules/vye/app/controllers/vye/v1/verifications_controller.rb index 40fc32ae139..413c53f6ade 100644 --- a/modules/vye/app/controllers/vye/v1/verifications_controller.rb +++ b/modules/vye/app/controllers/vye/v1/verifications_controller.rb @@ -12,7 +12,9 @@ class Vye::V1::VerificationsController < Vye::V1::ApplicationController def create authorize user_info, policy_class: UserInfoPolicy - user_info.verifications.create!(source_ind:) + award = user_info.awards.first + user_profile = user_info.user_profile + Verification.create!(source_ind:, award:, user_profile:) end private diff --git a/modules/vye/app/models/vye/address_change.rb b/modules/vye/app/models/vye/address_change.rb index 6a0b2f0c649..5ebeab75929 100644 --- a/modules/vye/app/models/vye/address_change.rb +++ b/modules/vye/app/models/vye/address_change.rb @@ -23,7 +23,17 @@ class Vye::AddressChange < ApplicationRecord presence: true, if: -> { origin == 'backend' } ) - enum origin: { frontend: 'f', backend: 'b' } + enum origin: { + + frontend: 'f', + + # This is a special case where the record was created on the frontend + # but will not have been reflected from the backend yet + cached: 'c', + + backend: 'b' + + } scope :created_today, lambda { includes(user_info: :user_profile) diff --git a/modules/vye/app/models/vye/award.rb b/modules/vye/app/models/vye/award.rb index f37db8962a3..f7755be9089 100644 --- a/modules/vye/app/models/vye/award.rb +++ b/modules/vye/app/models/vye/award.rb @@ -3,6 +3,7 @@ module Vye class Vye::Award < ApplicationRecord belongs_to :user_info + has_many :verifications, dependent: :nullify enum cur_award_ind: { current: 'C', future: 'F', past: 'P' } diff --git a/modules/vye/app/models/vye/bdn_clone.rb b/modules/vye/app/models/vye/bdn_clone.rb new file mode 100644 index 00000000000..1ae8895f9e1 --- /dev/null +++ b/modules/vye/app/models/vye/bdn_clone.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Vye::BdnClone < ApplicationRecord +end diff --git a/modules/vye/app/models/vye/pending_document.rb b/modules/vye/app/models/vye/pending_document.rb index c94555c2cdc..7130c96b84b 100644 --- a/modules/vye/app/models/vye/pending_document.rb +++ b/modules/vye/app/models/vye/pending_document.rb @@ -2,7 +2,7 @@ module Vye class Vye::PendingDocument < ApplicationRecord - self.ignored_columns += %i[claim_no_ciphertext ssn_ciphertext ssn_digest] + self.ignored_columns += %i[claim_no_ciphertext encrypted_kms_key ssn_ciphertext ssn_digest] belongs_to :user_profile diff --git a/modules/vye/app/models/vye/user_info.rb b/modules/vye/app/models/vye/user_info.rb index a846faf238d..a50ce81e882 100644 --- a/modules/vye/app/models/vye/user_info.rb +++ b/modules/vye/app/models/vye/user_info.rb @@ -20,13 +20,15 @@ class Vye::UserInfo < ApplicationRecord has_many :address_changes, dependent: :destroy has_many :awards, dependent: :destroy has_many :direct_deposit_changes, dependent: :destroy - has_many :verifications, dependent: :destroy + + scope :with_bdn_clone_active, -> { where(bdn_clone_active: true) } enum mr_status: { active: 'A', expired: 'E' } enum indicator: { chapter1606: 'A', chapter1607: 'E', chapter30: 'B', D: 'D' } delegate :icn, to: :user_profile, allow_nil: true - delegate :pending_documents, to: :user_profile, allow_nil: true + delegate :pending_documents, to: :user_profile + delegate :verifications, to: :user_profile has_kms_key has_encrypted(:dob, :file_number, :stub_nm, key: :kms_key, **lockbox_options) diff --git a/modules/vye/app/models/vye/user_profile.rb b/modules/vye/app/models/vye/user_profile.rb index 2c5119fc63f..d4e7265339f 100644 --- a/modules/vye/app/models/vye/user_profile.rb +++ b/modules/vye/app/models/vye/user_profile.rb @@ -4,17 +4,15 @@ class Vye::UserProfile < ApplicationRecord include Vye::DigestProtected has_many :user_infos, dependent: :restrict_with_exception - - has_many( - :active_user_infos, - lambda { - order(created_at: :desc).limit(1) - }, - class_name: 'Vye::UserInfo', inverse_of: :user_profile, + has_one( + :active_user_info, + -> { with_bdn_clone_active }, + class_name: 'Vye::UserInfo', + inverse_of: :user_profile, dependent: :restrict_with_exception ) - has_many :pending_documents, dependent: :restrict_with_exception + has_many :verifications, dependent: :restrict_with_exception digest_attribute :ssn digest_attribute :file_number @@ -28,11 +26,7 @@ class Vye::UserProfile < ApplicationRecord end end - scope :with_assos, -> { includes(:pending_documents, active_user_infos: %i[address_changes awards verifications]) } - - def active_user_info - active_user_infos.first - end + scope :with_assos, -> { includes(:pending_documents, :verifications, active_user_info: %i[address_changes awards]) } def self.find_and_update_icn(user:) return if user.blank? diff --git a/modules/vye/app/models/vye/verification.rb b/modules/vye/app/models/vye/verification.rb index 99e903b1917..9e1ef5316cf 100644 --- a/modules/vye/app/models/vye/verification.rb +++ b/modules/vye/app/models/vye/verification.rb @@ -2,25 +2,29 @@ module Vye class Vye::Verification < ApplicationRecord - belongs_to :user_info + belongs_to :user_profile + belongs_to :award, optional: true validates(:source_ind, presence: true) enum source_ind: { web: 'W', phone: 'P' } - scope :created_today, -> { includes(:user_info).where('created_at >= ?', Time.zone.now.beginning_of_day) } - def self.todays_verifications - created_today.each_with_object([]) do |record, result| - result << { - stub_nm: record.user_info.stub_nm, - ssn: record.user_info.ssn, - transact_date: record.created_at.strftime('%Y%m%d'), - rpo_code: record.user_info.rpo_code, - indicator: record.user_info.indicator, - source_ind: record.source_ind - } - end + UserInfo + .joins(awards: :verifications) + .includes(awards: :verifications) + .distinct + .each_with_object([]) do |user_info, result| + verification = user_info.awards.map(&:verifications).flatten.first + result << { + stub_nm: user_info.stub_nm, + ssn: user_info.ssn, + transact_date: verification.created_at.strftime('%Y%m%d'), + rpo_code: user_info.rpo_code, + indicator: user_info.indicator, + source_ind: verification.source_ind + } + end end def self.todays_verifications_report diff --git a/modules/vye/spec/factories/vye/awards.rb b/modules/vye/spec/factories/vye/awards.rb index 06e09afaf7a..4411fc2f099 100644 --- a/modules/vye/spec/factories/vye/awards.rb +++ b/modules/vye/spec/factories/vye/awards.rb @@ -2,6 +2,8 @@ FactoryBot.define do factory :vye_award, class: 'Vye::Award' do + association :user_info, factory: :vye_user_info + cur_award_ind { Vye::Award.cur_award_inds.values.sample } award_begin_date { DateTime.now } award_end_date { DateTime.now + 1.month } diff --git a/modules/vye/spec/factories/vye/bdn_clones.rb b/modules/vye/spec/factories/vye/bdn_clones.rb new file mode 100644 index 00000000000..482a4db9704 --- /dev/null +++ b/modules/vye/spec/factories/vye/bdn_clones.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :vye_bdn_clone, class: 'Vye::BdnClone' do + is_active { true } + export_ready { false } + end +end diff --git a/modules/vye/spec/factories/vye/user_infos.rb b/modules/vye/spec/factories/vye/user_infos.rb index 20176580da1..a864f672c97 100644 --- a/modules/vye/spec/factories/vye/user_infos.rb +++ b/modules/vye/spec/factories/vye/user_infos.rb @@ -22,5 +22,6 @@ fac_code { Faker::Lorem.word } payment_amt { Faker::Number.decimal(l_digits: 4, r_digits: 2) } indicator { Vye::UserInfo.indicators.values.sample } + bdn_clone_active { true } end end diff --git a/modules/vye/spec/factories/vye/user_profiles.rb b/modules/vye/spec/factories/vye/user_profiles.rb index 673eef21678..a887e216c95 100644 --- a/modules/vye/spec/factories/vye/user_profiles.rb +++ b/modules/vye/spec/factories/vye/user_profiles.rb @@ -6,6 +6,6 @@ factory :vye_user_profile, class: 'Vye::UserProfile' do ssn { (1..9).map(&digit).join } file_number { (1..9).map(&digit).join } - icn { 'random-icn' } + icn { SecureRandom.uuid } end end diff --git a/modules/vye/spec/factories/vye/verifications.rb b/modules/vye/spec/factories/vye/verifications.rb index 4cee53aaf16..f82142385b3 100644 --- a/modules/vye/spec/factories/vye/verifications.rb +++ b/modules/vye/spec/factories/vye/verifications.rb @@ -2,6 +2,9 @@ FactoryBot.define do factory :vye_verification, class: 'Vye::Verification' do + association :user_profile, factory: :vye_user_profile + association :award, factory: :vye_award + source_ind { Vye::Verification.source_inds.values.sample } end end diff --git a/modules/vye/spec/models/vye/bdn_clone_spec.rb b/modules/vye/spec/models/vye/bdn_clone_spec.rb new file mode 100644 index 00000000000..67c51b88bbb --- /dev/null +++ b/modules/vye/spec/models/vye/bdn_clone_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Vye::BdnClone, type: :model do + describe 'create' do + let(:attributes) { FactoryBot.attributes_for(:vye_bdn_clone) } + + it 'creates a record' do + expect do + described_class.create!(attributes) + end.to change(described_class, :count).by(1) + end + end +end diff --git a/modules/vye/spec/models/vye/verification_spec.rb b/modules/vye/spec/models/vye/verification_spec.rb index 9a545b36c70..14af09e52ba 100644 --- a/modules/vye/spec/models/vye/verification_spec.rb +++ b/modules/vye/spec/models/vye/verification_spec.rb @@ -3,20 +3,22 @@ require 'rails_helper' RSpec.describe Vye::Verification, type: :model do - let(:user_info) { create(:vye_user_info) } - describe 'create' do - let(:attributes) { FactoryBot.attributes_for(:vye_verification, user_info:) } + let!(:user_profile) { FactoryBot.create(:vye_user_profile) } + let(:verification) { FactoryBot.build(:vye_verification, user_profile:) } it 'creates a record' do expect do - Vye::Verification.create!(attributes) + verification.save! end.to change(Vye::Verification, :count).by(1) end end describe 'show todays verifications' do - let!(:verification) { FactoryBot.create(:vye_verification, user_info:) } + let!(:user_profile) { FactoryBot.create(:vye_user_profile) } + let!(:user_info) { FactoryBot.create(:vye_user_info, user_profile:) } + let!(:award) { FactoryBot.create(:vye_award, user_info:) } + let!(:verification) { FactoryBot.create(:vye_verification, award:, user_profile:) } before do ssn = '123456789' diff --git a/modules/vye/spec/requests/vye/v1/verify/create_spec.rb b/modules/vye/spec/requests/vye/v1/verify/create_spec.rb index c98fcb71d97..9e33dad14b3 100644 --- a/modules/vye/spec/requests/vye/v1/verify/create_spec.rb +++ b/modules/vye/spec/requests/vye/v1/verify/create_spec.rb @@ -47,11 +47,11 @@ describe 'in VYE' do let!(:user_profile) { FactoryBot.create(:vye_user_profile, icn: current_user.icn) } let!(:user_info) { FactoryBot.create(:vye_user_info, user_profile:) } - let(:award) { FactoryBot.create(:vye_award, user_info:) } + let!(:award) { FactoryBot.create(:vye_award, user_info:) } it 'creates a new verification' do post('/vye/v1/verify', params: {}) - # puts JSON.pretty_generate(JSON.parse(response)) + expect(response).to have_http_status(:no_content) end end @@ -63,7 +63,7 @@ end let!(:user_profile) { FactoryBot.create(:vye_user_profile, icn: current_user.icn) } let!(:user_info) { FactoryBot.create(:vye_user_info, user_profile:) } - let(:award) { create(:vye_award, user_info:) } + let!(:award) { create(:vye_award, user_info:) } it 'creates a new verification' do post('/vye/v1/verify', params: ivr_params)