Skip to content

Commit

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

Expand Down
4 changes: 4 additions & 0 deletions modules/vye/app/models/vye/bdn_clone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Vye::BdnClone < ApplicationRecord
end
2 changes: 1 addition & 1 deletion modules/vye/app/models/vye/pending_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions modules/vye/app/models/vye/user_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 7 additions & 13 deletions modules/vye/app/models/vye/user_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
30 changes: 17 additions & 13 deletions modules/vye/app/models/vye/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions modules/vye/spec/factories/vye/awards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 8 additions & 0 deletions modules/vye/spec/factories/vye/bdn_clones.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions modules/vye/spec/factories/vye/user_infos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/vye/spec/factories/vye/user_profiles.rb
Original file line number Diff line number Diff line change
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 { 'random-icn' }
icn { SecureRandom.uuid }
end
end
3 changes: 3 additions & 0 deletions modules/vye/spec/factories/vye/verifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions modules/vye/spec/models/vye/bdn_clone_spec.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions modules/vye/spec/models/vye/verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions modules/vye/spec/requests/vye/v1/verify/create_spec.rb
Original file line number Diff line number Diff line change
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 53c5051

Please sign in to comment.