-
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.
Add serializer for PowerOfAttorneyRequest with controller and tests
- Implement `PowerOfAttorneyRequestSerializer` to standardize JSON:API output - Add request specs for controller endpoints (`index` and `show`) - Add serializer specs to ensure proper formatting of resolution details - Normalize response keys for consistency in test expectations
- Loading branch information
Showing
4 changed files
with
80 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,54 +3,21 @@ | |
module AccreditedRepresentativePortal | ||
module V0 | ||
class PowerOfAttorneyRequestsController < ApplicationController | ||
POA_REQUEST_ITEM_MOCK_DATA = { | ||
status: 'Pending', | ||
declinedReason: nil, | ||
powerOfAttorneyCode: '091', | ||
submittedAt: '2024-04-30T11:03:17Z', | ||
acceptedOrDeclinedAt: nil, | ||
isAddressChangingAuthorized: false, | ||
isTreatmentDisclosureAuthorized: true, | ||
veteran: { | ||
firstName: 'Jon', | ||
middleName: nil, | ||
lastName: 'Smith', | ||
participantId: '6666666666666' | ||
}, | ||
representative: { | ||
email: '[email protected]', | ||
firstName: 'Jane', | ||
lastName: 'Doe' | ||
}, | ||
claimant: { | ||
firstName: 'Sam', | ||
lastName: 'Smith', | ||
participantId: '777777777777777', | ||
relationshipToVeteran: 'Child' | ||
}, | ||
claimantAddress: { | ||
city: 'Hartford', | ||
state: 'CT', | ||
zip: '06107', | ||
country: 'GU', | ||
militaryPostOffice: nil, | ||
militaryPostalCode: nil | ||
} | ||
}.freeze | ||
|
||
POA_REQUEST_LIST_MOCK_DATA = [ | ||
POA_REQUEST_ITEM_MOCK_DATA, | ||
POA_REQUEST_ITEM_MOCK_DATA, | ||
POA_REQUEST_ITEM_MOCK_DATA | ||
].freeze | ||
|
||
def index | ||
render json: POA_REQUEST_LIST_MOCK_DATA | ||
requests = PowerOfAttorneyRequest.includes(:resolution) | ||
render json: PowerOfAttorneyRequestSerializer.new(requests).serializable_hash, status: :ok | ||
end | ||
|
||
def show | ||
render json: POA_REQUEST_ITEM_MOCK_DATA | ||
request = PowerOfAttorneyRequest.includes(:resolution).find(params[:id]) | ||
render json: PowerOfAttorneyRequestSerializer.new(request).serializable_hash, status: :ok | ||
rescue ActiveRecord::RecordNotFound | ||
render json: { error: 'Record not found' }, status: :not_found | ||
end | ||
|
||
private | ||
|
||
def authenticate; end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,47 +4,58 @@ | |
|
||
RSpec.describe AccreditedRepresentativePortal::V0::PowerOfAttorneyRequestsController, type: :request do | ||
let(:test_user) { create(:representative_user) } | ||
let(:poa_request_details_id) { '123' } | ||
let(:poa_request_details_mock_data) do | ||
{ | ||
'status' => 'Pending', | ||
'declinedReason' => nil, | ||
'powerOfAttorneyCode' => '091', | ||
'submittedAt' => '2024-04-30T11:03:17Z', | ||
'acceptedOrDeclinedAt' => nil, | ||
'isAddressChangingAuthorized' => false, | ||
'isTreatmentDisclosureAuthorized' => true, | ||
'veteran' => { 'firstName' => 'Jon', 'middleName' => nil, 'lastName' => 'Smith', | ||
'participantId' => '6666666666666' }, | ||
'representative' => { 'email' => '[email protected]', 'firstName' => 'Jane', 'lastName' => 'Doe' }, | ||
'claimant' => { 'firstName' => 'Sam', 'lastName' => 'Smith', 'participantId' => '777777777777777', | ||
'relationshipToVeteran' => 'Child' }, | ||
'claimantAddress' => { 'city' => 'Hartford', 'state' => 'CT', 'zip' => '06107', 'country' => 'GU', | ||
'militaryPostOffice' => nil, 'militaryPostalCode' => nil } | ||
} | ||
end | ||
let(:poa_request_list_mock_data) do | ||
[poa_request_details_mock_data, poa_request_details_mock_data, poa_request_details_mock_data] | ||
end | ||
let(:poa_request) { create(:power_of_attorney_request) } | ||
let(:poa_requests) { create_list(:power_of_attorney_request, 3) } | ||
|
||
before do | ||
Flipper.enable(:accredited_representative_portal_pilot) | ||
login_as(test_user) | ||
end | ||
|
||
describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do | ||
it 'returns the list of a power of attorney request' do | ||
it 'returns the list of power of attorney requests' do | ||
poa_requests | ||
|
||
get('/accredited_representative_portal/v0/power_of_attorney_requests') | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(JSON.parse(response.body)).to eq(poa_request_list_mock_data) | ||
parsed_response = JSON.parse(response.body) | ||
|
||
expected_response = AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer | ||
.new(poa_requests) | ||
.serializable_hash | ||
|
||
expect(deep_stringify(parsed_response)).to eq(deep_stringify(expected_response)) | ||
end | ||
end | ||
|
||
describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests/:id' do | ||
it 'returns the details of a power of attorney request' do | ||
get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request_details_id}") | ||
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) | ||
expect(JSON.parse(response.body)).to include(poa_request_details_mock_data) | ||
parsed_response = JSON.parse(response.body) | ||
|
||
expected_response = AccreditedRepresentativePortal::PowerOfAttorneyRequestSerializer | ||
.new(poa_request) | ||
.serializable_hash | ||
|
||
expect(deep_stringify(parsed_response)).to eq(deep_stringify(expected_response)) | ||
end | ||
end | ||
|
||
def deep_stringify(value) | ||
case value | ||
when Hash | ||
value.each_with_object({}) do |(k, v), result| | ||
result[k.to_s] = deep_stringify(v) # Stringify keys and recursively process values | ||
end | ||
when Array | ||
value.map { |v| deep_stringify(v) } # Recursively process arrays | ||
when Symbol | ||
value.to_s # Convert symbols to strings | ||
else | ||
value # Leave other primitives (e.g., strings, numbers, nil) as is | ||
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