Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ranked qualification waiting list #668

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/models/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def event_details
competing_lane&.lane_details&.[]('event_details')
end

def event_details_for(event_id)
competing_lane.lane_details['event_details'].find { |e| e['event_id'] == event_id }
end

def competing_waiting_list_position
competing_lane&.lane_details&.[]('waiting_list_position')
end
Expand Down Expand Up @@ -141,9 +145,12 @@ def update_competing_lane!(update_params)
lane.lane_state = update_params[:status]

lane.lane_details['event_details'].each do |event|
# NOTE: Currently event_registration_state is not used - when per-event registrations are added, we need to add validation logic to support cases like
# limited registrations and waiting lists for certain events
event['event_registration_state'] = update_params[:status]
competition = CompetitionApi.find(competition_id)
if competition.get_qualification_for(event['event_id'])['type'] == 'ranking' && update_params[:status] == 'accepted'
event['event_registration_state'] = 'waiting_list'
else
event['event_registration_state'] = update_params[:status]
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/lane_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.competing_lane(event_ids: [], comment: '', admin_comment: '', registrat
competing_lane.completed_steps = ['Event Registration']
competing_lane.lane_state = registration_status
competing_lane.lane_details = {
'event_details' => event_ids.map { |event_id| { event_id: event_id, event_registration_state: registration_status } },
'event_details' => event_ids.map { |event_id| { 'event_id' => event_id, 'event_registration_state' => registration_status } },
'comment' => comment,
'admin_comment' => admin_comment,
'waiting_list_position' => waiting_list_position.to_i,
Expand Down
53 changes: 33 additions & 20 deletions spec/models/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,21 @@
end

describe '#update_competing_lane!' do
it 'given accepted status, it changes the users status to accepted' do
registration = FactoryBot.create(:registration, registration_status: 'pending')
registration.update_competing_lane!({ status: 'accepted' })
expect(registration.competing_status).to eq('accepted')
end

it 'accepted given cancelled, it sets competing_status accordingly' do
registration = FactoryBot.create(:registration, registration_status: 'accepted')
registration.update_competing_lane!({ status: 'cancelled' })
expect(registration.competing_status).to eq('cancelled')
end

it 'accepted given pending, it sets competing_status accordingly' do
registration = FactoryBot.create(:registration, registration_status: 'accepted')
registration.update_competing_lane!({ status: 'pending' })
expect(registration.competing_status).to eq('pending')
RSpec.shared_examples 'competing_status updates' do |old_status, new_status|
it "given #{new_status}, #{old_status} updates as expected" do
registration = FactoryBot.create(:registration, registration_status: old_status)
registration.update_competing_lane!({ status: new_status })
expect(registration.competing_status).to eq(new_status)
end
end

it 'accepted given waiting_list, it sets competing_status' do
registration = FactoryBot.create(:registration, registration_status: 'accepted')
registration.update_competing_lane!({ status: 'waiting_list' })
expect(registration.competing_status).to eq('waiting_list')
[
{ old_status: 'pending', new_status: 'accepted' },
{ old_status: 'accepted', new_status: 'cancelled' },
{ old_status: 'accepted', new_status: 'pending' },
{ old_status: 'accepted', new_status: 'waiting_list' },
].each do |params|
it_behaves_like 'competing_status updates', params[:old_status], params[:new_status]
end
end

Expand Down Expand Up @@ -307,6 +300,26 @@
end
end

describe '#update_competing_lane#event_waiting_lists', :tag do
RSpc.shared_examples 'ranking qualification: event_registration_state updates' do
it 'event_status must correspond to updated competing_status' do |start_status, new_status, event_status|
competition = FactoryBot.build(:competition, :has_qualifications)
stub_json(CompetitionApi.url(competition['id']), 200, competition)
stub_json(CompetitionApi.url("#{competition['id']}/qualifications"), 200, competition['qualifications'])

registration = FactoryBot.create(:registration, registration_status: start_status, events: ['pyram'])
registration.update_competing_lane!({ status: new_status })

expect(registration.event_details_for('pyram')['event_registration_state']).to eq(event_status)
end
end
[
{ starting_competing_status: 'pending', new_competing_status: 'accepted', expected_event_state: 'waiting_list' },
].each do |params|
it_behaves_like 'ranking qualification: event_registration_state updates', params[:starting_competing_status], params[:new_competing_status], params[:expected_event_state]
end
end

describe '#accepted_competitors' do
it 'returns the number of accepted competitors only for a specific competition' do
target_comp = 'TargetCompId'
Expand Down
Loading