Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
initial tests for ranked waiting list
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkOnIT committed Sep 2, 2024
1 parent 5b5e0d7 commit 3c19be6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
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
1 change: 0 additions & 1 deletion lib/lane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def update_events(new_event_ids)
end

private

# Used for propagating a change in waiting_list_position to all affected registrations
# increment_value is the value by which position should be shifted - usually 1 or -1
# Lower waiting_list_position = higher up the waiting list (1 on waiting list will be accepted before 10)
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
23 changes: 22 additions & 1 deletion spec/models/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end
end

describe '#update_competing_lane!', :tag do
describe '#update_competing_lane!' do
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)
Expand Down Expand Up @@ -300,6 +300,27 @@
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

0 comments on commit 3c19be6

Please sign in to comment.