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