Merge branch 'fix/timer-timezone-offset' into TUR-32_backend-beamer

This commit is contained in:
Tobias Huber 2026-04-16 08:10:53 +02:00
commit 513c9d8ae1
3 changed files with 69 additions and 31 deletions

View File

@ -96,7 +96,7 @@ class TournamentsController < ApplicationController
# GET /tournaments/:id/timer_end
def timer_end
render json: { timer_end: @tournament.timer_end }
render json: { timer_end: serialize_timer_end(@tournament.timer_end) }
end
# PATCH /tournaments/:id/set_timer_end
@ -115,6 +115,10 @@ class TournamentsController < ApplicationController
{ timer_end: params[:timer_end] }
end
def serialize_timer_end(timer_end)
timer_end&.iso8601
end
def organize_teams_in_groups(teams)
# each team gets put into an array of teams depending on the group specified in team[:group]
teams.group_by { |team| team['group'] }.values.map do |group|
@ -177,7 +181,6 @@ class TournamentsController < ApplicationController
error: 'playoff_teams_amount, instant_finalists_amount and intermediate_round_participants_amount don\'t match'
}, status: :unprocessable_entity
end
end
def validate_set_timer_end_params
timer_end = params[:timer_end]
@ -207,6 +210,8 @@ def validate_set_timer_end_params
elsif !parsed_time.future?
return render json: { error: 'Timer end must be in the future' }, status: :unprocessable_entity
end
params[:timer_end] = parsed_time
rescue ArgumentError
return render json: { error: 'Invalid datetime format' }, status: :unprocessable_entity
end
@ -214,3 +219,4 @@ def validate_set_timer_end_params
return render json: { error: 'Timer end is required' }, status: :unprocessable_entity
end
end
end

View File

@ -2,9 +2,13 @@
class TournamentSerializer < SimpleTournamentSerializer
attributes :description, :playoff_teams_amount,
:instant_finalists_amount, :intermediate_round_participants_amount, :timer_end
:instant_finalists_amount, :intermediate_round_participants_amount
has_many :stages
attribute :timer_end do
object.timer_end&.iso8601
end
attribute :owner_username do
object.owner.username
end

View File

@ -142,6 +142,34 @@ RSpec.describe TournamentsController, type: :controller do
end
end
describe 'GET #timer_end' do
it 'returns timer_end in ISO 8601 format' do
timer_end = Time.utc(2026, 4, 13, 18, 0, 0)
@tournament.update!(timer_end: timer_end)
get :timer_end, params: { id: @tournament.to_param }
expect(response).to be_successful
expect(deserialize_response(response)[:timer_end]).to eq(timer_end.iso8601)
end
end
describe 'PATCH #set_timer_end' do
before(:each) do
apply_authentication_headers_for @user
end
it 'stores timezone-aware timer_end values without shifting them' do
timer_end = '2030-04-13T18:00:00+02:00'
patch :set_timer_end, params: { id: @tournament.to_param, timer_end: timer_end }
expect(response).to be_successful
expect(@tournament.reload.timer_end.iso8601).to eq(Time.iso8601(timer_end).utc.iso8601)
expect(deserialize_response(response)[:timer_end]).to eq(@tournament.timer_end.iso8601)
end
end
describe 'POST #create' do
let(:create_playoff_tournament_data) do
{