2017-06-05 03:09:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-01 08:24:45 -08:00
|
|
|
describe 'API V1 Streaming' do
|
2023-11-07 01:10:36 -08:00
|
|
|
around do |example|
|
2017-06-05 03:09:29 -07:00
|
|
|
before = Rails.configuration.x.streaming_api_base_url
|
2024-01-10 07:05:46 -08:00
|
|
|
Rails.configuration.x.streaming_api_base_url = "wss://#{Rails.configuration.x.web_domain}"
|
2017-06-05 03:09:29 -07:00
|
|
|
example.run
|
|
|
|
Rails.configuration.x.streaming_api_base_url = before
|
|
|
|
end
|
|
|
|
|
2024-03-01 08:24:45 -08:00
|
|
|
let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
|
2017-06-05 03:09:29 -07:00
|
|
|
|
|
|
|
context 'with streaming api on same host' do
|
2024-03-01 08:24:45 -08:00
|
|
|
describe 'GET /api/v1/streaming' do
|
2017-06-05 03:09:29 -07:00
|
|
|
it 'raises ActiveRecord::RecordNotFound' do
|
2024-03-01 08:24:45 -08:00
|
|
|
get '/api/v1/streaming', headers: headers
|
|
|
|
|
2017-06-05 03:09:29 -07:00
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with streaming api on different host' do
|
2023-11-07 01:10:36 -08:00
|
|
|
before do
|
2023-02-21 16:54:36 -08:00
|
|
|
Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
|
2017-06-05 03:09:29 -07:00
|
|
|
end
|
|
|
|
|
2024-03-01 08:24:45 -08:00
|
|
|
describe 'GET /api/v1/streaming' do
|
2017-06-05 03:09:29 -07:00
|
|
|
it 'redirects to streaming host' do
|
2024-03-01 08:24:45 -08:00
|
|
|
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
|
|
|
|
)
|
2023-11-08 07:42:30 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-03-01 08:24:45 -08:00
|
|
|
def request_uri
|
|
|
|
URI.parse(request.url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_to_uri
|
|
|
|
URI.parse(response.location)
|
|
|
|
end
|
|
|
|
|
2023-11-08 07:42:30 -08:00
|
|
|
def streaming_host
|
|
|
|
URI.parse(Rails.configuration.x.streaming_api_base_url).host
|
2017-06-05 03:09:29 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|