Skip to content

Commit

Permalink
Add travel_pay/v0/claims route (same as travel_pay/claims) (#18319)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinzed1127 authored Sep 5, 2024
1 parent 4d2ca74 commit 996918a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 42 deletions.
30 changes: 0 additions & 30 deletions modules/travel_pay/app/controllers/travel_pay/claims_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module TravelPay
module V0
class ClaimsController < ApplicationController
def index
begin
claims = service.get_claims(@current_user)
rescue Faraday::Error => e
TravelPay::ServiceError.raise_mapped_error(e)
end

render json: claims, status: :ok
end

private

def service
@service ||= TravelPay::Service.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
8 changes: 7 additions & 1 deletion modules/travel_pay/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# frozen_string_literal: true

TravelPay::Engine.routes.draw do
resources :claims
# TODO: remove this mapping once vets-website
# is pointing to the /v0/claims routes
resources :claims, controller: '/travel_pay/v0/claims'

namespace :v0 do
resources :claims
end
end
46 changes: 35 additions & 11 deletions modules/travel_pay/spec/requests/travel_pay/claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe 'TravelPay::Claims', type: :request do
RSpec.describe TravelPay::V0::ClaimsController, type: :request do
let(:user) { build(:user) }

before do
Expand All @@ -19,21 +19,45 @@
]
end

it 'responds with 200' do
VCR.use_cassette('travel_pay/200_claims', match_requests_on: %i[method path]) do
get '/travel_pay/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:ok)
claim_ids = JSON.parse(response.body)['data'].pluck('id')
expect(claim_ids).to eq(expected_claim_ids)
context '(Older) unversioned API route' do
it 'responds with 200' do
VCR.use_cassette('travel_pay/200_claims', match_requests_on: %i[method path]) do
get '/travel_pay/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:ok)
claim_ids = JSON.parse(response.body)['data'].pluck('id')
expect(claim_ids).to eq(expected_claim_ids)
end
end
end

context 'Versioned v0 API route' do
it 'responds with 200' do
VCR.use_cassette('travel_pay/200_claims', match_requests_on: %i[method path]) do
get '/travel_pay/v0/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:ok)
claim_ids = JSON.parse(response.body)['data'].pluck('id')
expect(claim_ids).to eq(expected_claim_ids)
end
end
end
end

context 'unsuccessful response from API' do
it 'responds with a 404 if the API endpoint is not found' do
VCR.use_cassette('travel_pay/404_claims', match_requests_on: %i[method path]) do
get '/travel_pay/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:bad_request)
context '(Older) unversioned API route' do
it 'responds with a 404 if the API endpoint is not found' do
VCR.use_cassette('travel_pay/404_claims', match_requests_on: %i[method path]) do
get '/travel_pay/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:bad_request)
end
end
end

context 'Versioned v0 API route' do
it 'responds with a 404 if the API endpoint is not found' do
VCR.use_cassette('travel_pay/404_claims', match_requests_on: %i[method path]) do
get '/travel_pay/v0/claims', params: nil, headers: { 'Authorization' => 'Bearer vagov_token' }
expect(response).to have_http_status(:bad_request)
end
end
end
end
Expand Down

0 comments on commit 996918a

Please sign in to comment.