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>
51 lines
1.8 KiB
Ruby
51 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Streams::GenerateCoverSlate do
|
|
let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
|
|
|
before do
|
|
load Rails.root.join("db/seeds/plans.rb")
|
|
Billing::AssignPlan.call(club: club, plan_slug: "premium_full")
|
|
club.cover_image.attach(
|
|
io: StringIO.new("fake-image"),
|
|
filename: "cover.png",
|
|
content_type: "image/png"
|
|
)
|
|
end
|
|
|
|
it "genera cover_slate e scrive su disco se ffmpeg ok" do
|
|
mp4 = Tempfile.new(["slate", ".mp4"])
|
|
mp4.write("fake mp4")
|
|
mp4.flush
|
|
|
|
allow(Open3).to receive(:capture3).and_return(["", "", instance_double(Process::Status, success?: true)])
|
|
allow(File).to receive(:exist?).and_call_original
|
|
allow(File).to receive(:exist?).with(mp4.path).and_return(true)
|
|
allow(File).to receive(:size).with(mp4.path).and_return(8)
|
|
|
|
service = described_class.new(club)
|
|
allow(service).to receive(:encode_slate).and_return(mp4.path)
|
|
allow(service).to receive(:download_cover_image).and_return("/tmp/in.png")
|
|
|
|
slates_dir = Rails.root.join("tmp/slates-custom-test")
|
|
FileUtils.mkdir_p(slates_dir)
|
|
allow(Streams::CoverSlatePaths).to receive(:slates_custom_root).and_return(slates_dir.to_s)
|
|
|
|
service.call
|
|
|
|
expect(club.reload.cover_slate).to be_attached
|
|
expect(club.cover_slate.content_type).to eq("video/mp4")
|
|
ensure
|
|
mp4.close!
|
|
FileUtils.rm_rf(slates_dir) if defined?(slates_dir)
|
|
end
|
|
|
|
it "solleva Error se ffmpeg fallisce" do
|
|
allow(Open3).to receive(:capture3).and_return(["", "boom", instance_double(Process::Status, success?: false)])
|
|
|
|
expect {
|
|
described_class.new(club).send(:encode_slate, "/tmp/in.png")
|
|
}.to raise_error(Streams::GenerateCoverSlate::Error, /ffmpeg slate failed/)
|
|
end
|
|
end
|