require "rails_helper" RSpec.describe Mediamtx::Client do let!(:user) { User.create!(email: "mtx@test.it", name: "U", password: "Password123", role: "coach") } let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") } let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") } let!(:match) { team.matches.create!(opponent_name: "Opp", sport: "volleyball") } let!(:node) do StreamNode.create!( slug: "stream-home", hostname: "home", role: "home", status: "ready", provider: "local", rtmp_base_url: "rtmp://localhost:1935", hls_base_url: "http://localhost:8888", api_base_url: "http://mediamtx:9997", max_publishers: 6, max_relays: 6 ) end let!(:session) do StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "idle", stream_node: node) end before do load Rails.root.join("db/seeds/plans.rb") Billing::AssignPlan.call(club: club, plan_slug: "premium_full") end it "usa SlateDistributor per alwaysAvailableFile" do custom = "/slates/custom/club-test.mp4" allow(Streams::SlateDistributor).to receive(:slate_path_for_session).with(session).and_return(custom) conn = instance_double(Faraday::Connection) response = instance_double(Faraday::Response, success?: true, status: 200, body: {}) allow(Faraday).to receive(:new).and_return(conn) allow(conn).to receive(:post).and_return(response) allow(conn).to receive(:get) allow(Redis).to receive(:new).and_return(instance_double(Redis, get: nil, set: true)) client = described_class.new(base_url: "http://mediamtx:9997") client.create_path(session) expect(conn).to have_received(:post).with( "/v3/config/paths/add/live%2Fmatch_#{session.id}", hash_including(alwaysAvailableFile: custom) ) end end