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