Skip to content

Commit 1c386dc

Browse files
patrick-brown-oddballojbucaonihil2501
authored
15: [ART] Have serializers match front end data (#20254)
* 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]>
1 parent 0d4ec63 commit 1c386dc

File tree

10 files changed

+372
-273
lines changed

10 files changed

+372
-273
lines changed

modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb

+20-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module ClaimantTypes
99
].freeze
1010
end
1111

12+
EXPIRY_DURATION = 60.days
13+
1214
belongs_to :claimant, class_name: 'UserAccount'
1315

1416
has_one :power_of_attorney_form,
@@ -31,14 +33,27 @@ module ClaimantTypes
3133

3234
delegate :poa_code, to: :accredited_individual
3335

36+
def expires_at
37+
created_at + EXPIRY_DURATION if unresolved?
38+
end
39+
40+
def unresolved?
41+
!resolved?
42+
end
43+
44+
def resolved?
45+
resolution.present?
46+
end
47+
3448
private
3549

3650
def set_claimant_type
37-
self.claimant_type = if power_of_attorney_form.parsed_data['dependent']
38-
ClaimantTypes::DEPENDENT
39-
elsif power_of_attorney_form.parsed_data['veteran']
40-
ClaimantTypes::VETERAN
41-
end
51+
self.claimant_type =
52+
if power_of_attorney_form.parsed_data['dependent']
53+
ClaimantTypes::DEPENDENT
54+
elsif power_of_attorney_form.parsed_data['veteran']
55+
ClaimantTypes::VETERAN
56+
end
4257
end
4358
end
4459
end

modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22

33
module AccreditedRepresentativePortal
44
class PowerOfAttorneyRequestSerializer < ApplicationSerializer
5-
attributes :claimant_id, :claimant_type, :created_at
5+
attributes :claimant_id, :created_at, :expires_at
66

77
attribute :power_of_attorney_form do |poa_request|
8-
poa_request.power_of_attorney_form.parsed_data
8+
poa_request.power_of_attorney_form.parsed_data.tap do |form|
9+
claimant_key =
10+
case poa_request.claimant_type
11+
when PowerOfAttorneyRequest::ClaimantTypes::DEPENDENT
12+
'dependent'
13+
when PowerOfAttorneyRequest::ClaimantTypes::VETERAN
14+
'veteran'
15+
end
16+
17+
form['claimant'] = form.delete(claimant_key)
18+
form.delete('dependent')
19+
end
920
end
1021

1122
attribute :resolution do |poa_request|

modules/accredited_representative_portal/lib/tasks/seed.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module AccreditedRepresentativePortal
116116
Records::CLAIMANTS.each do |claimant|
117117
claimant_id = claimant[:id]
118118
claimant_poa_forms[claimant_id] =
119-
FactoryBot.build(:dynamic_power_of_attorney_form)
119+
FactoryBot.build(:power_of_attorney_form)
120120

121121
RESOLUTION_HISTORY_CYCLE.next.each do |resolution_trait|
122122
accreditation = accreditation_cycle.next

modules/accredited_representative_portal/spec/factories/power_of_attorney_form.rb

+52-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
form_data = {
3+
dependent_claimant_data_hash = {
44
authorizations: {
55
record_disclosure: true,
66
record_disclosure_limitations: [],
@@ -51,12 +51,47 @@
5151
}
5252
}
5353

54+
veteran_claimant_data_hash = {
55+
authorizations: {
56+
record_disclosure: true,
57+
record_disclosure_limitations: %w[
58+
HIV
59+
DRUG_ABUSE
60+
],
61+
address_change: true
62+
},
63+
dependent: nil,
64+
veteran: {
65+
name: {
66+
first: 'John',
67+
middle: 'Middle',
68+
last: 'Doe'
69+
},
70+
address: {
71+
address_line1: '123 Main St',
72+
address_line2: 'Apt 1',
73+
city: 'Springfield',
74+
state_code: 'IL',
75+
country: 'US',
76+
zip_code: '62704',
77+
zip_code_suffix: '6789'
78+
},
79+
ssn: '123456789',
80+
va_file_number: '123456789',
81+
date_of_birth: '1980-12-31',
82+
service_number: '123456789',
83+
service_branch: 'ARMY',
84+
phone: '1234567890',
85+
86+
}
87+
}
88+
5489
FactoryBot.define do
5590
factory :power_of_attorney_form, class: 'AccreditedRepresentativePortal::PowerOfAttorneyForm' do
56-
data { form_data.to_json }
91+
data { data_hash.to_json }
5792

58-
factory :dynamic_power_of_attorney_form do
59-
data do
93+
transient do
94+
data_hash do
6095
{
6196
authorizations: {
6297
record_disclosure: Faker::Boolean.boolean,
@@ -101,7 +136,19 @@
101136
phone: Faker::PhoneNumber.phone_number,
102137
email: Faker::Internet.email
103138
}
104-
}.to_json
139+
}
140+
end
141+
end
142+
143+
trait :with_veteran_claimant do
144+
transient do
145+
data_hash { veteran_claimant_data_hash }
146+
end
147+
end
148+
149+
trait :with_dependent_claimant do
150+
transient do
151+
data_hash { dependent_claimant_data_hash }
105152
end
106153
end
107154
end

modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb

+8
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@
1919
trait :with_expiration do
2020
resolution { create(:power_of_attorney_request_resolution, :expiration) }
2121
end
22+
23+
trait :with_veteran_claimant do
24+
association :power_of_attorney_form, :with_veteran_claimant, strategy: :build
25+
end
26+
27+
trait :with_dependent_claimant do
28+
association :power_of_attorney_form, :with_dependent_claimant, strategy: :build
29+
end
2230
end
2331
end

modules/accredited_representative_portal/spec/factories/power_of_attorney_request_resolution.rb

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution' do
66
power_of_attorney_request
77

8+
trait :with_veteran_claimant do
9+
association :power_of_attorney_request, :with_veteran_claimant
10+
end
11+
12+
trait :with_dependent_claimant do
13+
association :power_of_attorney_request, :with_dependent_claimant
14+
end
15+
816
trait :acceptance do
917
after(:build) do |resolution|
1018
resolution.resolving =

0 commit comments

Comments
 (0)