From df700fcd3de99aa0c171eeee14658a53d0295b76 Mon Sep 17 00:00:00 2001 From: Oren Mittman Date: Fri, 20 Dec 2024 20:30:16 -0500 Subject: [PATCH] [ART-98710] Spike ARP POA request list and show endpoints --- .../power_of_attorney_requests_controller.rb | 7 +- .../power_of_attorney_request_decision.rb | 7 +- .../power_of_attorney_request_expiration.rb | 1 - .../power_of_attorney_request_resolution.rb | 8 - ...of_attorney_request_decision_serializer.rb | 22 +++ ..._attorney_request_expiration_serializer.rb | 6 + ..._attorney_request_resolution_serializer.rb | 20 +-- .../power_of_attorney_request_serializer.rb | 21 ++- .../spec/factories/power_of_attorney_form.rb | 1 - .../factories/power_of_attorney_request.rb | 14 +- ... => power_of_attorney_request_decision.rb} | 10 +- ...> power_of_attorney_request_expiration.rb} | 4 +- .../power_of_attorney_request_resolution.rb | 53 +------ .../power_of_attorney_form_spec.rb | 16 -- ...power_of_attorney_request_decision_spec.rb | 10 -- ...wer_of_attorney_request_expiration_spec.rb | 16 -- ...wer_of_attorney_request_resolution_spec.rb | 142 ----------------- .../power_of_attorney_request_spec.rb | 11 -- .../v0/power_of_attorney_requests_spec.rb | 147 ++++++++++++++++-- ...rney_request_resolution_serializer_spec.rb | 42 ----- ...wer_of_attorney_request_serializer_spec.rb | 48 ------ 21 files changed, 203 insertions(+), 403 deletions(-) create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb create mode 100644 modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb rename modules/accredited_representative_portal/spec/factories/{power_of_attorney_decision.rb => power_of_attorney_request_decision.rb} (56%) rename modules/accredited_representative_portal/spec/factories/{power_of_attorney_expiration.rb => power_of_attorney_request_expiration.rb} (73%) delete mode 100644 modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_resolution_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer_spec.rb delete mode 100644 modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_serializer_spec.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 2f0dc0a512a..9449f87b84e 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 @@ -5,12 +5,15 @@ module V0 class PowerOfAttorneyRequestsController < ApplicationController def index poa_requests = PowerOfAttorneyRequest.includes(resolution: :resolving).limit(100) - render json: PowerOfAttorneyRequestSerializer.new(poa_requests).serializable_hash, status: :ok + serializer = PowerOfAttorneyRequestSerializer.new(poa_requests, include: [:resolution]) + + render json: serializer.serializable_hash, status: :ok end def show poa_request = PowerOfAttorneyRequest.includes(resolution: :resolving).find(params[:id]) - render json: PowerOfAttorneyRequestSerializer.new(poa_request).serializable_hash, status: :ok + serializer = PowerOfAttorneyRequestSerializer.new(poa_request, include: [:resolution]) + render json: serializer.serializable_hash, status: :ok rescue ActiveRecord::RecordNotFound render json: { error: 'Record not found' }, status: :not_found end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb index 6dcc0a03e41..3bcd9768516 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb @@ -2,10 +2,13 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestDecision < ApplicationRecord - include PowerOfAttorneyRequestResolution::Resolving - self.inheritance_column = nil + module Types + ACCEPTANCE = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestAcceptance' + DECLINATION = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDeclination' + end + belongs_to :creator, class_name: 'UserAccount' end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb index a2a6fd4cd9e..5098794bf72 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb @@ -2,6 +2,5 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestExpiration < ApplicationRecord - include PowerOfAttorneyRequestResolution::Resolving end end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb index 96754cbb86d..05c0f329514 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb @@ -16,13 +16,5 @@ class PowerOfAttorneyRequestResolution < ApplicationRecord has_kms_key has_encrypted :reason, key: :kms_key, **lockbox_options - - module Resolving - extend ActiveSupport::Concern - - included do - has_one :power_of_attorney_request_resolution, as: :resolving - end - 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 new file mode 100644 index 00000000000..4a1350887c8 --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_decision_serializer.rb @@ -0,0 +1,22 @@ +# 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 new file mode 100644 index 00000000000..239c1457c8d --- /dev/null +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_expiration_serializer.rb @@ -0,0 +1,6 @@ +# 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 index 99ce0602977..5aa195f560b 100644 --- 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 @@ -4,24 +4,6 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestResolutionSerializer include JSONAPI::Serializer - attribute :id - - attribute :type do |object| - object.resolving_type.demodulize.underscore.split('_').last - end - - attribute :decision_type, if: proc { |obj| obj.resolving.respond_to?(:type) } do |object| - object.resolving.type - end - - attribute :reason - - attribute :creator_id, if: proc { |obj| obj.resolving.respond_to?(:creator_id) } do |object| - object.resolving.creator_id - end - - attribute :created_at do |object| - object.created_at.iso8601 - end + 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 4114143b6b1..2a9b1b6e385 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,18 +4,15 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestSerializer include JSONAPI::Serializer - attributes :id, :claimant_id + attributes :claimant_id, :created_at - attribute :created_at do |object| - object.created_at.iso8601 - end - - attribute :resolution do |object| - next nil if object.resolution.blank? - - AccreditedRepresentativePortal::PowerOfAttorneyRequestResolutionSerializer.new( - object.resolution - ).serializable_hash[:data][:attributes] - end + has_one :resolution, if: :resolution.to_proc, serializer: proc { |resolution| + case resolution.resolving + when PowerOfAttorneyRequestDecision + PowerOfAttorneyRequestDecisionSerializer + when PowerOfAttorneyRequestExpiration + PowerOfAttorneyRequestExpirationSerializer + 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 adb3cb7f3ca..4542c038c09 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 @@ -2,7 +2,6 @@ FactoryBot.define do factory :power_of_attorney_form, class: 'AccreditedRepresentativePortal::PowerOfAttorneyForm' do - association :power_of_attorney_request, factory: :power_of_attorney_request data_ciphertext { 'Test encrypted data' } city_bidx { Faker::Alphanumeric.alphanumeric(number: 44) } state_bidx { Faker::Alphanumeric.alphanumeric(number: 44) } 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 5d04780c575..866f3dc4c9d 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,11 +3,17 @@ FactoryBot.define do factory :power_of_attorney_request, class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest' do association :claimant, factory: :user_account - id { Faker::Internet.uuid } - created_at { Time.current } - trait :with_resolution do - resolution { create(:power_of_attorney_request_resolution, :with_decision) } + trait :with_acceptance do + resolution { create(:power_of_attorney_request_resolution, :acceptance) } + end + + trait :with_declination do + resolution { create(:power_of_attorney_request_resolution, :declination) } + end + + trait :with_expiration do + resolution { create(:power_of_attorney_request_resolution, :expiration) } end end end diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_decision.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb similarity index 56% rename from modules/accredited_representative_portal/spec/factories/power_of_attorney_decision.rb rename to modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb index 96066eafe0c..6e249a2edda 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_decision.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_decision.rb @@ -3,16 +3,14 @@ FactoryBot.define do factory :power_of_attorney_request_decision, class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision' do - id { Faker::Internet.uuid } association :creator, factory: :user_account - type { 'Approval' } - trait :declination do - type { 'Declination' } + trait :acceptance do + type { AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision::Types::ACCEPTANCE } end - trait :approval do - type { 'Approval' } + trait :declination do + type { AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision::Types::DECLINATION } end end end diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_expiration.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_expiration.rb similarity index 73% rename from modules/accredited_representative_portal/spec/factories/power_of_attorney_expiration.rb rename to modules/accredited_representative_portal/spec/factories/power_of_attorney_request_expiration.rb index 2f294a2a9fb..774154b0719 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_expiration.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request_expiration.rb @@ -2,7 +2,5 @@ FactoryBot.define do factory :power_of_attorney_request_expiration, - class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration' do - id { Faker::Internet.uuid } - end + class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration' 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 098e490a7ac..ae0e72cfae8 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 @@ -3,58 +3,19 @@ FactoryBot.define do factory :power_of_attorney_request_resolution, class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution' do - association :power_of_attorney_request - resolving_type { 'AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration' } - reason { 'Test reason for resolution' } - created_at { Time.current } + power_of_attorney_request - after(:build) do |resolution| - resolution.id ||= SecureRandom.random_number(1000) + trait :acceptance do + resolving { create(:power_of_attorney_request_decision, :acceptance) } end - trait :with_expiration do - resolving_type { 'AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration' } - resolving { create(:power_of_attorney_request_expiration) } - end - - trait :with_decision do - resolving_type { 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision' } - resolving { create(:power_of_attorney_request_decision, creator: create(:user_account)) } - end - - trait :with_declination do - resolving_type { 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision' } + trait :declination do + resolving { create(:power_of_attorney_request_decision, :declination) } reason { "Didn't authorize treatment record disclosure" } - resolving { create(:power_of_attorney_request_decision, creator: create(:user_account)) } end - trait :with_invalid_type do - resolving_type { 'AccreditedRepresentativePortal::InvalidType' } - resolving { AccreditedRepresentativePortal::InvalidType.new } + trait :expiration do + resolving { create(:power_of_attorney_request_expiration) } end end end - -module AccreditedRepresentativePortal - class InvalidType - def method_missing(_method, *_args) = self - - def respond_to_missing?(_method, _include_private = false) = true - - def id = nil - - def self.method_missing(_method, *_args) = NullObject.new - - def self.respond_to_missing?(_method, _include_private = false) = true - end - - class NullObject - def method_missing(_method, *_args) = self - - def respond_to_missing?(*) = true - - def nil? = true - - def to_s = '' - end -end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb deleted file mode 100644 index 0767cf0ceca..00000000000 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyForm, type: :model do - describe 'associations' do - it { is_expected.to belong_to(:power_of_attorney_request) } - end - - describe 'creation' do - it 'creates a valid form' do - form = build(:power_of_attorney_form, data_ciphertext: 'test_data') - expect(form).to be_valid - end - end -end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb deleted file mode 100644 index c2376dc7ecd..00000000000 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision, type: :model do - describe 'associations' do - it { is_expected.to belong_to(:creator).class_name('UserAccount') } - it { is_expected.to have_one(:power_of_attorney_request_resolution) } - end -end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb deleted file mode 100644 index 2213312df20..00000000000 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration, type: :model do - describe 'associations' do - it { is_expected.to have_one(:power_of_attorney_request_resolution) } - end - - describe 'validations' do - it 'creates a valid record' do - expiration = create(:power_of_attorney_request_expiration) - expect(expiration).to be_valid - end - end -end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_resolution_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_resolution_spec.rb deleted file mode 100644 index e7a006aac77..00000000000 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_resolution_spec.rb +++ /dev/null @@ -1,142 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -mod = AccreditedRepresentativePortal -RSpec.describe mod::PowerOfAttorneyRequestResolution, type: :model do - describe 'associations' do - let(:power_of_attorney_request) { create(:power_of_attorney_request) } - - it { is_expected.to belong_to(:power_of_attorney_request) } - - it 'can resolve to PowerOfAttorneyRequestExpiration' do - expiration = create(:power_of_attorney_request_expiration) - resolution = described_class.create!( - resolving: expiration, - power_of_attorney_request: power_of_attorney_request, - created_at: Time.zone.now, - encrypted_kms_key: SecureRandom.hex(16) - ) - - expect(resolution.resolving).to eq(expiration) - expect(resolution.resolving_type).to eq('AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration') - end - - it 'can resolve to PowerOfAttorneyRequestDecision' do - decision = create(:power_of_attorney_request_decision) - resolution = described_class.create!( - resolving: decision, - power_of_attorney_request: power_of_attorney_request, - created_at: Time.zone.now, - encrypted_kms_key: SecureRandom.hex(16) - ) - - expect(resolution.resolving).to eq(decision) - expect(resolution.resolving_type).to eq('AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision') - end - end - - describe 'delegated_type resolving' do - it 'is valid with expiration resolving' do - resolution = create(:power_of_attorney_request_resolution, :with_expiration) - expect(resolution).to be_valid - expect(resolution.resolving).to be_a(mod::PowerOfAttorneyRequestExpiration) - end - - it 'is valid with decision resolving' do - resolution = create(:power_of_attorney_request_resolution, :with_decision) - expect(resolution).to be_valid - expect(resolution.resolving).to be_a(mod::PowerOfAttorneyRequestDecision) - end - - it 'is invalid with null resolving_type and resolving_id' do - resolution = build(:power_of_attorney_request_resolution, resolving_type: nil, resolving_id: nil) - expect(resolution).not_to be_valid - end - end - - describe 'heterogeneous list behavior' do - it 'conveniently returns heterogeneous lists' do - travel_to Time.zone.parse('2024-11-25T09:46:24Z') do - creator = create(:user_account) - - ids = [] - - # Persisted resolving records - decision_acceptance = mod::PowerOfAttorneyRequestDecision.create!( - type: 'acceptance', - creator: creator - ) - decision_declination = mod::PowerOfAttorneyRequestDecision.create!( - type: 'declination', - creator: creator - ) - expiration = mod::PowerOfAttorneyRequestExpiration.create! - - # Associate resolving records - ids << described_class.create!( - power_of_attorney_request: create(:power_of_attorney_request), - resolving: decision_acceptance, - encrypted_kms_key: SecureRandom.hex(16), - created_at: Time.current - ).id - - ids << described_class.create!( - power_of_attorney_request: create(:power_of_attorney_request), - resolving: decision_declination, - encrypted_kms_key: SecureRandom.hex(16), - created_at: Time.current - ).id - - ids << described_class.create!( - power_of_attorney_request: create(:power_of_attorney_request), - resolving: expiration, - encrypted_kms_key: SecureRandom.hex(16), - created_at: Time.current - ).id - - resolutions = described_class.includes(:resolving).find(ids) - - # Serialize for comparison - actual = - resolutions.map do |resolution| - serialized = - case resolution.resolving - when mod::PowerOfAttorneyRequestDecision - { - type: 'decision', - decision_type: resolution.resolving.type - } - when mod::PowerOfAttorneyRequestExpiration - { - type: 'expiration' - } - end - - serialized.merge!( - created_at: resolution.created_at.iso8601 - ) - end - - expect(actual).to eq( - [ - { - type: 'decision', - decision_type: 'acceptance', - created_at: '2024-11-25T09:46:24Z' - }, - { - type: 'decision', - decision_type: 'declination', - created_at: '2024-11-25T09:46:24Z' - }, - { - type: 'expiration', - created_at: '2024-11-25T09:46:24Z' - } - ] - ) - end - end - end -end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb deleted file mode 100644 index 81b29d90317..00000000000 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequest, type: :model do - describe 'associations' do - it { is_expected.to belong_to(:claimant).class_name('UserAccount') } - it { is_expected.to have_one(:power_of_attorney_form) } - it { is_expected.to have_one(: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 b9f4f6f2b58..f1f1a2cccee 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 @@ -4,12 +4,22 @@ RSpec.describe AccreditedRepresentativePortal::V0::PowerOfAttorneyRequestsController, type: :request do let(:test_user) { create(:representative_user) } - let(:poa_request) { create(:power_of_attorney_request) } - let(:poa_requests) { create_list(:power_of_attorney_request, 3) } + let(:poa_request) { create(:power_of_attorney_request_resolution, :declination).power_of_attorney_request } + let(:time) { '2024-12-21T04:45:37.458Z' } + + let(:poa_requests) do + [].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_resolution, :declination).power_of_attorney_request + memo << create(:power_of_attorney_request_resolution, :expiration).power_of_attorney_request + end + end before do Flipper.enable(:accredited_representative_portal_pilot) login_as(test_user) + travel_to(time) end describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do @@ -18,14 +28,98 @@ get('/accredited_representative_portal/v0/power_of_attorney_requests') - expect(response).to have_http_status(:ok) parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) - expected_response = AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer - .new(poa_requests) - .serializable_hash - - expect(parsed_response.to_json).to eq(expected_response.to_json) + 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 + }, + 'relationships' => {} + }, + { + 'id' => poa_requests[1].id, + 'type' => 'power_of_attorney_request', + 'attributes' => { + 'claimant_id' => poa_requests[1].claimant_id, + 'created_at' => time + }, + 'relationships' => { + 'resolution' => { + 'data' => { + 'id' => poa_requests[1].resolution.id, + 'type' => 'power_of_attorney_request_decision' + } + } + } + }, + { + 'id' => poa_requests[2].id, + 'type' => 'power_of_attorney_request', + 'attributes' => { + 'claimant_id' => poa_requests[2].claimant_id, + 'created_at' => time + }, + 'relationships' => { + 'resolution' => { + 'data' => { + 'id' => poa_requests[2].resolution.id, + 'type' => 'power_of_attorney_request_decision' + } + } + } + }, + { + 'id' => poa_requests[3].id, + 'type' => 'power_of_attorney_request', + 'attributes' => { + 'claimant_id' => poa_requests[3].claimant_id, + 'created_at' => time + }, + 'relationships' => { + 'resolution' => { + 'data' => { + 'id' => poa_requests[3].resolution.id, + 'type' => 'power_of_attorney_request_expiration' + } + } + } + } + ], + 'included' => [ + { + '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' + } + }, + { + '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' + } + }, + { + 'id' => poa_requests[3].resolution.id, + 'type' => 'power_of_attorney_request_expiration', + 'attributes' => { + 'created_at' => time + } + } + ] + ) end end @@ -33,14 +127,39 @@ it 'returns the details of a specific power of attorney request' do get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request.id}") - expect(response).to have_http_status(:ok) parsed_response = JSON.parse(response.body) + expect(response).to have_http_status(:ok) - expected_response = AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer - .new(poa_request) - .serializable_hash - - expect(parsed_response.to_json).to eq(expected_response.to_json) + 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 + }, + 'relationships' => { + 'resolution' => { + 'data' => { + 'id' => poa_request.resolution.id, + 'type' => 'power_of_attorney_request_decision' + } + } + } + }, + 'included' => [ + { + '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' + } + } + ] + ) end end end diff --git a/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer_spec.rb b/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer_spec.rb deleted file mode 100644 index 3df2538fd8b..00000000000 --- a/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_resolution_serializer_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestResolutionSerializer, type: :serializer do - describe 'serialization' do - subject { described_class.new(resolution).serializable_hash[:data][:attributes] } - - let(:user) { create(:user_account) } - let(:resolution) do - create(:power_of_attorney_request_resolution, resolving: resolving, reason: 'Did not authorize') - end - - context 'when resolving is a Decision' do - let(:resolving) { create(:power_of_attorney_request_decision, type: 'declination', creator: user) } - - it 'serializes resolution with decision-specific fields' do - expect(subject).to eq( - id: resolution.id, - created_at: resolution.created_at.iso8601, - reason: 'Did not authorize', - type: 'decision', - decision_type: 'declination', - creator_id: user.id - ) - end - end - - context 'when resolving is an Expiration' do - let(:resolving) { create(:power_of_attorney_request_expiration) } - - it 'serializes resolution with expiration-specific fields' do - expect(subject).to eq( - id: resolution.id, - created_at: resolution.created_at.iso8601, - reason: 'Did not authorize', - type: 'expiration' - ) - end - end - end -end diff --git a/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_serializer_spec.rb b/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_serializer_spec.rb deleted file mode 100644 index b923cf977bd..00000000000 --- a/modules/accredited_representative_portal/spec/serializers/accredited_representative_portal/power_of_attorney_request_serializer_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../rails_helper' - -RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer, type: :serializer do - describe 'serialization' do - subject { described_class.new(poa_request).serializable_hash[:data][:attributes] } - - let(:claimant) { create(:user_account) } - let(:poa_request) { create(:power_of_attorney_request, claimant: claimant, resolution: resolution) } - - context 'when resolution exists' do - let(:resolution) do - create(:power_of_attorney_request_resolution, - resolving: create(:power_of_attorney_request_decision, type: 'declination')) - end - - it 'serializes POA request with resolution' do - expect(subject).to eq( - id: poa_request.id, - claimant_id: poa_request.claimant_id, - created_at: poa_request.created_at.iso8601, - resolution: { - id: resolution.id, - created_at: resolution.created_at.iso8601, - reason: resolution.reason, - type: 'decision', - decision_type: 'declination', - creator_id: resolution.resolving.creator_id - } - ) - end - end - - context 'when resolution is absent' do - let(:resolution) { nil } - - it 'serializes POA request without resolution' do - expect(subject).to eq( - id: poa_request.id, - claimant_id: poa_request.claimant_id, - created_at: poa_request.created_at.iso8601, - resolution: nil - ) - end - end - end -end