Add API authenticated ping resource
This commit is contained in:
parent
d12c589e01
commit
78f79c4c34
@ -29,7 +29,11 @@ module API
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ping
|
def ping
|
||||||
render json: { pong: true }
|
ping_response
|
||||||
|
end
|
||||||
|
|
||||||
|
def ping_auth
|
||||||
|
ping_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate!
|
def authenticate!
|
||||||
@ -43,5 +47,12 @@ module API
|
|||||||
head :not_acceptable, content_type: 'application/json'
|
head :not_acceptable, content_type: 'application/json'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ping_response
|
||||||
|
render json: { pong: true }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
get '/ping', to: 'application#ping'
|
get '/ping', to: 'application#ping'
|
||||||
|
get '/ping/auth', to: 'application#ping_auth'
|
||||||
match '*all', to: 'application#cor_preflight', via: :options
|
match '*all', to: 'application#cor_preflight', via: :options
|
||||||
resources :playlists, only: %i[index show create update destroy]
|
resources :playlists, only: %i[index show create update destroy]
|
||||||
resources :sessions, only: :create
|
resources :sessions, only: :create
|
||||||
|
@ -7,6 +7,22 @@ describe 'API application' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'authenticated ping endpoint' do
|
||||||
|
before { get api_ping_auth_path, format: :json }
|
||||||
|
|
||||||
|
it 'requests authentication' do
|
||||||
|
expect(response).to have_http_status 401
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when session is authenticated' do
|
||||||
|
subject { response }
|
||||||
|
|
||||||
|
before { api_sign_in }
|
||||||
|
|
||||||
|
it { is_expected.to have_http_status 200 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'formats handling' do
|
describe 'formats handling' do
|
||||||
before { api_sign_in }
|
before { api_sign_in }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user