From 1ef45c0d6ee33c8dec17508bd1ae4e0c39df764d Mon Sep 17 00:00:00 2001 From: Oren Mittman Date: Mon, 23 Dec 2024 02:54:06 -0500 Subject: [PATCH] [ART] Serialize POA form data with POA request --- .../power_of_attorney_requests_controller.rb | 1 + .../power_of_attorney_form.rb | 50 ++- .../power_of_attorney_request.rb | 24 +- .../application_serializer.rb | 25 ++ ...of_attorney_request_decision_serializer.rb | 22 -- ..._attorney_request_expiration_serializer.rb | 6 - ..._attorney_request_resolution_serializer.rb | 9 - .../power_of_attorney_request_serializer.rb | 16 +- .../decision_serializer.rb | 26 ++ .../expiration_serializer.rb | 9 + .../resolution_serializer.rb | 9 + .../spec/factories/power_of_attorney_form.rb | 58 ++- .../factories/power_of_attorney_request.rb | 1 + .../v0/power_of_attorney_requests_spec.rb | 356 ++++++++++++++---- 14 files changed, 492 insertions(+), 120 deletions(-) create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/application_serializer.rb delete mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb delete mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb delete mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer.rb create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/decision_serializer.rb create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/expiration_serializer.rb create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/resolution_serializer.rb diff --git a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/power_of_attorney_requests_controller.rb b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/power_of_attorney_requests_controller.rb index a7291752958..f376037b0fc 100644 --- a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/power_of_attorney_requests_controller.rb +++ b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/power_of_attorney_requests_controller.rb @@ -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 diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb index 1f66334e366..d3d034b98d0 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb @@ -2,19 +2,57 @@ module AccreditedRepresentativePortal class PowerOfAttorneyForm < ApplicationRecord - self.ignored_columns += %w[city_bidx state_bidx zipcode_bidx] - belongs_to :power_of_attorney_request, class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest', inverse_of: :power_of_attorney_form + 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 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 18af415b22c..399ff936876 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 @@ -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 + end + end end end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/application_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/application_serializer.rb new file mode 100644 index 00000000000..e914fb40460 --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/application_serializer.rb @@ -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 diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb deleted file mode 100644 index 4a1350887c8..00000000000 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module AccreditedRepresentativePortal - class PowerOfAttorneyRequestDecisionSerializer < PowerOfAttorneyRequestResolutionSerializer - attribute :decision_type do |resolution| - case resolution.resolving.type - when PowerOfAttorneyRequestDecision::Types::ACCEPTANCE - 'acceptance' - when PowerOfAttorneyRequestDecision::Types::DECLINATION - 'declination' - end - end - - attribute :reason, if: proc { |resolution| - resolution.resolving.type == PowerOfAttorneyRequestDecision::Types::DECLINATION - } - - attribute :creator_id do |resolution| - resolution.resolving.creator_id - end - end -end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb deleted file mode 100644 index 239c1457c8d..00000000000 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -module AccreditedRepresentativePortal - class PowerOfAttorneyRequestExpirationSerializer < PowerOfAttorneyRequestResolutionSerializer - end -end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer.rb deleted file mode 100644 index 5aa195f560b..00000000000 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module AccreditedRepresentativePortal - class PowerOfAttorneyRequestResolutionSerializer - include JSONAPI::Serializer - - attributes :created_at - end -end 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 242bbc1db1a..1710d9a77b2 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 @@ -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 @@ -12,12 +14,14 @@ class PowerOfAttorneyRequestSerializer serializer = case poa_request.resolution.resolving when PowerOfAttorneyRequestDecision - PowerOfAttorneyRequestDecisionSerializer + DecisionSerializer when PowerOfAttorneyRequestExpiration - PowerOfAttorneyRequestExpirationSerializer + ExpirationSerializer end - serializer.new(poa_request.resolution) + serializer + .new(poa_request.resolution) + .serializable_hash end end end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/decision_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/decision_serializer.rb new file mode 100644 index 00000000000..32f80146741 --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/decision_serializer.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module AccreditedRepresentativePortal + class PowerOfAttorneyRequestSerializer + class DecisionSerializer < ResolutionSerializer + attribute(:type) { 'decision' } + + attribute :decision_type do |resolution| + case resolution.resolving.type + when PowerOfAttorneyRequestDecision::Types::ACCEPTANCE + 'acceptance' + when PowerOfAttorneyRequestDecision::Types::DECLINATION + 'declination' + end + end + + attribute :reason, if: proc { |resolution| + resolution.resolving.type == PowerOfAttorneyRequestDecision::Types::DECLINATION + } + + attribute :creator_id do |resolution| + resolution.resolving.creator_id + end + end + end +end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/expiration_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/expiration_serializer.rb new file mode 100644 index 00000000000..9da789dcee8 --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/expiration_serializer.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module AccreditedRepresentativePortal + class PowerOfAttorneyRequestSerializer + class ExpirationSerializer < ResolutionSerializer + attribute(:type) { 'expiration' } + end + end +end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/resolution_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/resolution_serializer.rb new file mode 100644 index 00000000000..fc4c97068e4 --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/resolution_serializer.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module AccreditedRepresentativePortal + class PowerOfAttorneyRequestSerializer + class ResolutionSerializer < ApplicationSerializer + attributes :created_at + end + end +end 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 4542c038c09..8e0826ef9f1 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 @@ -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": "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" + } + } +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 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 866f3dc4c9d..10929482348 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 @@ -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) } 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 88e0d841866..d4b59a09326 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 @@ -23,7 +23,7 @@ end describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do - it 'returns the list of power of attorney requests', skip: 'temp skip' do + it 'returns the list of power of attorney requests' do poa_requests get('/accredited_representative_portal/v0/power_of_attorney_requests') @@ -32,70 +32,250 @@ expect(response).to have_http_status(:ok) expect(parsed_response).to eq( - 'data' => [ + [ { 'id' => poa_requests[0].id, - 'type' => 'power_of_attorney_request', - 'attributes' => { - 'claimant_id' => poa_requests[0].claimant_id, - 'created_at' => time, - 'resolution' => nil - } + 'claimant_id' => poa_requests[0].claimant_id, + 'claimant_type' => 'dependent', + 'created_at' => time, + 'power_of_attorney_form' => { + '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' => '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' => nil }, { 'id' => poa_requests[1].id, - 'type' => 'power_of_attorney_request', - 'attributes' => { - 'claimant_id' => poa_requests[1].claimant_id, - 'created_at' => time, - 'resolution' => { - 'data' => { - 'id' => poa_requests[1].resolution.id, - 'type' => 'power_of_attorney_request_decision', - 'attributes' => { - 'created_at' => time, - 'creator_id' => poa_requests[1].resolution.resolving.creator_id, - 'decision_type' => 'acceptance' - } - } + 'claimant_id' => poa_requests[1].claimant_id, + 'claimant_type' => 'dependent', + 'created_at' => time, + 'power_of_attorney_form' => { + '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' => '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_requests[1].resolution.id, + 'type' => 'decision', + 'created_at' => time, + 'creator_id' => poa_requests[1].resolution.resolving.creator_id, + 'decision_type' => 'acceptance' } }, { 'id' => poa_requests[2].id, - 'type' => 'power_of_attorney_request', - 'attributes' => { - 'claimant_id' => poa_requests[2].claimant_id, - 'created_at' => time, - 'resolution' => { - 'data' => { - 'id' => poa_requests[2].resolution.id, - 'type' => 'power_of_attorney_request_decision', - 'attributes' => { - 'created_at' => time, - 'creator_id' => poa_requests[2].resolution.resolving.creator_id, - 'reason' => 'Didn\'t authorize treatment record disclosure', - 'decision_type' => 'declination' - } - } + 'claimant_id' => poa_requests[2].claimant_id, + 'claimant_type' => 'dependent', + 'created_at' => time, + 'power_of_attorney_form' => { + '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' => '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_requests[2].resolution.id, + 'type' => 'decision', + 'created_at' => time, + 'creator_id' => poa_requests[2].resolution.resolving.creator_id, + 'reason' => 'Didn\'t authorize treatment record disclosure', + 'decision_type' => 'declination' } }, { 'id' => poa_requests[3].id, - 'type' => 'power_of_attorney_request', - 'attributes' => { - 'claimant_id' => poa_requests[3].claimant_id, - 'created_at' => time, - 'resolution' => { - 'data' => { - 'id' => poa_requests[3].resolution.id, - 'type' => 'power_of_attorney_request_expiration', - 'attributes' => { - 'created_at' => time - } - } + 'claimant_id' => poa_requests[3].claimant_id, + 'claimant_type' => 'dependent', + 'created_at' => time, + 'power_of_attorney_form' => { + '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' => '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_requests[3].resolution.id, + 'type' => 'expiration', + 'created_at' => time } } ] @@ -104,31 +284,75 @@ end describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests/:id' do - it 'returns the details of a specific power of attorney request', skip: 'temp skip' 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( - 'data' => { + { 'id' => poa_request.id, - 'type' => 'power_of_attorney_request', - 'attributes' => { - 'claimant_id' => poa_request.claimant_id, - 'created_at' => time, - 'resolution' => { - 'data' => { - 'id' => poa_request.resolution.id, - 'type' => 'power_of_attorney_request_decision', - 'attributes' => { - 'created_at' => time, - 'creator_id' => poa_request.resolution.resolving.creator_id, - 'reason' => 'Didn\'t authorize treatment record disclosure', - 'decision_type' => 'declination' - } - } + 'claimant_id' => poa_request.claimant_id, + 'claimant_type' => 'dependent', + 'created_at' => time, + "power_of_attorney_form" => { + "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" => "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' } } )