Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Claim By ID Endpoint #18404

Merged
merged 16 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/swagger/swagger/requests/travel_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class TravelPay

parameter :authorization

parameter do
key :in, :path
key :name, :id
key :pattern, ''
key :description, 'The non-PII/PHI id of a claim'
key :required, false
end

response 200 do
key :description, 'Successfully retrieved claims for a user'
schema do
Expand All @@ -24,6 +32,34 @@ class TravelPay
end
end
end

swagger_path '/travel_pay/claims/{id}' do
operation :get do
extend Swagger::Responses::AuthenticationError
extend Swagger::Responses::BadRequestError

key :description, 'Get a single travel reimbursment claim summary'
key :operationId, 'getTravelPayClaimById'
key :tags, %w[travel_pay]

parameter :authorization

parameter do
key :in, :path
key :name, :id
key :pattern, '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[4][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$'
key :description, 'The non-PII/PHI id of a claim'
key :required, false
end

response 200 do
key :description, 'Successfully retrieved claim for a user'
schema do
key :$ref, :TravelPayClaimSummary
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ def index
render json: claims, status: :ok
end

def show
begin
claim = service.get_claim_by_id(@current_user, params[:id])
rescue Faraday::Error => e
TravelPay::ServiceError.raise_mapped_error(e)
end

if claim.nil?
raise Common::Exceptions::ResourceNotFound, message: "Claim not found. ID provided: #{params[:id]}"
end

render json: claim, status: :ok
end

private

def service
@service ||= TravelPay::ClaimsService.new
end

def common_exception(e)
case e
when Faraday::ResourceNotFound
Common::Exceptions::ResourceNotFound.new
else
Common::Exceptions::InternalServerError.new
end
end
end
end
end
15 changes: 15 additions & 0 deletions modules/travel_pay/app/services/travel_pay/claims_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ def get_claims(current_user)
}
end

def get_claim_by_id(current_user, claim_id)
kjduensing marked this conversation as resolved.
Show resolved Hide resolved
# ensure claim ID is the right format
uuid_v4_format = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i

unless uuid_v4_format.match?(claim_id)
raise ArgumentError, message: "Expected claim id to be a valid v4 UUID, got #{claim_id}."
end

claims_response = client.get_claims(current_user)

claims = claims_response.body['data']

claims.find { |c| c['id'] == claim_id }
end

private

def client
Expand Down
28 changes: 28 additions & 0 deletions modules/travel_pay/spec/requests/travel_pay/claims_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'securerandom'

RSpec.describe TravelPay::V0::ClaimsController, type: :request do
let(:user) { build(:user) }
Expand Down Expand Up @@ -62,4 +63,31 @@
end
end
end

describe '#show' do
it 'returns a single claim on success' do
VCR.use_cassette('travel_pay/show/success', match_requests_on: %i[method path]) do
# This claim ID matches a claim ID in the cassette.
claim_id = '33016896-ed7f-4d4f-a81b-cc4f2ca0832c'
expected_claim_num = 'TC092809828275'

get "/travel_pay/v0/claims/#{claim_id}", headers: { 'Authorization' => 'Bearer vagov_token' }
actual_claim_num = JSON.parse(response.body)['claimNumber']

expect(response).to have_http_status(:ok)
expect(actual_claim_num).to eq(expected_claim_num)
end
end

it 'returns a Not Found response if claim number valid but claim not found' do
VCR.use_cassette('travel_pay/show/success', match_requests_on: %i[method path]) do
# This claim ID matches a claim ID in the cassette.
claim_id = SecureRandom.uuid

get "/travel_pay/v0/claims/#{claim_id}", headers: { 'Authorization' => 'Bearer vagov_token' }

expect(response).to have_http_status(:not_found)
end
end
end
end
32 changes: 30 additions & 2 deletions modules/travel_pay/spec/services/claims_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'securerandom'

describe TravelPay::ClaimsService do
context 'get_claims' do
Expand Down Expand Up @@ -36,8 +37,8 @@
'modifiedOn' => '2024-02-01T00:00:00.0Z'
},
{
'id' => 'uuid4',
'claimNumber' => '73611905-71bf-46ed-b1ec-e790593b8565',
'id' => '73611905-71bf-46ed-b1ec-e790593b8565',
'claimNumber' => 'TC0004',
'claimName' => '9d81c1a1-cd05-47c6-be97-d14dec579893',
'claimStatus' => 'Claim Submitted',
'appointmentDateTime' => nil,
Expand Down Expand Up @@ -70,5 +71,32 @@

expect(actual_statuses).to match_array(expected_statuses)
end

context 'get claim by id' do
it 'returns a single claim when passed a valid id' do
claim_id = '73611905-71bf-46ed-b1ec-e790593b8565'
expected_claim = claims_data['data'].find { |c| c['id'] == claim_id }
service = TravelPay::Service.new
actual_claim = service.get_claim_by_id(user, claim_id)

expect(actual_claim).to eq(expected_claim)
end

it 'returns nil if a claim with the given id was not found' do
claim_id = SecureRandom.uuid
service = TravelPay::Service.new
actual_claim = service.get_claim_by_id(user, claim_id)

expect(actual_claim).to eq(nil)
end

it 'throws an ArgumentException if claim_id is invalid format' do
claim_id = 'this-is-definitely-a-uuid-right'
service = TravelPay::Service.new

expect { service.get_claim_by_id(user, claim_id) }
.to raise_error(ArgumentError, /valid v4 UUID/i)
end
end
end
end
Loading
Loading