From 127b36d6f8c21bcc800a759b4af390e8e20a060b Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Tue, 7 Jan 2025 13:00:02 -0500 Subject: [PATCH] adjusting_serializer_to_match_new_front_end_data --- .../power_of_attorney_request.rb | 8 +- .../power_of_attorney_request_serializer.rb | 18 +- .../poa_request_query_params_schema.rb | 2 +- .../poa_request_search_filter_service.rb | 2 +- .../spec/factories/power_of_attorney_form.rb | 4 +- .../factories/power_of_attorney_request.rb | 36 +- .../power_of_attorney_request_decision.rb | 13 + .../power_of_attorney_request_resolution.rb | 11 +- .../v0/power_of_attorney_requests_spec.rb | 835 +++--------------- .../v0/support/poa_requests_responses.rb | 437 +++++++++ 10 files changed, 616 insertions(+), 750 deletions(-) create mode 100644 modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/support/poa_requests_responses.rb diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb index e83bd61858f..d20485848d8 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb @@ -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'") @@ -58,7 +58,7 @@ module ClaimantTypes } def expires_at - self.created_at + 60.day + created_at + 60.days end private diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer.rb index 58d0be45c1a..62641d6cf9b 100644 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer.rb +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer.rb @@ -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 @@ -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| diff --git a/modules/accredited_representative_portal/app/services/poa_request_query_params_schema.rb b/modules/accredited_representative_portal/app/services/poa_request_query_params_schema.rb index 57a6b534139..83cec5c0c01 100644 --- a/modules/accredited_representative_portal/app/services/poa_request_query_params_schema.rb +++ b/modules/accredited_representative_portal/app/services/poa_request_query_params_schema.rb @@ -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]) diff --git a/modules/accredited_representative_portal/app/services/poa_request_search_filter_service.rb b/modules/accredited_representative_portal/app/services/poa_request_search_filter_service.rb index be3feda2e02..969363bb912 100644 --- a/modules/accredited_representative_portal/app/services/poa_request_search_filter_service.rb +++ b/modules/accredited_representative_portal/app/services/poa_request_search_filter_service.rb @@ -2,7 +2,7 @@ class PoaRequestSearchFilterService DEFAULT_PARAMS = { - status: 'Pending', + status: 'pending', sortField: 'ar_power_of_attorney_requests.created_at', sortDirection: 'desc', pageNumber: 1, diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_form.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_form.rb index 1335b375060..b476c882b17 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_form.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_form.rb @@ -107,7 +107,7 @@ end end - factory :static_power_of_attorney_form do + factory :veteran_type_form do data do { authorizations: { @@ -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: 'veteran@example.com' } diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb index d5cc9079117..96db93b2f56 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb @@ -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 diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb index 0e7ee10a780..3aed78d980e 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb @@ -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 diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_resolution.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_resolution.rb index 2dc29d792d9..c1100ff26be 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_resolution.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_resolution.rb @@ -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 @@ -20,7 +21,7 @@ resolution.resolving = build( :power_of_attorney_request_decision, :acceptance, - resolution: + resolution: resolution ) end end @@ -30,7 +31,7 @@ resolution.resolving = build( :power_of_attorney_request_decision, :declination, - resolution: + resolution: resolution ) end @@ -42,7 +43,7 @@ resolution.resolving = build( :power_of_attorney_request_expiration, - resolution: + resolution: resolution ) end end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb index 84a2156cfa7..eede7ddfa20 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb @@ -1,26 +1,23 @@ # frozen_string_literal: true require_relative '../../../rails_helper' +require_relative './support/poa_requests_responses' RSpec.describe AccreditedRepresentativePortal::V0::PowerOfAttorneyRequestsController, type: :request do let(:test_user) { create(:representative_user) } - let(:poa_request) { create(:power_of_attorney_request_resolution, :declination).power_of_attorney_request } - let(:time) { "2024-12-21T04:45:37Z" } - let(:created_at) { "2024-12-21T04:45:37.000Z" } - let(:time_plus_one_day) { "2024-12-22T04:45:37Z" } - let(:created_at_plus_one_day) { "2024-12-22T04:45:37.000Z" } - let(:expires_at) { "2025-02-19T04:45:37.000Z" } + let(:poa_request) { create(:power_of_attorney_request, :with_declination) } + let(:time) { '2024-12-21T04:45:37Z' } + let(:time_plus_one_day) { '2024-12-22T04:45:37Z' } + let(:expires_at) { '2025-02-19T04:45:37.000Z' } let(:poa_requests) do - # debugger [].tap do |memo| - memo << create(:power_of_attorney_request) - memo << create(:power_of_attorney_request_resolution, :acceptance).power_of_attorney_request - # memo << create(:power_of_attorney_request, :with_acceptance, :with_static_power_of_attorney_form ) - memo << create(:power_of_attorney_request_resolution, :acceptance, - created_at: time_plus_one_day).power_of_attorney_request - memo << create(:power_of_attorney_request_resolution, :declination).power_of_attorney_request - memo << create(:power_of_attorney_request_resolution, :expiration).power_of_attorney_request + memo << create(:power_of_attorney_request, skip_resolution: true) + memo << create(:power_of_attorney_request, :with_acceptance) + memo << create(:power_of_attorney_request, :with_acceptance, :with_veteran_type_form, + created_at: time_plus_one_day) + memo << create(:power_of_attorney_request, :with_declination) + memo << create(:power_of_attorney_request, :with_expiration) end end @@ -33,727 +30,123 @@ describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do it 'returns the list of power of attorney requests and defaults to status pending' do poa_requests - # debugger get('/accredited_representative_portal/v0/power_of_attorney_requests') - debugger parsed_response = JSON.parse(response.body) expect(response).to have_http_status(:ok) expect(parsed_response).to eq( [ - { - 'id' => poa_requests[0].id, - 'claimant_id' => poa_requests[0].claimant_id, - 'created_at' => time, - 'expires_at' => expires_at, - 'power_of_attorney_form' => { - 'authorizations' => { - 'record_disclosure' => true, - 'record_disclosure_limitations' => [], - 'address_change' => true - }, - 'claimant' => { - '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' => 'veteran@example.com' - }, - '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' => 'veteran@example.com' - } - }, - 'power_of_attorney_holder' => { - 'id' => poa_requests[0].power_of_attorney_holder.id, - 'type' => 'veteran_service_organization', - 'name' => poa_requests[0].power_of_attorney_holder.name - }, - 'accredited_individual' => { - 'id' => poa_requests[0].accredited_individual.id, - 'full_name' => [ - poa_requests[0].accredited_individual.first_name, - poa_requests[0].accredited_individual.last_name - ].join(' ') - }, - 'resolution' => nil - } + PoaRequestResponses.poa_response0(poa_requests, time, expires_at) ] ) end - # it 'returns the list of accepted power of attorney requests and orders them correctly by poa_request.created_at' do - # poa_requests - - # poa_requests[1].created_at = time_plus_one_day - # poa_requests[1].save - - # get '/accredited_representative_portal/v0/power_of_attorney_requests', params: { status: 'Accepted' } - - # parsed_response = JSON.parse(response.body) - # expect(response).to have_http_status(:ok) - - # expect(parsed_response).to eq( - # [ - # { - # 'id' => poa_requests[1].id, - # 'claimant_id' => poa_requests[1].claimant_id, - # 'created_at' => time_plus_one_day, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [ - # "HIV", - # "DRUG_ABUSE" - # ], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[1].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[1].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[1].accredited_individual.id, - # 'full_name' => [ - # poa_requests[1].accredited_individual.first_name, - # poa_requests[1].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[1].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at, - # 'creator_id' => poa_requests[1].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # }, - # { - # 'id' => poa_requests[2].id, - # 'claimant_id' => poa_requests[2].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # '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' => 'veteran@example.com' - # } - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[2].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[2].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[2].accredited_individual.id, - # 'full_name' => [ - # poa_requests[2].accredited_individual.first_name, - # poa_requests[2].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[2].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at_plus_one_day, - # 'creator_id' => poa_requests[2].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # } - # ] - # ) - # end - - # it 'returns the list of accepted power of attorney requests and orders them correctly by resolution.created_at' do - # poa_requests - - # get '/accredited_representative_portal/v0/power_of_attorney_requests', - # params: { status: 'Accepted', sort_field: 'resolution.created_at', sort_direction: 'asc' } - - # parsed_response = JSON.parse(response.body) - # expect(response).to have_http_status(:ok) - - # expect(parsed_response).to eq( - # [ - # { - # 'id' => poa_requests[1].id, - # 'claimant_id' => poa_requests[1].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [ - # "HIV", - # "DRUG_ABUSE" - # ], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[1].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[1].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[1].accredited_individual.id, - # 'full_name' => [ - # poa_requests[1].accredited_individual.first_name, - # poa_requests[1].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[1].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at, - # 'creator_id' => poa_requests[1].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # }, - # { - # 'id' => poa_requests[2].id, - # 'claimant_id' => poa_requests[2].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # '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' => 'veteran@example.com' - # } - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[2].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[2].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[2].accredited_individual.id, - # 'full_name' => [ - # poa_requests[2].accredited_individual.first_name, - # poa_requests[2].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[2].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at_plus_one_day, - # 'creator_id' => poa_requests[2].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # } - # ] - # ) - # end - - # it 'orders power of attorney requests correctly by resolution.created_at desc' do - # poa_requests - - # get '/accredited_representative_portal/v0/power_of_attorney_requests', - # params: { status: 'Accepted', sort_field: 'resolution.created_at' } - - # parsed_response = JSON.parse(response.body) - # expect(response).to have_http_status(:ok) - - # expect(parsed_response).to eq( - # [ - # { - # 'id' => poa_requests[2].id, - # 'claimant_id' => poa_requests[2].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # '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' => 'veteran@example.com' - # } - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[2].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[2].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[2].accredited_individual.id, - # 'full_name' => [ - # poa_requests[2].accredited_individual.first_name, - # poa_requests[2].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[2].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at_plus_one_day, - # 'creator_id' => poa_requests[2].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # }, - # { - # 'id' => poa_requests[1].id, - # 'claimant_id' => poa_requests[1].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [ - # "HIV", - # "DRUG_ABUSE" - # ], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[1].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[1].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[1].accredited_individual.id, - # 'full_name' => [ - # poa_requests[1].accredited_individual.first_name, - # poa_requests[1].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[1].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at, - # 'creator_id' => poa_requests[1].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # } - # ] - # ) - # end - - # it 'returns paginated results' do - # poa_requests - - # get '/accredited_representative_portal/v0/power_of_attorney_requests', - # params: { status: 'Accepted', sort_field: 'resolution.created_at', page_size: 1 } - - # parsed_response = JSON.parse(response.body) - # expect(response).to have_http_status(:ok) - - # expect(parsed_response).to eq( - # [{ - # 'id' => poa_requests[2].id, - # 'claimant_id' => poa_requests[2].claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # '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' => 'veteran@example.com' - # } - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_requests[2].power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_requests[2].power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_requests[2].accredited_individual.id, - # 'full_name' => [ - # poa_requests[2].accredited_individual.first_name, - # poa_requests[2].accredited_individual.last_name - # ].join(' ') - # }, - # 'resolution' => { - # 'id' => poa_requests[2].resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at_plus_one_day, - # 'creator_id' => poa_requests[2].resolution.resolving.creator_id, - # 'decision_type' => 'acceptance' - # } - # }] - # ) - # end - - # it 'returns an error when status is not valid' do - # get '/accredited_representative_portal/v0/power_of_attorney_requests', params: { status: 'Not Real' } - - # expect(response).to have_http_status(:bad_request) - # parsed_response = JSON.parse(response.body) - - # expect(parsed_response).to eq( - # { - # 'errors' => [ - # { - # 'field' => 'status', - # 'message' => 'must be one of: Pending, Accepted, Declined' - # } - # ] - # } - # ) - # end + it 'returns the list of accepted power of attorney requests and orders them correctly by poa_request.created_at' do + poa_requests + + get '/accredited_representative_portal/v0/power_of_attorney_requests', params: { status: 'accepted' } + + parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) + + expect(parsed_response).to eq( + [ + PoaRequestResponses.poa_response_2_with_extra_day(poa_requests, time, time_plus_one_day), + PoaRequestResponses.poa_response1(poa_requests, time) + ] + ) + end + + it 'returns the list of accepted power of attorney requests and orders them correctly by resolution.created_at' do + poa_requests + + poa_requests[1].resolution.created_at = time_plus_one_day + poa_requests[1].resolution.save + + get '/accredited_representative_portal/v0/power_of_attorney_requests', + params: { status: 'accepted', sort_field: 'resolution.created_at', sort_direction: 'asc' } + + parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) + + expect(parsed_response).to eq( + [ + PoaRequestResponses.poa_response_2_with_extra_day(poa_requests, time, time_plus_one_day), + PoaRequestResponses.poa_response_1_with_resolution_extra_day(poa_requests, time, time_plus_one_day) + ] + ) + end + + it 'orders power of attorney requests correctly by resolution.created_at desc' do + poa_requests + + poa_requests[2].resolution.created_at = time_plus_one_day + poa_requests[2].resolution.save + + get '/accredited_representative_portal/v0/power_of_attorney_requests', + params: { status: 'accepted', sort_field: 'resolution.created_at' } + + parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) + + expect(parsed_response).to eq( + [ + PoaRequestResponses.poa_response_2_with_both_extra_day(poa_requests, time_plus_one_day), + PoaRequestResponses.poa_response1(poa_requests, time) + ] + ) + end + + it 'returns paginated results' do + poa_requests + + poa_requests[1].resolution.created_at = time_plus_one_day + poa_requests[1].resolution.save + + get '/accredited_representative_portal/v0/power_of_attorney_requests', + params: { status: 'accepted', sort_field: 'resolution.created_at', page_size: 1 } + + parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) + + expect(parsed_response).to eq( + [ + PoaRequestResponses.poa_response_1_with_resolution_extra_day(poa_requests, time, time_plus_one_day) + ] + ) + end + + it 'returns an error when status is not valid' do + get '/accredited_representative_portal/v0/power_of_attorney_requests', params: { status: 'Not Real' } + + expect(response).to have_http_status(:bad_request) + parsed_response = JSON.parse(response.body) + + expect(parsed_response).to eq( + { + 'errors' => [ + { + 'field' => 'status', + 'message' => 'must be one of: pending, accepted, declined' + } + ] + } + ) + end end describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests/:id' do - # it 'returns the details of a specific power of attorney request' do - # get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request.id}") - - # parsed_response = JSON.parse(response.body) - # expect(response).to have_http_status(:ok) - - # expect(parsed_response).to eq( - # { - # 'id' => poa_request.id, - # 'claimant_id' => poa_request.claimant_id, - # 'created_at' => time, - # 'expires_at' => nil, - # 'power_of_attorney_form' => { - # 'authorizations' => { - # 'record_disclosure' => true, - # 'record_disclosure_limitations' => [], - # 'address_change' => true - # }, - # 'claimant' => { - # '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' => 'veteran@example.com' - # }, - # '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' => 'veteran@example.com' - # } - # }, - # 'resolution' => { - # 'id' => poa_request.resolution.id, - # 'type' => 'decision', - # 'created_at' => created_at, - # 'creator_id' => poa_request.resolution.resolving.creator_id, - # 'reason' => 'Didn\'t authorize treatment record disclosure', - # 'decision_type' => 'declination' - # }, - # 'power_of_attorney_holder' => { - # 'id' => poa_request.power_of_attorney_holder.id, - # 'type' => 'veteran_service_organization', - # 'name' => poa_request.power_of_attorney_holder.name - # }, - # 'accredited_individual' => { - # 'id' => poa_request.accredited_individual.id, - # 'full_name' => [ - # poa_request.accredited_individual.first_name, - # poa_request.accredited_individual.last_name - # ].join(' ') - # } - # } - # ) - # end + it 'returns the details of a specific power of attorney request' do + get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request.id}") + + parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) + + expect(parsed_response).to eq( + PoaRequestResponses.singular_poa_response(poa_request, time) + ) + end end end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/support/poa_requests_responses.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/support/poa_requests_responses.rb new file mode 100644 index 00000000000..94891a0e52e --- /dev/null +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/support/poa_requests_responses.rb @@ -0,0 +1,437 @@ +# frozen_string_literal: true + +# rubocop:disable Metrics/ModuleLength +module PoaRequestResponses + # rubocop:disable Metrics/MethodLength + def self.poa_response0(poa_requests, time, expires_at) + { + 'id' => poa_requests[0].id, + 'claimant_id' => poa_requests[0].claimant_id, + 'created_at' => time, + 'expires_at' => expires_at, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => [], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + }, + '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' => 'veteran@example.com' + } + }, + 'power_of_attorney_holder' => { + 'id' => poa_requests[0].power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_requests[0].power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_requests[0].accredited_individual.id, + 'full_name' => [ + poa_requests[0].accredited_individual.first_name, + poa_requests[0].accredited_individual.last_name + ].join(' ') + }, + 'resolution' => nil + } + end + + def self.poa_response1(poa_requests, time) + { + 'id' => poa_requests[1].id, + 'claimant_id' => poa_requests[1].claimant_id, + 'created_at' => time, + 'expires_at' => nil, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => [], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + }, + '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' => 'veteran@example.com' + } + }, + 'power_of_attorney_holder' => { + 'id' => poa_requests[1].power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_requests[1].power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_requests[1].accredited_individual.id, + 'full_name' => [ + poa_requests[1].accredited_individual.first_name, + poa_requests[1].accredited_individual.last_name + ].join(' ') + }, + 'resolution' => { + 'id' => poa_requests[1].resolution.id, + 'type' => 'decision', + 'created_at' => time, + 'creator_id' => poa_requests[1].resolution.resolving.creator_id, + 'decision_type' => 'acceptance' + } + } + end + + def self.poa_response_1_with_resolution_extra_day(poa_requests, time, time_plus_one_day) + { + 'id' => poa_requests[1].id, + 'claimant_id' => poa_requests[1].claimant_id, + 'created_at' => time, + 'expires_at' => nil, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => [], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + }, + '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' => 'veteran@example.com' + } + }, + 'power_of_attorney_holder' => { + 'id' => poa_requests[1].power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_requests[1].power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_requests[1].accredited_individual.id, + 'full_name' => [ + poa_requests[1].accredited_individual.first_name, + poa_requests[1].accredited_individual.last_name + ].join(' ') + }, + 'resolution' => { + 'id' => poa_requests[1].resolution.id, + 'type' => 'decision', + 'created_at' => time_plus_one_day, + 'creator_id' => poa_requests[1].resolution.resolving.creator_id, + 'decision_type' => 'acceptance' + } + } + end + + def self.poa_response_2_with_extra_day(poa_requests, time, time_plus_one_day) + { + 'id' => poa_requests[2].id, + 'claimant_id' => poa_requests[2].claimant_id, + 'created_at' => time_plus_one_day, + 'expires_at' => nil, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => %w[ + HIV + DRUG_ABUSE + ], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + } + }, + 'power_of_attorney_holder' => { + 'id' => poa_requests[2].power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_requests[2].power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_requests[2].accredited_individual.id, + 'full_name' => [ + poa_requests[2].accredited_individual.first_name, + poa_requests[2].accredited_individual.last_name + ].join(' ') + }, + 'resolution' => { + 'id' => poa_requests[2].resolution.id, + 'type' => 'decision', + 'created_at' => time, + 'creator_id' => poa_requests[2].resolution.resolving.creator_id, + 'decision_type' => 'acceptance' + } + } + end + + def self.poa_response_2_with_both_extra_day(poa_requests, time_plus_one_day) + { + 'id' => poa_requests[2].id, + 'claimant_id' => poa_requests[2].claimant_id, + 'created_at' => time_plus_one_day, + 'expires_at' => nil, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => %w[ + HIV + DRUG_ABUSE + ], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + } + }, + 'power_of_attorney_holder' => { + 'id' => poa_requests[2].power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_requests[2].power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_requests[2].accredited_individual.id, + 'full_name' => [ + poa_requests[2].accredited_individual.first_name, + poa_requests[2].accredited_individual.last_name + ].join(' ') + }, + 'resolution' => { + 'id' => poa_requests[2].resolution.id, + 'type' => 'decision', + 'created_at' => time_plus_one_day, + 'creator_id' => poa_requests[2].resolution.resolving.creator_id, + 'decision_type' => 'acceptance' + } + } + end + + def self.singular_poa_response(poa_request, time) + { + 'id' => poa_request.id, + 'claimant_id' => poa_request.claimant_id, + 'created_at' => time, + 'expires_at' => nil, + 'power_of_attorney_form' => { + 'authorizations' => { + 'record_disclosure' => true, + 'record_disclosure_limitations' => [], + 'address_change' => true + }, + 'claimant' => { + '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' => 'veteran@example.com' + }, + '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' => 'veteran@example.com' + } + }, + 'resolution' => { + 'id' => poa_request.resolution.id, + 'type' => 'decision', + 'created_at' => time, + 'creator_id' => poa_request.resolution.resolving.creator_id, + 'reason' => 'Didn\'t authorize treatment record disclosure', + 'decision_type' => 'declination' + }, + 'power_of_attorney_holder' => { + 'id' => poa_request.power_of_attorney_holder.id, + 'type' => 'veteran_service_organization', + 'name' => poa_request.power_of_attorney_holder.name + }, + 'accredited_individual' => { + 'id' => poa_request.accredited_individual.id, + 'full_name' => [ + poa_request.accredited_individual.first_name, + poa_request.accredited_individual.last_name + ].join(' ') + } + } + end + # rubocop:enable Metrics/MethodLength + end + # rubocop:enable Metrics/ModuleLength + \ No newline at end of file