1
0

streaming_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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. context 'with streaming api on same host' do
  11. describe 'GET /api/v1/streaming' do
  12. it 'raises ActiveRecord::RecordNotFound' do
  13. integration_session.https!(false)
  14. get '/api/v1/streaming'
  15. expect(response).to have_http_status(404)
  16. expect(response.content_type)
  17. .to start_with('application/json')
  18. end
  19. end
  20. end
  21. context 'with streaming api on different host' do
  22. before do
  23. Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
  24. end
  25. describe 'GET /api/v1/streaming' do
  26. it 'redirects to streaming host' do
  27. get '/api/v1/streaming', headers: headers, params: { access_token: 'deadbeef', stream: 'public' }
  28. expect(response)
  29. .to have_http_status(301)
  30. expect(redirect_to_uri)
  31. .to have_attributes(
  32. fragment: request_uri.fragment,
  33. host: eq(streaming_host),
  34. path: request_uri.path,
  35. query: request_uri.query,
  36. scheme: request_uri.scheme
  37. )
  38. end
  39. private
  40. def request_uri
  41. URI.parse(request.url)
  42. end
  43. def redirect_to_uri
  44. URI.parse(response.location)
  45. end
  46. def streaming_host
  47. URI.parse(Rails.configuration.x.streaming_api_base_url).host
  48. end
  49. end
  50. end
  51. end