-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): Add serializers for PowerOfAttorneyRequest and Resolution wit…
…h specs - Implement `PowerOfAttorneyRequestSerializer` to handle serialization of power of attorney requests, including nested resolution data. - Implement `PowerOfAttorneyRequestResolutionSerializer` to serialize resolution details, accommodating various resolution subtypes. - Add comprehensive specs for both serializers to ensure accurate and dynamic handling of attributes. - Adjust model factories accordingly
- Loading branch information
Showing
8 changed files
with
133 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...izers/accredited_representative_portal/power_of_attorney_request_resolution_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../accredited_representative_portal/power_of_attorney_request_resolution_serializer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 |
109 changes: 41 additions & 68 deletions
109
...serializers/accredited_representative_portal/power_of_attorney_request_serializer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/serializers/power_of_attorney_request_serializer_spec.rb | ||
require 'rails_helper' | ||
|
||
RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer do | ||
subject { described_class.new(request).serializable_hash[:data][:attributes] } | ||
|
||
let(:request) { create(:power_of_attorney_request, created_at: '2024-12-17T00:30:55Z') } | ||
|
||
context 'when resolution is nil' do | ||
it 'returns the request without resolution' do | ||
expect(subject).to eq({ | ||
id: request.id, | ||
claimant_id: request.claimant_id, | ||
created_at: '2024-12-17T00:30:55.000Z', | ||
resolution: nil | ||
}) | ||
end | ||
end | ||
|
||
context 'when resolution is an expiration' do | ||
let(:resolution) do | ||
create(:power_of_attorney_request_resolution, :with_expiration, reason: 'Test reason for resolution') | ||
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 | ||
|
||
before { request.update(resolution: resolution) } | ||
|
||
it 'includes resolution details with type expiration and reason' do | ||
expect(subject[:resolution]).to eq({ | ||
id: resolution.id, | ||
type: 'power_of_attorney_request_expiration', | ||
created_at: resolution.created_at.iso8601(3), | ||
reason: 'Test reason for resolution' | ||
}) | ||
end | ||
end | ||
|
||
context 'when resolution is a decision with creator_id' do | ||
let(:resolution) do | ||
create(:power_of_attorney_request_resolution, :with_decision) | ||
end | ||
|
||
before { request.update(resolution: resolution) } | ||
|
||
it 'includes resolution details with type decision and creator_id' do | ||
expect(subject[:resolution]).to eq({ | ||
id: resolution.id, | ||
type: 'power_of_attorney_request_decision', | ||
created_at: resolution.created_at.iso8601(3), | ||
reason: 'Test reason for resolution', | ||
creator_id: resolution.resolving.creator_id | ||
}) | ||
end | ||
end | ||
|
||
context 'when resolution is a declination with reason' do | ||
let(:resolution) do | ||
create(:power_of_attorney_request_resolution, :with_declination, | ||
reason: "Didn't authorize treatment record disclosure") | ||
end | ||
|
||
before { request.update(resolution: resolution) } | ||
|
||
it 'includes resolution details with type decision, reason, and creator_id' do | ||
expect(subject[:resolution]).to eq({ | ||
id: resolution.id, | ||
type: 'power_of_attorney_request_decision', | ||
created_at: resolution.created_at.iso8601(3), | ||
reason: "Didn't authorize treatment record disclosure", | ||
creator_id: resolution.resolving.creator_id | ||
}) | ||
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 |