Files
MatchLiveTv/backend/spec/models/match_scheduling_spec.rb
Emiliano Frascaro 34c97f4447 Fix sport squadra su partite basket e ruoli organico per board.
Le partite ereditano lo sport_key della squadra alla creazione invece del default pallavolo; l'organico mostra ruoli per board (basket, volley, timed) e il wizard Android usa lo sport del team per overlay e icona.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 22:32:36 +02:00

119 lines
3.9 KiB
Ruby

require "rails_helper"
RSpec.describe Match, "scheduling scopes" do
let!(:club) do
Club.create!(name: "Sched Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff")
end
let!(:team) { club.teams.create!(name: "U16", sport: "volleyball") }
let!(:user) { User.create!(email: "coach@test.com", name: "Coach", password: "password123", role: "coach") }
it "scheduled_for_live esclude partite già passate oggi" do
past = team.matches.create!(opponent_name: "Past", scheduled_at: 2.hours.ago, sets_to_win: 3)
future = team.matches.create!(opponent_name: "Future", scheduled_at: 2.hours.from_now, sets_to_win: 3)
expect(described_class.scheduled_for_live).to include(future)
expect(described_class.scheduled_for_live).not_to include(past)
end
describe "#coach_hub_visible?" do
it "mostra diretta attiva da riprendere" do
match = team.matches.create!(opponent_name: "Live", sets_to_win: 3)
StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "paused")
expect(match.coach_hub_visible?).to be(true)
end
it "mostra wizard in corso (sessione idle)" do
match = team.matches.create!(opponent_name: "Setup", sets_to_win: 3)
StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "idle")
expect(match.coach_hub_visible?).to be(true)
end
it "mostra partita programmata futura mai trasmessa" do
match = team.matches.create!(
opponent_name: "Future",
scheduled_at: 2.hours.from_now,
sets_to_win: 3
)
expect(match.coach_hub_visible?).to be(true)
end
it "nasconde bozza abbandonata senza sessione" do
match = team.matches.create!(opponent_name: "Avversario", sets_to_win: 3)
expect(match.coach_hub_visible?).to be(false)
end
it "nasconde partita già trasmessa e terminata" do
match = team.matches.create!(opponent_name: "Done", sets_to_win: 3)
StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "ended")
expect(match.coach_hub_visible?).to be(false)
end
it "eredita lo sport della squadra alla creazione (non il default pallavolo)" do
basket_team = club.teams.create!(name: "U13 Basket", sport_key: "basket")
match = basket_team.matches.create!(opponent_name: "Ospiti", sets_to_win: 3)
expect(match.sport_key).to eq("basket")
expect(match.effective_board_type).to eq("basket")
expect(match.effective_overlay_kind).to eq("basket")
end
it "nasconde partita con diretta terminata anche se resta una sessione idle vecchia" do
match = team.matches.create!(opponent_name: "Avversario", sets_to_win: 3)
StreamSession.create!(
match: match,
user: user,
platform: "matchlivetv",
status: "idle",
created_at: 3.days.ago
)
StreamSession.create!(
match: match,
user: user,
platform: "matchlivetv",
status: "ended",
created_at: 1.hour.ago
)
expect(match.active_stream_session).to be_nil
expect(match.coach_hub_visible?).to be(false)
end
it "nasconde partita programmata nel passato mai trasmessa" do
match = team.matches.create!(
opponent_name: "Missed",
scheduled_at: 2.hours.ago,
sets_to_win: 3
)
expect(match.coach_hub_visible?).to be(false)
end
end
describe "scoring_rules" do
it "accetta regole personalizzate valide" do
match = team.matches.new(
opponent_name: "Opp",
sets_to_win: 2,
scoring_rules: { points_per_set: 21, points_deciding_set: 15, min_point_lead: 2 }
)
expect(match).to be_valid
end
it "rifiuta punteggi non positivi" do
match = team.matches.new(
opponent_name: "Opp",
scoring_rules: { points_per_set: 0 }
)
expect(match).not_to be_valid
expect(match.errors[:scoring_rules]).to be_present
end
end
end