Skip to content

Commit

Permalink
57042 Include code in TravelClaim Response when successful (#12436)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomsync authored Apr 18, 2023
1 parent c422cbc commit bf56803
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
19 changes: 13 additions & 6 deletions modules/check_in/app/services/travel_claim/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module TravelClaim
class Response
attr_reader :body, :status

CODE_SUCCESS = 'CLM_000_SUCCESS'
CODE_MULTIPLE_APPTS = 'CLM_001_MULTIPLE_APPTS'
CODE_CLAIM_EXISTS = 'CLM_002_CLAIM_EXISTS'
CODE_APPT_NOT_FOUND = 'CLM_003_APPOINTMENT_NOT_FOUND'
CODE_INVALID_AUTH = 'CLM_020_INVALID_AUTH'
CODE_SUBMISSION_ERROR = 'CLM_010_CLAIM_SUBMISSION_ERROR'

def self.build(opts = {})
new(opts)
end
Expand All @@ -22,7 +29,7 @@ def handle

case status
when 200
{ data: response_body, status: }
{ data: response_body.merge(code: CODE_SUCCESS), status: }
when 400, 401, 404
{ data: error_data(message: response_body[:message]), status: }
else
Expand All @@ -39,15 +46,15 @@ def unknown_error_data
def error_data(message:)
error_code = case message
when /multiple appointments/i
'CLM_001_MULTIPLE_APPTS'
CODE_MULTIPLE_APPTS
when /already has a claim/i
'CLM_002_CLAIM_EXISTS'
CODE_CLAIM_EXISTS
when /appointment not found/i
'CLM_003_APPOINTMENT_NOT_FOUND'
CODE_APPT_NOT_FOUND
when /unauthorized/i
'CLM_020_INVALID_AUTH'
CODE_INVALID_AUTH
else
'CLM_010_CLAIM_SUBMISSION_ERROR'
CODE_SUBMISSION_ERROR
end

{ error: true, code: error_code, message: }
Expand Down
12 changes: 1 addition & 11 deletions modules/check_in/spec/services/travel_claim/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@
claims_api_response = { value: { claimNumber: 'TC202207000011666' }, formatters: [], contentTypes: [],
declaredType: [], statusCode: 200 }
resp = Faraday::Response.new(body: claims_api_response, status: 200)
hsh = { data: claims_api_response, status: 200 }

expect(subject.build(response: resp).handle).to eq(hsh)
end
end

context 'when non json string' do
it 'returns a formatted response' do
claims_api_response = 'TC202207000011666'
resp = Faraday::Response.new(body: claims_api_response, status: 200)
hsh = { data: claims_api_response, status: 200 }
hsh = { data: claims_api_response.merge(code: 'CLM_000_SUCCESS'), status: 200 }

expect(subject.build(response: resp).handle).to eq(hsh)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
end
let(:faraday_response) { Faraday::Response.new(body: claims_json, status: 200) }

let(:submit_claim_response) { { data: claims_json, status: 200 } }
let(:submit_claim_response) { { data: claims_json.merge(code: 'CLM_000_SUCCESS'), status: 200 } }

before do
Rails.cache.write(
Expand Down

0 comments on commit bf56803

Please sign in to comment.