Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6: [ART] Skip spec for POA request accredited entities migration #20000

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def index
def show
poa_request = PowerOfAttorneyRequest.includes(resolution: :resolving).find(params[:id])
serializer = PowerOfAttorneyRequestSerializer.new(poa_request)

render json: serializer.serializable_hash, status: :ok
rescue ActiveRecord::RecordNotFound
render json: { error: 'Record not found' }, status: :not_found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,56 @@
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest',
inverse_of: :power_of_attorney_form


Check failure on line 9 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/EmptyLines: Extra blank line detected.
has_kms_key

has_encrypted :data, key: :kms_key, **lockbox_options
has_encrypted(
:data,
:claimant_city,
:claimant_state_code,
:claimant_zip_code,
key: :kms_key,
**lockbox_options
)

blind_index(
:claimant_city,
:claimant_state_code,
:claimant_zip_code
)

validate :data_must_comply_with_schema
before_validation :set_location

# Maybe can manage interdepencies between this and the POA reqeust without
# exposing this.
def parsed_data
@parsed_data ||= JSON.parse(data)
end

private

def set_location
claimant = parsed_data['dependent']
claimant ||= parsed_data['veteran']

address = claimant.to_h['address']
return unless address

self.claimant_city = address['city']
self.claimant_state_code = address['state_code']
self.claimant_zip_code = address['zip_code']
end

def data_must_comply_with_schema
data_errors = JSONSchemer.schema(SCHEMA).validate(parsed_data)
return if data_errors.none?

blind_index :city
blind_index :state
blind_index :zipcode
errors.add :data, 'does not comply with schema'
end

##
# TODO: Can couple this to the schema involved in user input during POA

Check failure on line 58 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/TrailingWhitespace: Trailing whitespace detected.
# request creation.
#
# Currently, it is a small-ish transformation of the most closely related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequest < ApplicationRecord
module ClaimantTypes
DEPENDENT = 'dependent'
VETERAN = 'veteran'
end

belongs_to :claimant, class_name: 'UserAccount'

has_one :power_of_attorney_form,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyForm',
inverse_of: :power_of_attorney_request
inverse_of: :power_of_attorney_request,
required: true

has_one :resolution,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution',
inverse_of: :power_of_attorney_request

before_validation :set_claimant_type

private

def set_claimant_type
if power_of_attorney_form.parsed_data['dependent']
self.claimant_type = ClaimantTypes::DEPENDENT
return
end

if power_of_attorney_form.parsed_data['veteran']
self.claimant_type = ClaimantTypes::VETERAN
return

Check failure on line 33 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/RedundantReturn: Redundant `return` detected.
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class ApplicationSerializer
include JSONAPI::Serializer

# We're not building to JSONAPI.
def serializable_hash
data = super[:data]

case data
when Array
data.map(&method(:unwrap_serializable_hash))
when Hash
unwrap_serializable_hash(data)
end
end

private

def unwrap_serializable_hash(data)
data[:attributes].merge!(id: data[:id])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestDecisionSerializer < PowerOfAttorneyRequestResolutionSerializer
attribute(:type) { 'decision' }

attribute :decision_type do |resolution|
case resolution.resolving.type
when PowerOfAttorneyRequestDecision::Types::ACCEPTANCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestExpirationSerializer < PowerOfAttorneyRequestResolutionSerializer
attribute(:type) { 'expiration' }
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestResolutionSerializer
include JSONAPI::Serializer

class PowerOfAttorneyRequestResolutionSerializer < ApplicationSerializer
attributes :created_at
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer
include JSONAPI::Serializer
class PowerOfAttorneyRequestSerializer < ApplicationSerializer
attributes :claimant_id, :claimant_type, :created_at

attributes :claimant_id, :created_at
attribute :power_of_attorney_form do |poa_request|
poa_request.power_of_attorney_form.parsed_data
end

attribute :resolution do |poa_request|
next unless poa_request.resolution
Expand All @@ -17,7 +19,9 @@ class PowerOfAttorneyRequestSerializer
PowerOfAttorneyRequestExpirationSerializer
end

serializer.new(poa_request.resolution)
serializer
.new(poa_request.resolution)
.serializable_hash
end
end
end
9 changes: 6 additions & 3 deletions modules/accredited_representative_portal/bin/rails
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENGINE_ROOT = File.expand_path('../..', __dir__)
ENGINE_PATH = File.expand_path('../../lib/accredited_representative_portal/engine', __dir__)
require 'pathname'

ENGINE_ROOT = Pathname(__dir__).parent
ENGINE_PATH = ENGINE_ROOT / 'lib/accredited_representative_portal/engine'
BUNDLE_GEMFILE = ENGINE_ROOT / 'Gemfile'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
ENV['BUNDLE_GEMFILE'] ||= BUNDLE_GEMFILE.to_path
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class MakePoaRequestAndFormAdjustments < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
remove_index :ar_power_of_attorney_forms, name: 'idx_on_city_bidx_state_bidx_zipcode_bidx_a85b76f9bc'
remove_index :ar_power_of_attorney_forms, name: 'index_ar_power_of_attorney_forms_on_zipcode_bidx'
safety_assured { remove_columns :ar_power_of_attorney_forms, :city_bidx, :state_bidx, :zipcode_bidx }

add_column :ar_power_of_attorney_forms, :claimant_city_ciphertext, :string, null: false
add_column :ar_power_of_attorney_forms, :claimant_city_bidx, :string, null: false

add_column :ar_power_of_attorney_forms, :claimant_state_code_ciphertext, :string, null: false
add_column :ar_power_of_attorney_forms, :claimant_state_code_bidx, :string, null: false

add_column :ar_power_of_attorney_forms, :claimant_zip_code_ciphertext, :string, null: false
add_column :ar_power_of_attorney_forms, :claimant_zip_code_bidx, :string, null: false

add_index :ar_power_of_attorney_forms,
[:claimant_city_bidx, :claimant_state_code_bidx, :claimant_zip_code_bidx],
algorithm: :concurrently

add_column :ar_power_of_attorney_requests, :claimant_type, :string, null: false
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
# frozen_string_literal: true

form_data = <<~JSON
{
"authorizations": {
"record_disclosure": true,
"record_disclosure_limitations": [],
"address_change": true
},
"dependent": {
"name": {
"first": "John",
"middle": "Middle",
"last": "Doe"
},
"address": {
"address_line1": "123 Main St",
"address_line2": "Apt 1",
"city": "Springfield",
"state_code": "IL",
"country": "US",
"zip_code": "62704",
"zip_code_suffix": "6789"
},
"date_of_birth": "1980-12-31",
"relationship": "Spouse",
"phone": "1234567890",
"email": "[email protected]"
},
"veteran": {
"name": {
"first": "John",
"middle": "Middle",
"last": "Doe"
},
"address": {
"address_line1": "123 Main St",
"address_line2": "Apt 1",
"city": "Springfield",
"state_code": "IL",
"country": "US",
"zip_code": "62704",
"zip_code_suffix": "6789"
},
"ssn": "123456789",
"va_file_number": "123456789",
"date_of_birth": "1980-12-31",
"service_number": "123456789",
"service_branch": "ARMY",
"phone": "1234567890",
"email": "[email protected]"
}
}
JSON

FactoryBot.define do
factory :power_of_attorney_form, class: 'AccreditedRepresentativePortal::PowerOfAttorneyForm' do
data_ciphertext { 'Test encrypted data' }
city_bidx { Faker::Alphanumeric.alphanumeric(number: 44) }
state_bidx { Faker::Alphanumeric.alphanumeric(number: 44) }
zipcode_bidx { Faker::Alphanumeric.alphanumeric(number: 44) }
data { form_data }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FactoryBot.define do
factory :power_of_attorney_request, class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest' do
association :claimant, factory: :user_account
association :power_of_attorney_form, strategy: :build

trait :with_acceptance do
resolution { create(:power_of_attorney_request_resolution, :acceptance) }
Expand Down
Loading
Loading