Skip to content

Commit

Permalink
Travel Pay/Create new claim client and service (#18678)
Browse files Browse the repository at this point in the history
* create new claim client and service + tests

* add params comment, remove unneeded comment

* provide default for required claim name

* fix tests
  • Loading branch information
liztownd authored Oct 4, 2024
1 parent 86985fb commit bfd5aad
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/travel_pay/app/services/travel_pay/claims_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,35 @@ def get_claims(veis_token, btsss_token)
req.headers.merge!(claim_headers)
end
end

##
# HTTP POST call to the BTSSS 'claims' endpoint
# API responds with a new travel pay claim ID
#
# @params {
# "appointmentId": "string", (BTSSS internal appointment ID - uuid)
# "claimName": "string",
# "claimantType": "Veteran" (currently, "Veteran" is the only claimant type supported)
# }
#
# @return claimID => string
#
def create_claim(veis_token, btsss_token, params = {})
btsss_url = Settings.travel_pay.base_url
correlation_id = SecureRandom.uuid
Rails.logger.debug(message: 'Correlation ID', correlation_id:)

connection(server_url: btsss_url).post('api/v1.1/claims') do |req|
req.headers['Authorization'] = "Bearer #{veis_token}"
req.headers['BTSSS-Access-Token'] = btsss_token
req.headers['X-Correlation-ID'] = correlation_id
req.headers.merge!(claim_headers)
req.body = {
'appointmentId' => params['btsss_appt_id'],
'claimName' => params['claim_name'] || 'Travel reimbursement',
'claimantType' => params['claimant_type'] || 'Veteran'
}.to_json
end
end
end
end
19 changes: 19 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 @@ -36,6 +36,25 @@ def get_claim_by_id(veis_token, btsss_token, claim_id)
end
end

def create_new_claim(veis_token, btsss_token, params = {})
# ensure appt ID is the right format, allowing any version
uuid_all_version_format = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[89ABCD][0-9A-F]{3}-[0-9A-F]{12}$/i

unless params['btsss_appt_id']
raise ArgumentError,
message: 'You must provide a BTSSS appointment ID to create a claim.'
end

unless uuid_all_version_format.match?(params['btsss_appt_id'])
raise ArgumentError,
message: "Expected BTSSS appointment id to be a valid UUID, got #{params['btsss_appt_id']}."
end

new_claim_response = client.create_claim(veis_token, btsss_token, params)

new_claim_response.body
end

private

def filter_by_date(date_string, claims)
Expand Down
26 changes: 26 additions & 0 deletions modules/travel_pay/spec/services/claims_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
.and_return('veis_token', 'btsss_token')
end

# GET
it 'returns response from claims endpoint' do
@stubs.get('/api/v1/claims') do
[
Expand Down Expand Up @@ -89,5 +90,30 @@

expect(actual_claim_ids).to eq(expected_ids)
end

# POST create_claim
it 'returns a claim ID from the claims endpoint' do
claim_id = '3fa85f64-5717-4562-b3fc-2c963f66afa6'
body = { 'appointmentId' => 'fake_btsss_appt_id', 'claimName' => 'SMOC claim',
'claimantType' => 'Veteran' }.to_json
@stubs.post('/api/v1.1/claims') do
[
200,
{},
{
'data' =>
{
'claimId' => claim_id
}
}
]
end

client = TravelPay::ClaimsClient.new
new_claim_response = client.create_claim('veis_token', 'btsss_token', body)
actual_claim_id = new_claim_response.body['data']['claimId']

expect(actual_claim_id).to eq(claim_id)
end
end
end
45 changes: 45 additions & 0 deletions modules/travel_pay/spec/services/claims_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,49 @@
end
end
end

context 'create_new_claim' do
let(:user) { build(:user) }
let(:new_claim_data) do
{
'data' =>
{
'claimId' => '3fa85f64-5717-4562-b3fc-2c963f66afa6'
}
}
end
let(:new_claim_response) do
Faraday::Response.new(
body: new_claim_data
)
end

let(:tokens) { %w[veis_token btsss_token] }

it 'returns a claim ID when passed a valid btsss appt id' do
btsss_appt_id = '73611905-71bf-46ed-b1ec-e790593b8565'
allow_any_instance_of(TravelPay::ClaimsClient)
.to receive(:create_claim)
.with(*tokens, { 'btsss_appt_id' => btsss_appt_id, 'claim_name' => 'SMOC claim' })
.and_return(new_claim_response)

service = TravelPay::ClaimsService.new
actual_claim_response = service.create_new_claim(*tokens,
{ 'btsss_appt_id' => btsss_appt_id,
'claim_name' => 'SMOC claim' })

expect(actual_claim_response['data']).to equal(new_claim_data['data'])
end

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

expect { service.create_new_claim(*tokens, { 'btsss_appt_id' => btsss_appt_id }) }
.to raise_error(ArgumentError, /valid UUID/i)

expect { service.create_new_claim(*tokens, { 'btsss_appt_id' => nil }) }
.to raise_error(ArgumentError, /must provide/i)
end
end
end

0 comments on commit bfd5aad

Please sign in to comment.