Convert more API specs from controller->request style (#29004)
This commit is contained in:
parent
a25014de8f
commit
18945f62e0
10 changed files with 159 additions and 156 deletions
62
spec/requests/api/v1/streaming_spec.rb
Normal file
62
spec/requests/api/v1/streaming_spec.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Streaming' do
|
||||
around do |example|
|
||||
before = Rails.configuration.x.streaming_api_base_url
|
||||
Rails.configuration.x.streaming_api_base_url = "wss://#{Rails.configuration.x.web_domain}"
|
||||
example.run
|
||||
Rails.configuration.x.streaming_api_base_url = before
|
||||
end
|
||||
|
||||
let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
|
||||
|
||||
context 'with streaming api on same host' do
|
||||
describe 'GET /api/v1/streaming' do
|
||||
it 'raises ActiveRecord::RecordNotFound' do
|
||||
get '/api/v1/streaming', headers: headers
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with streaming api on different host' do
|
||||
before do
|
||||
Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/streaming' do
|
||||
it 'redirects to streaming host' do
|
||||
get '/api/v1/streaming', headers: headers, params: { access_token: 'deadbeef', stream: 'public' }
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(301)
|
||||
|
||||
expect(redirect_to_uri)
|
||||
.to have_attributes(
|
||||
fragment: request_uri.fragment,
|
||||
host: eq(streaming_host),
|
||||
path: request_uri.path,
|
||||
query: request_uri.query,
|
||||
scheme: request_uri.scheme
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_uri
|
||||
URI.parse(request.url)
|
||||
end
|
||||
|
||||
def redirect_to_uri
|
||||
URI.parse(response.location)
|
||||
end
|
||||
|
||||
def streaming_host
|
||||
URI.parse(Rails.configuration.x.streaming_api_base_url).host
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue