Skip to content

Commit

Permalink
Add travel_pay/v0/claims route (same as travel_pay/claims)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinzed1127 committed Sep 5, 2024
1 parent ca7fdf6 commit dc7cecb
Show file tree
Hide file tree
Showing 4 changed files with 75 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
9 changes: 8 additions & 1 deletion modules/travel_pay/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
TravelPay::Engine.routes.draw do
get '/pings/ping', to: 'pings#ping'
get '/pings/authorized_ping', to: 'pings#authorized_ping'
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/controllers/claims_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe TravelPay::ClaimsController, 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 dc7cecb

Please sign in to comment.