streaming_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'API V1 Streaming' do
  4. around do |example|
  5. before = Rails.configuration.x.streaming_api_base_url
  6. Rails.configuration.x.streaming_api_base_url = "wss://#{Rails.configuration.x.web_domain}"
  7. example.run
  8. Rails.configuration.x.streaming_api_base_url = before
  9. end
  10. let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
  11. context 'with streaming api on same host' do
  12. describe 'GET /api/v1/streaming' do
  13. it 'raises ActiveRecord::RecordNotFound' do
  14. get '/api/v1/streaming', headers: headers
  15. expect(response).to have_http_status(404)
  16. end
  17. end
  18. end
  19. context 'with streaming api on different host' do
  20. before do
  21. Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
  22. end
  23. describe 'GET /api/v1/streaming' do
  24. it 'redirects to streaming host' do
  25. get '/api/v1/streaming', headers: headers, params: { access_token: 'deadbeef', stream: 'public' }
  26. expect(response)
  27. .to have_http_status(301)
  28. expect(redirect_to_uri)
  29. .to have_attributes(
  30. fragment: request_uri.fragment,
  31. host: eq(streaming_host),
  32. path: request_uri.path,
  33. query: request_uri.query,
  34. scheme: request_uri.scheme
  35. )
  36. end
  37. private
  38. def request_uri
  39. URI.parse(request.url)
  40. end
  41. def redirect_to_uri
  42. URI.parse(response.location)
  43. end
  44. def streaming_host
  45. URI.parse(Rails.configuration.x.streaming_api_base_url).host
  46. end
  47. end
  48. end
  49. end