test: cover manual team action list flows

This commit is contained in:
Daniel Schädler 2026-04-23 22:48:00 +02:00
parent b40e64cde8
commit d69e08a25b
4 changed files with 94 additions and 12 deletions

View File

@ -141,11 +141,29 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do
expect(tournament_signature(follower)).to eq(tournament_signature(source)) expect(tournament_signature(follower)).to eq(tournament_signature(source))
expect(follower.fetch(:stages).map { |stage| stage.fetch(:level) }).to include(-1, 0, 1) expect(follower.fetch(:stages).map { |stage| stage.fetch(:level) }).to include(-1, 0, 1)
expect(synced_team_id_pairs(source: source, follower: follower)).not_to be_empty expect(synced_team_id_pairs(source: source, follower: follower)).not_to be_empty
expect(source.fetch(:team_action_lists)).to eq([])
expect(follower.fetch(:team_action_lists)).to eq([])
log_phase!('create team action list on source and verify follower mirrors it')
created_list = create_team_action_list!(source.fetch(:id))
expect(created_list.fetch(:key)).to eq(playoff_token_list_key)
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_token_list(source)).not_to be_nil expect(playoff_token_list(source)).not_to be_nil
expect(playoff_token_list(follower)).not_to be_nil expect(playoff_token_list(follower)).not_to be_nil
expect(playoff_token_list(follower).fetch(:team_action_items).map { |item| item.dig(:team, :name) }) expect(playoff_token_list(follower).fetch(:team_action_items).map { |item| item.dig(:team, :name) })
.to match_array(playoff_token_list(source).fetch(:team_action_items).map { |item| item.dig(:team, :name) }) .to match_array(playoff_token_list(source).fetch(:team_action_items).map { |item| item.dig(:team, :name) })
locked_list_create = follower_owner_client.post("/tournaments/#{follower.fetch(:id)}/team_action_lists", body: {
name: 'Follower created list',
key: 'follower_created_list',
action_name: 'Should fail',
source: 'all_tournament_teams'
})
expect(locked_list_create[:status]).to eq(423)
expect(locked_list_create.dig(:json, :error)).to eq('Tournament is in read only follower mode')
follower_group = follower.fetch(:stages).find { |stage| stage.fetch(:level) == -1 }.fetch(:groups).first follower_group = follower.fetch(:stages).find { |stage| stage.fetch(:level) == -1 }.fetch(:groups).first
follower_team = follower_group.fetch(:matches).first.fetch(:match_scores).first.fetch(:team) follower_team = follower_group.fetch(:matches).first.fetch(:match_scores).first.fetch(:team)
locked_team_update = follower_owner_client.patch("/teams/#{follower_team.fetch(:id)}", body: { name: 'Nope' }) locked_team_update = follower_owner_client.patch("/teams/#{follower_team.fetch(:id)}", body: { name: 'Nope' })
@ -155,7 +173,7 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do
log_phase!('mark playoff token collected on source through business key route and verify follower mirrors it') log_phase!('mark playoff token collected on source through business key route and verify follower mirrors it')
source_token_item = playoff_token_list(source).fetch(:team_action_items).first source_token_item = playoff_token_list(source).fetch(:team_action_items).first
source_token_update = source_owner_client.patch( source_token_update = source_owner_client.patch(
"/tournaments/#{source.fetch(:id)}/team_action_lists/group_stage_survivor_playoff_tokens/teams/#{source_token_item.dig(:team, :id)}", "/tournaments/#{source.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/#{source_token_item.dig(:team, :id)}",
body: { completed: true } body: { completed: true }
) )
expect(source_token_update[:status]).to eq(200) expect(source_token_update[:status]).to eq(200)
@ -167,7 +185,7 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do
follower_token_item = find_team_action_item(follower, team_name: source_token_item.dig(:team, :name)) follower_token_item = find_team_action_item(follower, team_name: source_token_item.dig(:team, :name))
locked_token_update = follower_owner_client.patch( locked_token_update = follower_owner_client.patch(
"/tournaments/#{follower.fetch(:id)}/team_action_lists/group_stage_survivor_playoff_tokens/teams/#{follower_token_item.dig(:team, :id)}", "/tournaments/#{follower.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/#{follower_token_item.dig(:team, :id)}",
body: { completed: false } body: { completed: false }
) )
expect(locked_token_update[:status]).to eq(423) expect(locked_token_update[:status]).to eq(423)
@ -265,6 +283,17 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do
response.fetch(:json) response.fetch(:json)
end end
def create_team_action_list!(tournament_id)
response = source_owner_client.post("/tournaments/#{tournament_id}/team_action_lists", body: {
name: 'Playoff token collection',
key: playoff_token_list_key,
action_name: 'Collect playoff token',
source: 'group_stage_survivors'
})
expect(response[:status]).to eq(201)
response.fetch(:json)
end
def seed_unrelated_tournaments!(client:, prefix:, range:) def seed_unrelated_tournaments!(client:, prefix:, range:)
amount = rand(range) amount = rand(range)
Array.new(amount) do |index| Array.new(amount) do |index|
@ -552,10 +581,14 @@ RSpec.describe 'Tournament follower sync HTTP E2E' do
def playoff_token_list(tournament) def playoff_token_list(tournament)
tournament.fetch(:team_action_lists, []).find do |list| tournament.fetch(:team_action_lists, []).find do |list|
list.fetch(:key) == 'group_stage_survivor_playoff_tokens' list.fetch(:key) == playoff_token_list_key
end end
end end
def playoff_token_list_key
'playoff_token_collection'
end
def find_team_action_item(tournament, team_name:) def find_team_action_item(tournament, team_name:)
playoff_token_list(tournament).fetch(:team_action_items).find do |item| playoff_token_list(tournament).fetch(:team_action_items).find do |item|
item.dig(:team, :name) == team_name item.dig(:team, :name) == team_name

View File

@ -37,6 +37,7 @@ RSpec.describe 'Tournament follower sync websocket HTTP E2E' do
expect(configure_sync[:status]).to eq(200) expect(configure_sync[:status]).to eq(200)
finish_group_stage_and_create_playoffs!(source_id: source.fetch(:id)) finish_group_stage_and_create_playoffs!(source_id: source.fetch(:id))
create_team_action_list!(source.fetch(:id))
follower = wait_for_list_presence!(follower.fetch(:id)) follower = wait_for_list_presence!(follower.fetch(:id))
cable_client = TurniereE2E::ActionCableClient.new(base_url: follower_base_url) cable_client = TurniereE2E::ActionCableClient.new(base_url: follower_base_url)
@ -106,6 +107,17 @@ RSpec.describe 'Tournament follower sync websocket HTTP E2E' do
response.fetch(:json) response.fetch(:json)
end end
def create_team_action_list!(tournament_id)
response = source_client.post("/tournaments/#{tournament_id}/team_action_lists", body: {
name: 'Playoff token collection',
key: playoff_token_list_key,
action_name: 'Collect playoff token',
source: 'group_stage_survivors'
})
expect(response[:status]).to eq(201)
response.fetch(:json)
end
def finish_group_stage_and_create_playoffs!(source_id:) def finish_group_stage_and_create_playoffs!(source_id:)
tournament = fetch_tournament(base_url: source_base_url, tournament_id: source_id) tournament = fetch_tournament(base_url: source_base_url, tournament_id: source_id)
group_stage = tournament.fetch(:stages).find { |stage| stage.fetch(:level) == -1 } group_stage = tournament.fetch(:stages).find { |stage| stage.fetch(:level) == -1 }
@ -161,13 +173,17 @@ RSpec.describe 'Tournament follower sync websocket HTTP E2E' do
def find_playoff_token_list!(tournament) def find_playoff_token_list!(tournament)
tournament.fetch(:team_action_lists).find do |list| tournament.fetch(:team_action_lists).find do |list|
list.fetch(:key) == 'group_stage_survivor_playoff_tokens' list.fetch(:key) == playoff_token_list_key
end || raise('playoff token list missing') end || raise('playoff token list missing')
end end
def team_action_item_completed?(payload, team_name:) def team_action_item_completed?(payload, team_name:)
list = payload.fetch('team_action_lists').find { |candidate| candidate.fetch('key') == 'group_stage_survivor_playoff_tokens' } list = payload.fetch('team_action_lists').find { |candidate| candidate.fetch('key') == playoff_token_list_key }
item = list.fetch('team_action_items').find { |candidate| candidate.dig('team', 'name') == team_name } item = list.fetch('team_action_items').find { |candidate| candidate.dig('team', 'name') == team_name }
item.fetch('completed') item.fetch('completed')
end end
def playoff_token_list_key
'playoff_token_collection'
end
end end

View File

@ -63,6 +63,7 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
) )
finish_group_stage_and_create_playoffs!(leader.fetch(:id)) finish_group_stage_and_create_playoffs!(leader.fetch(:id))
create_team_action_list!(leader.fetch(:id))
leader_after_playoffs = fetch_tournament(leader.fetch(:id)) leader_after_playoffs = fetch_tournament(leader.fetch(:id))
token_list = find_playoff_token_list!(leader_after_playoffs) token_list = find_playoff_token_list!(leader_after_playoffs)
@ -73,7 +74,7 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
expect(update_by_item_id[:status]).to eq(200) expect(update_by_item_id[:status]).to eq(200)
update_by_business_key = client.patch( update_by_business_key = client.patch(
"/tournaments/#{leader.fetch(:id)}/team_action_lists/group_stage_survivor_playoff_tokens/teams/#{second_item.dig(:team, :id)}", "/tournaments/#{leader.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/#{second_item.dig(:team, :id)}",
body: { completed: true } body: { completed: true }
) )
expect(update_by_business_key[:status]).to eq(200) expect(update_by_business_key[:status]).to eq(200)
@ -94,6 +95,7 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
leader = create_group_stage_tournament(name_prefix: 'Missing Action Resource Leader') leader = create_group_stage_tournament(name_prefix: 'Missing Action Resource Leader')
finish_group_stage_and_create_playoffs!(leader.fetch(:id)) finish_group_stage_and_create_playoffs!(leader.fetch(:id))
create_team_action_list!(leader.fetch(:id))
leader_after_playoffs = fetch_tournament(leader.fetch(:id)) leader_after_playoffs = fetch_tournament(leader.fetch(:id))
token_list = find_playoff_token_list!(leader_after_playoffs) token_list = find_playoff_token_list!(leader_after_playoffs)
@ -109,7 +111,7 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
expect(missing_list_update[:status]).to eq(404) expect(missing_list_update[:status]).to eq(404)
missing_team_update = client.patch( missing_team_update = client.patch(
"/tournaments/#{leader.fetch(:id)}/team_action_lists/group_stage_survivor_playoff_tokens/teams/999999999", "/tournaments/#{leader.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/999999999",
body: { completed: true } body: { completed: true }
) )
expect(missing_team_update[:status]).to eq(404) expect(missing_team_update[:status]).to eq(404)
@ -179,6 +181,17 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
expect(finish_stage[:status]).to eq(200) expect(finish_stage[:status]).to eq(200)
end end
def create_team_action_list!(tournament_id)
response = client.post("/tournaments/#{tournament_id}/team_action_lists", body: {
name: 'Playoff token collection',
key: playoff_token_list_key,
action_name: 'Collect playoff token',
source: 'group_stage_survivors'
})
expect(response[:status]).to eq(201)
response.fetch(:json)
end
def play_match!(match_id, first_score:, second_score:) def play_match!(match_id, first_score:, second_score:)
match_response = anonymous_client.get("/matches/#{match_id}") match_response = anonymous_client.get("/matches/#{match_id}")
expect(match_response[:status]).to eq(200) expect(match_response[:status]).to eq(200)
@ -198,10 +211,14 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
def find_playoff_token_list!(tournament) def find_playoff_token_list!(tournament)
tournament.fetch(:team_action_lists).find do |list| tournament.fetch(:team_action_lists).find do |list|
list.fetch(:key) == 'group_stage_survivor_playoff_tokens' list.fetch(:key) == playoff_token_list_key
end || raise('playoff token list missing') end || raise('playoff token list missing')
end end
def playoff_token_list_key
'playoff_token_collection'
end
def playoff_token_item_completed?(tournament, team_name:) def playoff_token_item_completed?(tournament, team_name:)
list = find_playoff_token_list!(tournament) list = find_playoff_token_list!(tournament)
item = list.fetch(:team_action_items).find { |candidate| candidate.dig(:team, :name) == team_name } item = list.fetch(:team_action_items).find { |candidate| candidate.dig(:team, :name) == team_name }

View File

@ -26,6 +26,7 @@ RSpec.describe 'Tournament team action lists websocket HTTP E2E' do
it 'broadcasts initial and updated team action list state over websocket' do it 'broadcasts initial and updated team action list state over websocket' do
tournament = create_group_stage_tournament(name_prefix: 'Ws Leader') tournament = create_group_stage_tournament(name_prefix: 'Ws Leader')
finish_group_stage_and_create_playoffs!(tournament.fetch(:id)) finish_group_stage_and_create_playoffs!(tournament.fetch(:id))
create_team_action_list!(tournament.fetch(:id))
tournament = fetch_tournament(tournament.fetch(:id)) tournament = fetch_tournament(tournament.fetch(:id))
token_list = find_playoff_token_list!(tournament) token_list = find_playoff_token_list!(tournament)
@ -33,7 +34,7 @@ RSpec.describe 'Tournament team action lists websocket HTTP E2E' do
cable_client.subscribe_team_action_lists!(tournament_id: tournament.fetch(:id)) cable_client.subscribe_team_action_lists!(tournament_id: tournament.fetch(:id))
initial_payload = cable_client.wait_for_payload! initial_payload = cable_client.wait_for_payload!
expect(initial_payload.fetch('team_action_lists').first.fetch('key')).to eq('group_stage_survivor_playoff_tokens') expect(initial_payload.fetch('team_action_lists').first.fetch('key')).to eq(playoff_token_list_key)
first_item = token_list.fetch(:team_action_items).first first_item = token_list.fetch(:team_action_items).first
second_item = token_list.fetch(:team_action_items)[1] second_item = token_list.fetch(:team_action_items)[1]
@ -49,7 +50,7 @@ RSpec.describe 'Tournament team action lists websocket HTTP E2E' do
expect(team_action_item_completed?(first_update, team_name: first_item.dig(:team, :name))).to eq(true) expect(team_action_item_completed?(first_update, team_name: first_item.dig(:team, :name))).to eq(true)
update_by_business_key = client.patch( update_by_business_key = client.patch(
"/tournaments/#{tournament.fetch(:id)}/team_action_lists/group_stage_survivor_playoff_tokens/teams/#{second_item.dig(:team, :id)}", "/tournaments/#{tournament.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/#{second_item.dig(:team, :id)}",
body: { completed: true } body: { completed: true }
) )
expect(update_by_business_key[:status]).to eq(200) expect(update_by_business_key[:status]).to eq(200)
@ -113,6 +114,17 @@ RSpec.describe 'Tournament team action lists websocket HTTP E2E' do
expect(finish_stage[:status]).to eq(200) expect(finish_stage[:status]).to eq(200)
end end
def create_team_action_list!(tournament_id)
response = client.post("/tournaments/#{tournament_id}/team_action_lists", body: {
name: 'Playoff token collection',
key: playoff_token_list_key,
action_name: 'Collect playoff token',
source: 'group_stage_survivors'
})
expect(response[:status]).to eq(201)
response.fetch(:json)
end
def play_match!(match_id, first_score:, second_score:) def play_match!(match_id, first_score:, second_score:)
match_response = anonymous_client.get("/matches/#{match_id}") match_response = anonymous_client.get("/matches/#{match_id}")
expect(match_response[:status]).to eq(200) expect(match_response[:status]).to eq(200)
@ -142,13 +154,17 @@ RSpec.describe 'Tournament team action lists websocket HTTP E2E' do
def find_playoff_token_list!(tournament) def find_playoff_token_list!(tournament)
tournament.fetch(:team_action_lists).find do |list| tournament.fetch(:team_action_lists).find do |list|
list.fetch(:key) == 'group_stage_survivor_playoff_tokens' list.fetch(:key) == playoff_token_list_key
end || raise('playoff token list missing') end || raise('playoff token list missing')
end end
def team_action_item_completed?(payload, team_name:) def team_action_item_completed?(payload, team_name:)
list = payload.fetch('team_action_lists').find { |candidate| candidate.fetch('key') == 'group_stage_survivor_playoff_tokens' } list = payload.fetch('team_action_lists').find { |candidate| candidate.fetch('key') == playoff_token_list_key }
item = list.fetch('team_action_items').find { |candidate| candidate.dig('team', 'name') == team_name } item = list.fetch('team_action_items').find { |candidate| candidate.dig('team', 'name') == team_name }
item.fetch('completed') item.fetch('completed')
end end
def playoff_token_list_key
'playoff_token_collection'
end
end end