Permette upload da portale e app con ereditarietà partita→squadra→società, generazione MP4 via ffmpeg e distribuzione su home lab e nodi CPX per pause e assenza segnale. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
3.0 KiB
Ruby
81 lines
3.0 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Streams::SlateDistributor do
|
|
let!(:user) { User.create!(email: "u@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
|
|
|
|
def attach_ready_cover(record)
|
|
record.cover_image.attach(io: StringIO.new("img"), filename: "c.png", content_type: "image/png")
|
|
record.cover_slate.attach(io: StringIO.new("mp4"), filename: "s.mp4", content_type: "video/mp4")
|
|
path = Streams::CoverSlatePaths.expected_path(record)
|
|
FileUtils.mkdir_p(File.dirname(path))
|
|
File.write(path, "fake mp4")
|
|
path
|
|
end
|
|
|
|
it "usa slate default senza copertina custom" do
|
|
expect(described_class.slate_path_for_session(session)).to eq("/slates/offline.mp4")
|
|
end
|
|
|
|
it "usa path custom su nodo home quando la slate è su disco" do
|
|
attach_ready_cover(club)
|
|
custom = "/slates/custom/#{File.basename(Streams::CoverSlatePaths.expected_path(club))}"
|
|
expect(described_class.slate_path_for_session(session)).to eq(custom)
|
|
end
|
|
|
|
it "pusha sul relay agent per nodi cloud" do
|
|
cloud = StreamNode.create!(
|
|
slug: "ingest-01",
|
|
hostname: "ingest-01",
|
|
role: "cloud",
|
|
status: "ready",
|
|
provider: "hetzner",
|
|
rtmp_base_url: "rtmp://ingest-01.test:1935",
|
|
hls_base_url: "http://localhost:8888",
|
|
api_base_url: "http://203.0.113.9:9997",
|
|
max_publishers: 4,
|
|
max_relays: 4,
|
|
metadata: { "public_ip" => "203.0.113.9" }
|
|
)
|
|
session.update!(stream_node: cloud)
|
|
attach_ready_cover(club)
|
|
|
|
http = instance_double(Net::HTTP)
|
|
response = instance_double(Net::HTTPResponse, body: "{}", code: "201")
|
|
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
allow(Net::HTTP).to receive(:new).and_return(http)
|
|
allow(http).to receive(:open_timeout=)
|
|
allow(http).to receive(:read_timeout=)
|
|
allow(http).to receive(:request).and_return(response)
|
|
|
|
filename = File.basename(Streams::CoverSlatePaths.expected_path(club))
|
|
path = described_class.slate_path_for_session(session)
|
|
expect(path).to eq("/slates/custom/#{filename}")
|
|
expect(http).to have_received(:request)
|
|
end
|
|
end
|