# frozen_string_literal: true require "rails_helper" RSpec.describe "HLS proxy", type: :request do let(:mediamtx_hls) { "http://mediamtx.test:8888" } let(:playlist) do <<~M3U8 #EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:1 #EXTINF:1.0, /live/match_#{session_id}/segment0.ts M3U8 end let(:session_id) { "cc7e90b2-c672-4401-b5d3-51fdcdc7a214" } before do allow(MatchLiveTv).to receive(:mediamtx_hls_url).and_return(mediamtx_hls) end describe "GET /live/match_:session_id/*" do it "proxies MediaMTX redirect and rewrites playlist paths to /hls/" do stub_request(:get, "#{mediamtx_hls}/live/match_#{session_id}/index.m3u8") .to_return(status: 302, headers: { "Location" => "/live/match_#{session_id}/index.m3u8?cookieCheck=1" }) stub_request(:get, "#{mediamtx_hls}/live/match_#{session_id}/index.m3u8?cookieCheck=1") .to_return(status: 200, body: playlist, headers: { "Content-Type" => "application/vnd.apple.mpegurl" }) get "/live/match_#{session_id}/index.m3u8" expect(response).to have_http_status(:ok) expect(response.body).to include("/hls/live/match_#{session_id}/segment0.ts") expect(response.body).not_to include("/live/match_#{session_id}/segment0.ts") end end end