From 322d1e2ed416e3647545c0afd74a35ff5c4f7e4d Mon Sep 17 00:00:00 2001 From: Malaber Date: Sat, 8 Mar 2025 17:39:27 +0100 Subject: [PATCH] Add dummy tournament with group stage --- spec/factories/tournaments.rb | 9 +++++++ spec/services/group_stage_service_spec.rb | 33 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/spec/factories/tournaments.rb b/spec/factories/tournaments.rb index 9a8a7d3..7b61999 100644 --- a/spec/factories/tournaments.rb +++ b/spec/factories/tournaments.rb @@ -52,6 +52,15 @@ FactoryBot.define do end end + factory :prepared_group_stage_tournament do + transient do + group_stage { create(:group_stage) } + end + after(:create) do |tournament, evaluator| + tournament.stages << evaluator.group_stage + end + end + factory :dummy_stage_tournament do transient do stage_count { 3 } diff --git a/spec/services/group_stage_service_spec.rb b/spec/services/group_stage_service_spec.rb index 8073ef2..61768c9 100644 --- a/spec/services/group_stage_service_spec.rb +++ b/spec/services/group_stage_service_spec.rb @@ -190,4 +190,37 @@ RSpec.describe GroupStageService do end end end + + describe '#get_advancing_teams', focus: true do + context 'when special case for po2 applies' do + before do + # Create some example teams + teams1 = [Team.new(name: 'Team 1'), Team.new(name: 'Team 2'), Team.new(name: 'Team 3'), Team.new(name: 'Team 4')] + teams2 = [Team.new(name: 'Team 5'), Team.new(name: 'Team 6'), Team.new(name: 'Team 7'), Team.new(name: 'Team 8')] + + # Group the teams + groups = [teams1, teams2] + + # Generate the group stage + @group_stage = GroupStageService.generate_group_stage(groups) + + @tournament = create(:prepared_group_stage_tournament, group_stage: @group_stage) + + # iterate over all groups and update the matches within to all be decided + @group_stage.groups.each do |group| + group.matches.each do |match| + match.match_scores.each do |ms| + # give the team the amount of points as in their name + ms.points = ms.team.name.split(' ').last.to_i + ms.save! + end + match.state = 'finished' + match.save! + end + gs = GroupStageService.update_group_scores(group) + gs.each(&:save!) + end + end + end + end end