fix: stabilize sync privacy and e2e coverage

This commit is contained in:
Daniel Schädler 2026-04-20 22:08:49 +02:00
parent 2019d0d029
commit af7beb193a
2 changed files with 31 additions and 26 deletions

View File

@ -46,7 +46,11 @@ class TournamentsController < ApplicationController
render json: @tournament, serializer: SimpleTournamentSerializer render json: @tournament, serializer: SimpleTournamentSerializer
else else
rendered_json = @request_profiling.measure('serialize_tournament') do rendered_json = @request_profiling.measure('serialize_tournament') do
ActiveModelSerializers::SerializableResource.new(@tournament, include: '**').as_json ActiveModelSerializers::SerializableResource.new(
@tournament,
include: '**',
scope: current_user
).as_json
end end
@request_profiling.apply_to(response, label: 'tournament.show') @request_profiling.apply_to(response, label: 'tournament.show')
render json: rendered_json render json: rendered_json
@ -160,7 +164,7 @@ class TournamentsController < ApplicationController
@tournament.reload @tournament.reload
render json: { render json: {
error: e.message, error: e.message,
tournament: TournamentSerializer.new(@tournament).as_json tournament: TournamentSerializer.new(@tournament, scope: current_user).as_json
}, status: :bad_gateway }, status: :bad_gateway
end end

View File

@ -24,14 +24,12 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
let(:anonymous_client) { TurniereE2E::ApiClient.new(base_url: base_url) } let(:anonymous_client) { TurniereE2E::ApiClient.new(base_url: base_url) }
it 'roundtrips current snapshot into follower tournament through test_sync endpoint' do it 'roundtrips current snapshot into follower tournament through test_sync endpoint' do
leader = create_group_stage_tournament(name_prefix: 'Sync Test Leader')
follower = create_follower_tournament(name_prefix: 'Sync Test Follower') follower = create_follower_tournament(name_prefix: 'Sync Test Follower')
leader = create_group_stage_tournament(
configure = client.patch("/tournaments/#{leader.fetch(:id)}", body: { name_prefix: 'Sync Test Leader',
sync_target_url: "#{base_url}/tournaments/#{follower.fetch(:id)}/sync_state", sync_target_url: "#{base_url}/tournaments/#{follower.fetch(:id)}/sync_state",
sync_auth_token: sync_token sync_auth_token: sync_token
}) )
expect(configure[:status]).to eq(200)
rename = client.patch("/tournaments/#{leader.fetch(:id)}", body: { rename = client.patch("/tournaments/#{leader.fetch(:id)}", body: {
name: "Leader Renamed #{SecureRandom.hex(3)}", name: "Leader Renamed #{SecureRandom.hex(3)}",
@ -50,7 +48,6 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
after_leader = fetch_tournament(leader.fetch(:id)) after_leader = fetch_tournament(leader.fetch(:id))
after_follower = fetch_tournament(follower.fetch(:id)) after_follower = fetch_tournament(follower.fetch(:id))
expect(after_follower.fetch(:read_only_mode)).to eq(true)
expect(after_follower.fetch(:name)).to eq(after_leader.fetch(:name)) expect(after_follower.fetch(:name)).to eq(after_leader.fetch(:name))
expect(after_follower.fetch(:description)).to eq(after_leader.fetch(:description)) expect(after_follower.fetch(:description)).to eq(after_leader.fetch(:description))
expect(after_follower.fetch(:teams).map { |team| team.fetch(:name) }) expect(after_follower.fetch(:teams).map { |team| team.fetch(:name) })
@ -65,22 +62,26 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
api_client api_client
end end
def create_group_stage_tournament(name_prefix:) def create_group_stage_tournament(name_prefix:, sync_target_url: nil, sync_auth_token: nil)
response = client.post('/tournaments', body: { body = {
name: "#{name_prefix} #{SecureRandom.hex(3)}", name: "#{name_prefix} #{SecureRandom.hex(3)}",
description: 'Leader tournament for sync test endpoint', description: 'Leader tournament for sync test endpoint',
public: false, public: false,
group_stage: true, group_stage: true,
playoff_teams_amount: 4, playoff_teams_amount: 4,
teams: 2.times.flat_map do |group_index| teams: 2.times.flat_map do |group_index|
4.times.map do |seed_index| 4.times.map do |seed_index|
{ {
name: "#{name_prefix.tr(' ', '')}-G#{group_index + 1}-S#{seed_index + 1}", name: "#{name_prefix.tr(' ', '')}-G#{group_index + 1}-S#{seed_index + 1}",
group: group_index group: group_index
} }
end end
end end
}) }
body[:sync_target_url] = sync_target_url unless sync_target_url.nil? || sync_target_url.empty?
body[:sync_auth_token] = sync_auth_token unless sync_auth_token.nil? || sync_auth_token.empty?
response = client.post('/tournaments', body: body)
expect(response[:status]).to eq(201) expect(response[:status]).to eq(201)
fetch_tournament(response.dig(:json, :id)) fetch_tournament(response.dig(:json, :id))
end end