diff --git a/modules/vye/app/controllers/vye/v1/verifications_controller.rb b/modules/vye/app/controllers/vye/v1/verifications_controller.rb index 413c53f6ade..40fc32ae139 100644 --- a/modules/vye/app/controllers/vye/v1/verifications_controller.rb +++ b/modules/vye/app/controllers/vye/v1/verifications_controller.rb @@ -12,9 +12,7 @@ class Vye::V1::VerificationsController < Vye::V1::ApplicationController def create authorize user_info, policy_class: UserInfoPolicy - award = user_info.awards.first - user_profile = user_info.user_profile - Verification.create!(source_ind:, award:, user_profile:) + user_info.verifications.create!(source_ind:) end private diff --git a/modules/vye/app/models/vye/address_change.rb b/modules/vye/app/models/vye/address_change.rb index 5ebeab75929..6a0b2f0c649 100644 --- a/modules/vye/app/models/vye/address_change.rb +++ b/modules/vye/app/models/vye/address_change.rb @@ -23,17 +23,7 @@ class Vye::AddressChange < ApplicationRecord presence: true, if: -> { origin == 'backend' } ) - 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' - - } + enum origin: { frontend: 'f', 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 f7755be9089..f37db8962a3 100644 --- a/modules/vye/app/models/vye/award.rb +++ b/modules/vye/app/models/vye/award.rb @@ -3,7 +3,6 @@ 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 deleted file mode 100644 index 1ae8895f9e1..00000000000 --- a/modules/vye/app/models/vye/bdn_clone.rb +++ /dev/null @@ -1,4 +0,0 @@ -# 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 7130c96b84b..c94555c2cdc 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 encrypted_kms_key ssn_ciphertext ssn_digest] + self.ignored_columns += %i[claim_no_ciphertext 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 a50ce81e882..a846faf238d 100644 --- a/modules/vye/app/models/vye/user_info.rb +++ b/modules/vye/app/models/vye/user_info.rb @@ -20,15 +20,13 @@ class Vye::UserInfo < ApplicationRecord has_many :address_changes, dependent: :destroy has_many :awards, dependent: :destroy has_many :direct_deposit_changes, dependent: :destroy - - scope :with_bdn_clone_active, -> { where(bdn_clone_active: true) } + has_many :verifications, dependent: :destroy 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 - delegate :verifications, to: :user_profile + delegate :pending_documents, to: :user_profile, allow_nil: true 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 d4e7265339f..2c5119fc63f 100644 --- a/modules/vye/app/models/vye/user_profile.rb +++ b/modules/vye/app/models/vye/user_profile.rb @@ -4,15 +4,17 @@ class Vye::UserProfile < ApplicationRecord include Vye::DigestProtected has_many :user_infos, dependent: :restrict_with_exception - has_one( - :active_user_info, - -> { with_bdn_clone_active }, - class_name: 'Vye::UserInfo', - inverse_of: :user_profile, + + has_many( + :active_user_infos, + lambda { + order(created_at: :desc).limit(1) + }, + 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 @@ -26,7 +28,11 @@ class Vye::UserProfile < ApplicationRecord end end - scope :with_assos, -> { includes(:pending_documents, :verifications, active_user_info: %i[address_changes awards]) } + scope :with_assos, -> { includes(:pending_documents, active_user_infos: %i[address_changes awards verifications]) } + + def active_user_info + active_user_infos.first + end 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 9e1ef5316cf..99e903b1917 100644 --- a/modules/vye/app/models/vye/verification.rb +++ b/modules/vye/app/models/vye/verification.rb @@ -2,29 +2,25 @@ module Vye class Vye::Verification < ApplicationRecord - belongs_to :user_profile - belongs_to :award, optional: true + belongs_to :user_info 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 - 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 + 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 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 4411fc2f099..06e09afaf7a 100644 --- a/modules/vye/spec/factories/vye/awards.rb +++ b/modules/vye/spec/factories/vye/awards.rb @@ -2,8 +2,6 @@ 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 deleted file mode 100644 index 482a4db9704..00000000000 --- a/modules/vye/spec/factories/vye/bdn_clones.rb +++ /dev/null @@ -1,8 +0,0 @@ -# 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 a864f672c97..20176580da1 100644 --- a/modules/vye/spec/factories/vye/user_infos.rb +++ b/modules/vye/spec/factories/vye/user_infos.rb @@ -22,6 +22,5 @@ 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 a887e216c95..673eef21678 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 { SecureRandom.uuid } + icn { 'random-icn' } end end diff --git a/modules/vye/spec/factories/vye/verifications.rb b/modules/vye/spec/factories/vye/verifications.rb index f82142385b3..4cee53aaf16 100644 --- a/modules/vye/spec/factories/vye/verifications.rb +++ b/modules/vye/spec/factories/vye/verifications.rb @@ -2,9 +2,6 @@ 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 deleted file mode 100644 index 67c51b88bbb..00000000000 --- a/modules/vye/spec/models/vye/bdn_clone_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# 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 14af09e52ba..9a545b36c70 100644 --- a/modules/vye/spec/models/vye/verification_spec.rb +++ b/modules/vye/spec/models/vye/verification_spec.rb @@ -3,22 +3,20 @@ require 'rails_helper' RSpec.describe Vye::Verification, type: :model do + let(:user_info) { create(:vye_user_info) } + describe 'create' do - let!(:user_profile) { FactoryBot.create(:vye_user_profile) } - let(:verification) { FactoryBot.build(:vye_verification, user_profile:) } + let(:attributes) { FactoryBot.attributes_for(:vye_verification, user_info:) } it 'creates a record' do expect do - verification.save! + Vye::Verification.create!(attributes) end.to change(Vye::Verification, :count).by(1) end end describe 'show todays verifications' do - 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:) } + let!(:verification) { FactoryBot.create(:vye_verification, user_info:) } 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 9e33dad14b3..c98fcb71d97 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)