Skip to content

Commit

Permalink
adjusting_serializer_to_match_new_front_end_data
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-brown-oddball committed Jan 7, 2025
1 parent 3bd709e commit 127b36d
Show file tree
Hide file tree
Showing 10 changed files with 616 additions and 750 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ module ClaimantTypes

scope :with_status, lambda { |status|
case status
when 'Pending'
when 'pending'
where.missing(:resolution)

when 'Accepted'
when 'accepted'
# rubocop:disable Layout/LineLength
left_joins(:resolution)
.joins("LEFT OUTER JOIN ar_power_of_attorney_request_decisions AS decision ON decision.id = resolution.resolving_id AND resolution.resolving_type = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision'")
.where(resolution: { resolving_type: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision' })
.where(decision: { type: 'PowerOfAttorneyRequestAcceptance' })
# rubocop:enable Layout/LineLength
when 'Declined'
when 'declined'
# rubocop:disable Layout/LineLength
left_joins(:resolution)
.joins("LEFT OUTER JOIN ar_power_of_attorney_request_decisions AS decision ON decision.id = resolution.resolving_id AND resolution.resolving_type = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision'")
Expand All @@ -58,7 +58,7 @@ module ClaimantTypes
}

def expires_at
self.created_at + 60.day
created_at + 60.days
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer < ApplicationSerializer
attributes :claimant_id

attribute :created_at do
|poa_request| poa_request.created_at.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
attribute :created_at do |poa_request|
poa_request.created_at.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
end

attribute :expires_at do |poa_request|
poa_request.resolution.present? ? nil : poa_request.created_at + 60.day
poa_request.resolution.present? ? nil : poa_request.created_at + 60.days
end

attribute :power_of_attorney_form do |poa_request|
if poa_request.power_of_attorney_form.parsed_data["dependent"].present?
poa_request.power_of_attorney_form.parsed_data.transform_keys { |key| key == "dependent" ? "claimant" : key }
elsif poa_request.power_of_attorney_form.parsed_data["veteran"].present?
if poa_request.power_of_attorney_form.parsed_data['dependent'].present?
poa_request.power_of_attorney_form.parsed_data.transform_keys { |key| key == 'dependent' ? 'claimant' : key }
elsif poa_request.power_of_attorney_form.parsed_data['veteran'].present?
poa_request.power_of_attorney_form.parsed_data
.transform_keys { |key| key == "veteran" ? "claimant" : key }
.tap { |data| data.delete("dependent") }
.transform_keys { |key| key == 'veteran' ? 'claimant' : key }
.tap { |data| data.delete('dependent') }
end
end

Expand All @@ -35,7 +35,7 @@ class PowerOfAttorneyRequestSerializer < ApplicationSerializer

serializer
.new(poa_request.resolution)
.serializable_hash
.serializable_hash.merge(created_at: poa_request.resolution.created_at.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
end

attribute :power_of_attorney_holder do |poa_request|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'dry-schema'

PoaRequestQueryParamsSchema = Dry::Schema.Params do
required(:status).filled(:string, included_in?: %w[Pending Accepted Declined])
required(:status).filled(:string, included_in?: %w[pending accepted declined])
required(:sortField).filled(:string,
included_in?: ['resolution.created_at', 'ar_power_of_attorney_requests.created_at'])
required(:sortDirection).filled(:string, included_in?: %w[asc desc])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class PoaRequestSearchFilterService
DEFAULT_PARAMS = {
status: 'Pending',
status: 'pending',
sortField: 'ar_power_of_attorney_requests.created_at',
sortDirection: 'desc',
pageNumber: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
end
end

factory :static_power_of_attorney_form do
factory :veteran_type_form do
data do
{
authorizations: {
Expand Down Expand Up @@ -138,7 +138,7 @@
va_file_number: '123456789',
date_of_birth: '1980-12-31',
service_number: '123456789',
service_branch: "ARMY",
service_branch: 'ARMY',
phone: '1234567890',
email: '[email protected]'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,47 @@
end

after(:build) do |power_of_attorney_request, evaluator|
unless evaluator.skip_resolution
power_of_attorney_request.resolution ||= build(:power_of_attorney_request_resolution, :acceptance, skip_poa_request: true)
unless evaluator.skip_resolution || power_of_attorney_request.resolution.present?
power_of_attorney_request.resolution ||= build(
:power_of_attorney_request_resolution,
:acceptance,
power_of_attorney_request: power_of_attorney_request
)
end
end

trait :with_acceptance do
resolution { create(:power_of_attorney_request_resolution, :acceptance) }
resolution do
create(
:power_of_attorney_request_resolution,
:acceptance,
power_of_attorney_request: instance
)
end
end

trait :with_static_power_of_attorney_form do
power_of_attorney_form { FactoryBot.build(:static_power_of_attorney_form) }
trait :with_veteran_type_form do
power_of_attorney_form { FactoryBot.build(:veteran_type_form) }
end

trait :with_declination do
resolution { create(:power_of_attorney_request_resolution, :declination) }
resolution do
create(
:power_of_attorney_request_resolution,
:declination,
power_of_attorney_request: instance
)
end
end

trait :with_expiration do
resolution { create(:power_of_attorney_request_resolution, :expiration) }
resolution do
create(
:power_of_attorney_request_resolution,
:expiration,
power_of_attorney_request: instance
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
association :creator, factory: :user_account
association :resolution, factory: :power_of_attorney_request_resolution

transient do
skip_creator { false }
skip_resolution { false }
end

after(:build) do |decision, evaluator|
decision.creator ||= build(:user_account) unless evaluator.skip_creator || decision.creator.present?

unless evaluator.skip_resolution || decision.resolution.present?
decision.resolution ||= build(:power_of_attorney_request_resolution, skip_poa_request: true)
end
end

trait :acceptance do
type { AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision::Types::ACCEPTANCE }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
end

after(:build) do |resolution, evaluator|
unless evaluator.skip_poa_request
resolution.power_of_attorney_request ||= build(:power_of_attorney_request, :with_acceptance, :with_static_power_of_attorney_form, skip_resolution: true)
unless evaluator.skip_poa_request || resolution.power_of_attorney_request.present?
resolution.power_of_attorney_request ||= build(:power_of_attorney_request, :with_acceptance,
:with_veteran_type_form, skip_resolution: true)
end
end

Expand All @@ -20,7 +21,7 @@
resolution.resolving =
build(
:power_of_attorney_request_decision, :acceptance,
resolution:
resolution: resolution
)
end
end
Expand All @@ -30,7 +31,7 @@
resolution.resolving =
build(
:power_of_attorney_request_decision, :declination,
resolution:
resolution: resolution
)
end

Expand All @@ -42,7 +43,7 @@
resolution.resolving =
build(
:power_of_attorney_request_expiration,
resolution:
resolution: resolution
)
end
end
Expand Down
Loading

0 comments on commit 127b36d

Please sign in to comment.