Skip to content

Commit

Permalink
15: [ART] Have serializers match front end data (#20254)
Browse files Browse the repository at this point in the history
* art/serializers/match_front_end_data

* art/serializers/match_front_end_data - fixed tests

* art/serializers/match_front_end_data - fixed rubocop

* art/serializers/match_front_end_data - post oren comments 1.0

* art/serializers/match_front_end_data - fixed rubocop

* [ART] fix POA request factory hooks, un-abstract expected spec response

* [ART] (fix) Minor lint fixes

* art/serializers/match_front_end_data - added serializer spec

---------

Co-authored-by: OJ Bucao <[email protected]>
Co-authored-by: Oren Mittman <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent 0d4ec63 commit 1c386dc
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module ClaimantTypes
].freeze
end

EXPIRY_DURATION = 60.days

belongs_to :claimant, class_name: 'UserAccount'

has_one :power_of_attorney_form,
Expand All @@ -31,14 +33,27 @@ module ClaimantTypes

delegate :poa_code, to: :accredited_individual

def expires_at
created_at + EXPIRY_DURATION if unresolved?
end

def unresolved?
!resolved?
end

def resolved?
resolution.present?
end

private

def set_claimant_type
self.claimant_type = if power_of_attorney_form.parsed_data['dependent']
ClaimantTypes::DEPENDENT
elsif power_of_attorney_form.parsed_data['veteran']
ClaimantTypes::VETERAN
end
self.claimant_type =
if power_of_attorney_form.parsed_data['dependent']
ClaimantTypes::DEPENDENT
elsif power_of_attorney_form.parsed_data['veteran']
ClaimantTypes::VETERAN
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer < ApplicationSerializer
attributes :claimant_id, :claimant_type, :created_at
attributes :claimant_id, :created_at, :expires_at

attribute :power_of_attorney_form do |poa_request|
poa_request.power_of_attorney_form.parsed_data
poa_request.power_of_attorney_form.parsed_data.tap do |form|
claimant_key =
case poa_request.claimant_type
when PowerOfAttorneyRequest::ClaimantTypes::DEPENDENT
'dependent'
when PowerOfAttorneyRequest::ClaimantTypes::VETERAN
'veteran'
end

form['claimant'] = form.delete(claimant_key)
form.delete('dependent')
end
end

attribute :resolution do |poa_request|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module AccreditedRepresentativePortal
Records::CLAIMANTS.each do |claimant|
claimant_id = claimant[:id]
claimant_poa_forms[claimant_id] =
FactoryBot.build(:dynamic_power_of_attorney_form)
FactoryBot.build(:power_of_attorney_form)

RESOLUTION_HISTORY_CYCLE.next.each do |resolution_trait|
accreditation = accreditation_cycle.next
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

form_data = {
dependent_claimant_data_hash = {
authorizations: {
record_disclosure: true,
record_disclosure_limitations: [],
Expand Down Expand Up @@ -51,12 +51,47 @@
}
}

veteran_claimant_data_hash = {
authorizations: {
record_disclosure: true,
record_disclosure_limitations: %w[
HIV
DRUG_ABUSE
],
address_change: true
},
dependent: nil,
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]'
}
}

FactoryBot.define do
factory :power_of_attorney_form, class: 'AccreditedRepresentativePortal::PowerOfAttorneyForm' do
data { form_data.to_json }
data { data_hash.to_json }

factory :dynamic_power_of_attorney_form do
data do
transient do
data_hash do
{
authorizations: {
record_disclosure: Faker::Boolean.boolean,
Expand Down Expand Up @@ -101,7 +136,19 @@
phone: Faker::PhoneNumber.phone_number,
email: Faker::Internet.email
}
}.to_json
}
end
end

trait :with_veteran_claimant do
transient do
data_hash { veteran_claimant_data_hash }
end
end

trait :with_dependent_claimant do
transient do
data_hash { dependent_claimant_data_hash }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@
trait :with_expiration do
resolution { create(:power_of_attorney_request_resolution, :expiration) }
end

trait :with_veteran_claimant do
association :power_of_attorney_form, :with_veteran_claimant, strategy: :build
end

trait :with_dependent_claimant do
association :power_of_attorney_form, :with_dependent_claimant, strategy: :build
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution' do
power_of_attorney_request

trait :with_veteran_claimant do
association :power_of_attorney_request, :with_veteran_claimant
end

trait :with_dependent_claimant do
association :power_of_attorney_request, :with_dependent_claimant
end

trait :acceptance do
after(:build) do |resolution|
resolution.resolving =
Expand Down
Loading

0 comments on commit 1c386dc

Please sign in to comment.