Skip to content

Commit

Permalink
Revert "post database updates (#16500)" (#16507)
Browse files Browse the repository at this point in the history
This reverts commit c8354ff.
  • Loading branch information
RachalCassity committed Apr 25, 2024
1 parent beb6c78 commit 9825dab
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 88 deletions.
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions modules/vye/app/models/vye/address_change.rb
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion modules/vye/app/models/vye/award.rb
Expand Up @@ -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' }

Expand Down
4 changes: 0 additions & 4 deletions modules/vye/app/models/vye/bdn_clone.rb

This file was deleted.

2 changes: 1 addition & 1 deletion modules/vye/app/models/vye/pending_document.rb
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions modules/vye/app/models/vye/user_info.rb
Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions modules/vye/app/models/vye/user_profile.rb
Expand Up @@ -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
Expand All @@ -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?
Expand Down
30 changes: 13 additions & 17 deletions modules/vye/app/models/vye/verification.rb
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions modules/vye/spec/factories/vye/awards.rb
Expand Up @@ -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 }
Expand Down
8 changes: 0 additions & 8 deletions modules/vye/spec/factories/vye/bdn_clones.rb

This file was deleted.

1 change: 0 additions & 1 deletion modules/vye/spec/factories/vye/user_infos.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/vye/spec/factories/vye/user_profiles.rb
Expand Up @@ -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
3 changes: 0 additions & 3 deletions modules/vye/spec/factories/vye/verifications.rb
Expand Up @@ -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
15 changes: 0 additions & 15 deletions modules/vye/spec/models/vye/bdn_clone_spec.rb

This file was deleted.

12 changes: 5 additions & 7 deletions modules/vye/spec/models/vye/verification_spec.rb
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions modules/vye/spec/requests/vye/v1/verify/create_spec.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9825dab

Please sign in to comment.