2017-06-05 12:09:29 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Api::V1::StreamingController 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
|
|
|
|
|
2023-11-07 10:10:36 +01:00
|
|
|
before do
|
2017-06-05 12:09:29 +02:00
|
|
|
request.headers.merge! Host: Rails.configuration.x.web_domain
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with streaming api on same host' do
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'raises ActiveRecord::RecordNotFound' do
|
|
|
|
get :index
|
|
|
|
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
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'redirects to streaming host' do
|
2018-10-04 12:36:53 +02:00
|
|
|
get :index, params: { access_token: 'deadbeef', stream: 'public' }
|
2017-06-05 12:09:29 +02:00
|
|
|
expect(response).to have_http_status(301)
|
|
|
|
request_uri = URI.parse(request.url)
|
|
|
|
redirect_to_uri = URI.parse(response.location)
|
|
|
|
[:scheme, :path, :query, :fragment].each do |part|
|
|
|
|
expect(redirect_to_uri.send(part)).to eq(request_uri.send(part)), "redirect target #{part}"
|
|
|
|
end
|
2023-11-08 16:42:30 +01:00
|
|
|
expect(redirect_to_uri.host).to eq(streaming_host), 'redirect target host'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|