diff --git a/modules/check_in/app/services/travel_claim/response.rb b/modules/check_in/app/services/travel_claim/response.rb index 1a692322aae..1a13a434ead 100644 --- a/modules/check_in/app/services/travel_claim/response.rb +++ b/modules/check_in/app/services/travel_claim/response.rb @@ -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 @@ -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 @@ -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: } diff --git a/modules/check_in/spec/services/travel_claim/response_spec.rb b/modules/check_in/spec/services/travel_claim/response_spec.rb index c7c0eac4269..4a6f28a0295 100644 --- a/modules/check_in/spec/services/travel_claim/response_spec.rb +++ b/modules/check_in/spec/services/travel_claim/response_spec.rb @@ -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 diff --git a/modules/check_in/spec/services/travel_claim/service_spec.rb b/modules/check_in/spec/services/travel_claim/service_spec.rb index 2d749dc1331..048c25e95f1 100644 --- a/modules/check_in/spec/services/travel_claim/service_spec.rb +++ b/modules/check_in/spec/services/travel_claim/service_spec.rb @@ -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(