From bcc93099bf230883dc12bb53d1b21f72181cd60a Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 4 May 2026 17:42:38 +0200 Subject: [PATCH] test: assert playoff recreation matchups --- e2e/lib/scenario_runner.rb | 18 ++++++---- spec/e2e/http/tournament_follow_sync_spec.rb | 37 +++++++++++++------- spec/e2e/http/tournament_lifecycle_spec.rb | 15 ++++++-- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/e2e/lib/scenario_runner.rb b/e2e/lib/scenario_runner.rb index b8e20b0..cee171a 100644 --- a/e2e/lib/scenario_runner.rb +++ b/e2e/lib/scenario_runner.rb @@ -130,7 +130,7 @@ module TurniereE2E created_key = created_keys.fetch(index) checkpoints[created_key] = summarize_tournament(tournament).merge( - playoff_team_names: playoff_team_names(tournament) + playoff_matchups: playoff_matchups(tournament) ) return result(session: session, tournament: tournament, checkpoints: checkpoints, stop_at: stop_at) if stop_at == created_key @@ -711,11 +711,17 @@ module TurniereE2E } end - def playoff_team_names(tournament) - playoff_matches(tournament) - .flat_map { |match| match.fetch(:match_scores).map { |score| score.dig(:team, :name) } } - .uniq - .sort + def playoff_matchups(tournament) + entry_stage = tournament.fetch(:stages) + .reject { |stage| stage.fetch(:level) == -1 } + .max_by { |stage| stage.fetch(:level) } + entry_stage.fetch(:matches) + .sort_by { |match| match.fetch(:position) } + .map do |match| + match.fetch(:match_scores) + .map { |score| score.dig(:team, :name) } + .sort + end end def fetch_tournament_profile!(tournament_id) diff --git a/spec/e2e/http/tournament_follow_sync_spec.rb b/spec/e2e/http/tournament_follow_sync_spec.rb index f54c16c..410bba8 100644 --- a/spec/e2e/http/tournament_follow_sync_spec.rb +++ b/spec/e2e/http/tournament_follow_sync_spec.rb @@ -248,8 +248,8 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do source = fetch_tournament(client: source_anonymous_client, tournament_id: source.fetch(:id)) follower = wait_for_tournament_sync!(source_tournament_id: source.fetch(:id), follower_tournament_id: follower.fetch(:id)) - expect(playoff_team_names(source)).to eq(round.fetch(:expected_playoff_team_names)) - expect(playoff_team_names(follower)).to eq(round.fetch(:expected_playoff_team_names)) + expect(playoff_matchups(source)).to eq(round.fetch(:expected_playoff_matchups)) + expect(playoff_matchups(follower)).to eq(round.fetch(:expected_playoff_matchups)) expect(tournament_signature(follower)).to eq(tournament_signature(source)) next if index == rounds.size - 1 @@ -534,7 +534,10 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do 'G2-S1' => 3, 'G2-S2' => 1 }, - expected_playoff_team_names: %w[G1-S1 G2-S1] + expected_playoff_matchups: [ + %w[G1-S1 G2-S2], + %w[G1-S2 G2-S1] + ] }, { scores_by_team_name: { @@ -543,7 +546,10 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do 'G2-S1' => 0, 'G2-S2' => 4 }, - expected_playoff_team_names: %w[G1-S2 G2-S2] + expected_playoff_matchups: [ + %w[G1-S2 G2-S1], + %w[G1-S1 G2-S2] + ] }, { scores_by_team_name: { @@ -552,7 +558,10 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do 'G2-S1' => 2, 'G2-S2' => 5 }, - expected_playoff_team_names: %w[G1-S1 G2-S2] + expected_playoff_matchups: [ + %w[G1-S1 G2-S1], + %w[G1-S2 G2-S2] + ] } ] end @@ -590,13 +599,17 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do end end - def playoff_team_names(tournament) - tournament.fetch(:stages) - .select { |stage| stage.fetch(:level) >= 0 } - .flat_map { |stage| stage.fetch(:matches) } - .flat_map { |match| match.fetch(:match_scores).map { |score| seed_label(score.dig(:team, :name)) } } - .uniq - .sort + def playoff_matchups(tournament) + entry_stage = tournament.fetch(:stages) + .select { |stage| stage.fetch(:level) >= 0 } + .max_by { |stage| stage.fetch(:level) } + entry_stage.fetch(:matches) + .sort_by { |match| match.fetch(:position) } + .map do |match| + match.fetch(:match_scores) + .map { |score| seed_label(score.dig(:team, :name)) } + .sort + end end def seed_label(team_name) diff --git a/spec/e2e/http/tournament_lifecycle_spec.rb b/spec/e2e/http/tournament_lifecycle_spec.rb index 22c3970..ea5ff0a 100644 --- a/spec/e2e/http/tournament_lifecycle_spec.rb +++ b/spec/e2e/http/tournament_lifecycle_spec.rb @@ -65,12 +65,21 @@ RSpec.describe 'Tournament lifecycle HTTP E2E' do result = runner.run_group_stage_playoff_recreation checkpoints = result.fetch(:checkpoints) - expect(checkpoints.fetch(:first_playoffs_created).fetch(:playoff_team_names)).to eq(%w[G1-S1 G2-S1]) + expect(checkpoints.fetch(:first_playoffs_created).fetch(:playoff_matchups)).to eq([ + %w[G1-S1 G2-S2], + %w[G1-S2 G2-S1] + ]) expect(checkpoints.fetch(:first_playoffs_deleted).fetch(:stage_summaries).map { |stage| stage.fetch(:level) }).to eq([-1]) expect(checkpoints.fetch(:first_playoffs_deleted).fetch(:stage_summaries).first.fetch(:state)).to eq('in_progress') - expect(checkpoints.fetch(:second_playoffs_created).fetch(:playoff_team_names)).to eq(%w[G1-S2 G2-S2]) + expect(checkpoints.fetch(:second_playoffs_created).fetch(:playoff_matchups)).to eq([ + %w[G1-S2 G2-S1], + %w[G1-S1 G2-S2] + ]) expect(checkpoints.fetch(:second_playoffs_deleted).fetch(:stage_summaries).map { |stage| stage.fetch(:level) }).to eq([-1]) - expect(checkpoints.fetch(:third_playoffs_created).fetch(:playoff_team_names)).to eq(%w[G1-S1 G2-S2]) + expect(checkpoints.fetch(:third_playoffs_created).fetch(:playoff_matchups)).to eq([ + %w[G1-S1 G2-S1], + %w[G1-S2 G2-S2] + ]) end {