Restano avviabili solo le gare in ritardo senza punteggio, non quelle già terminate dal portale. Co-authored-by: Cursor <cursoragent@cursor.com>
197 lines
6.1 KiB
Ruby
197 lines
6.1 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 con risultato inserito dal portale anche senza diretta" do
|
|
match = team.matches.create!(
|
|
opponent_name: "Squadra 4",
|
|
scheduled_at: 2.hours.ago,
|
|
sets_to_win: 3,
|
|
home_score: 11,
|
|
away_score: 10,
|
|
result_status: "played"
|
|
)
|
|
|
|
expect(match.coach_hub_visible?).to be(false)
|
|
end
|
|
|
|
it "nasconde walkover anche se il torneo è ancora aperto" do
|
|
broadcast = club.teams.create!(
|
|
name: "Torneo Walkover",
|
|
sport_key: "pallavolo",
|
|
internal_kind: Tournament::INTERNAL_TEAM_KIND
|
|
)
|
|
tournament = Tournament.create!(
|
|
club: club,
|
|
name: "Torneo Walkover",
|
|
sport_key: "pallavolo",
|
|
starts_on: Date.current,
|
|
ends_on: Date.current,
|
|
format_kind: "free",
|
|
status: "published",
|
|
broadcast_team: broadcast
|
|
)
|
|
match = broadcast.matches.create!(
|
|
opponent_name: "TBD",
|
|
scheduled_at: 1.hour.ago,
|
|
sets_to_win: 3,
|
|
tournament: tournament,
|
|
result_status: "walkover_home",
|
|
home_score: 1,
|
|
away_score: 0
|
|
)
|
|
|
|
expect(match.coach_hub_visible?).to be(false)
|
|
end
|
|
|
|
it "mostra partita di oggi già passata d'orario se non è stata trasmessa" do
|
|
match = team.matches.create!(
|
|
opponent_name: "Late",
|
|
scheduled_at: 2.hours.ago,
|
|
sets_to_win: 3
|
|
)
|
|
|
|
expect(match.coach_hub_visible?).to be(true)
|
|
end
|
|
|
|
it "nasconde partita di un giorno precedente mai trasmessa" do
|
|
match = team.matches.create!(
|
|
opponent_name: "Yesterday",
|
|
scheduled_at: 1.day.ago.change(hour: 10),
|
|
sets_to_win: 3
|
|
)
|
|
|
|
expect(match.coach_hub_visible?).to be(false)
|
|
end
|
|
|
|
it "mostra gara di torneo in corso anche se l'orario era ieri" do
|
|
broadcast = club.teams.create!(
|
|
name: "Torneo Late",
|
|
sport_key: "pallavolo",
|
|
internal_kind: Tournament::INTERNAL_TEAM_KIND
|
|
)
|
|
tournament = Tournament.create!(
|
|
club: club,
|
|
name: "Torneo Late",
|
|
sport_key: "pallavolo",
|
|
starts_on: Date.yesterday,
|
|
ends_on: Date.current,
|
|
format_kind: "free",
|
|
status: "published",
|
|
broadcast_team: broadcast
|
|
)
|
|
match = broadcast.matches.create!(
|
|
opponent_name: "TBD",
|
|
scheduled_at: 1.day.ago.change(hour: 10),
|
|
sets_to_win: 3,
|
|
tournament: tournament
|
|
)
|
|
|
|
expect(match.coach_hub_visible?).to be(true)
|
|
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
|