Files
MatchLiveTv/backend/spec/services/recordings/delete_spec.rb
T
eminuxandCursor 1e4e0560f1 Allinea le spec alla policy password e prepara i piani di test.
Senza questo la suite locale fallisce sulla complessità password e sui piani mancanti.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-18 23:20:31 +02:00

73 lines
2.5 KiB
Ruby

require "rails_helper"
RSpec.describe Recordings::Delete do
let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") }
let!(:user) { User.create!(email: "coach@test.com", name: "Coach", password: "Password123", role: "coach") }
let!(:match) { team.matches.create!(opponent_name: "Rival", scheduled_at: 1.day.from_now) }
let!(:session) do
StreamSession.create!(match: match, user: user, platform: "youtube", status: "ended")
end
let!(:recording) do
Recording.create!(
stream_session: session,
team: team,
status: "ready",
privacy_status: "public",
expires_at: 10.days.from_now,
storage_key: "teams/#{team.id}/sessions/#{session.id}/replay.mp4",
youtube_video_id: "abc123xyz",
youtube_published_at: Time.current
)
end
def stub_delete_deps
storage = instance_double(Recordings::Storage, delete: true)
allow(Recordings::Storage).to receive(:new).and_return(storage)
yt = instance_double(Youtube::VideoLifecycleService, delete!: true)
allow(Youtube::VideoLifecycleService).to receive(:new).with(recording).and_return(yt)
[storage, yt]
end
it "elimina storage e YouTube (scope both)" do
storage, yt = stub_delete_deps
described_class.new(recording).call
expect(yt).to have_received(:delete!)
expect(storage).to have_received(:delete).at_least(:once)
recording.reload
expect(recording.deleted_at).to be_present
expect(recording.youtube_video_id).to be_nil
expect(recording.storage_key).to be_nil
end
it "elimina solo dal sito lasciando YouTube" do
storage, yt = stub_delete_deps
described_class.new(recording, scope: :site).call
expect(yt).not_to have_received(:delete!)
expect(storage).to have_received(:delete).at_least(:once)
recording.reload
expect(recording.deleted_at).to be_present
expect(recording.storage_key).to be_nil
expect(recording.youtube_video_id).to eq("abc123xyz")
end
it "elimina solo da YouTube lasciando il replay sul sito" do
storage, yt = stub_delete_deps
described_class.new(recording, scope: :youtube).call
expect(yt).to have_received(:delete!)
expect(storage).not_to have_received(:delete)
recording.reload
expect(recording.deleted_at).to be_nil
expect(recording.status).to eq("ready")
expect(recording.storage_key).to be_present
expect(recording.youtube_video_id).to be_nil
expect(recording.youtube_published_at).to be_nil
end
end