From 0d9afa694777aa378431e84a622b35ea2d9d491c Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 31 Aug 2024 14:28:38 +0200 Subject: [PATCH 1/5] refactored competing_status tests to use shared examples --- spec/models/registration_spec.rb | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index 30221eef..7dec46a9 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -18,29 +18,23 @@ end 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 + describe '#update_competing_lane!', :tag do - 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 From 79c4cab2571e979be3de101b7a281f1ed929e099 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 31 Aug 2024 14:28:58 +0200 Subject: [PATCH 2/5] whitespace --- spec/models/registration_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index 7dec46a9..de198c01 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -19,7 +19,6 @@ end describe '#update_competing_lane!', :tag 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) From 5b5e0d7fcbb9ec9b2201063637ac2fc50d64c689 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 31 Aug 2024 14:29:44 +0200 Subject: [PATCH 3/5] rubocop --- spec/models/registration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index de198c01..8afdad7c 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -33,7 +33,7 @@ { 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] + it_behaves_like 'competing_status updates', params[:old_status], params[:new_status] end end From 3c19be6ada699e58d13d4806e3f696d147948665 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 2 Sep 2024 07:28:09 +0200 Subject: [PATCH 4/5] initial tests for ranked waiting list --- app/models/registration.rb | 13 ++++++++++--- lib/lane.rb | 1 - lib/lane_factory.rb | 2 +- spec/models/registration_spec.rb | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/models/registration.rb b/app/models/registration.rb index 57dde88a..99e310ed 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -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 @@ -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 diff --git a/lib/lane.rb b/lib/lane.rb index d7894519..46c0bbad 100644 --- a/lib/lane.rb +++ b/lib/lane.rb @@ -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) diff --git a/lib/lane_factory.rb b/lib/lane_factory.rb index ae180fbb..63151d10 100644 --- a/lib/lane_factory.rb +++ b/lib/lane_factory.rb @@ -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, diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index 8afdad7c..ba34b52b 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -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) @@ -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' From 42442191d80ecbba570e47680c16d074f5a77778 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 2 Sep 2024 13:53:40 +0200 Subject: [PATCH 5/5] rubocop --- app/models/registration.rb | 2 +- lib/lane.rb | 1 + spec/models/registration_spec.rb | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/registration.rb b/app/models/registration.rb index 99e310ed..b3e4ece6 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -78,7 +78,7 @@ def event_details end def event_details_for(event_id) - competing_lane.lane_details['event_details'].find { |e| e['event_id'] == event_id} + competing_lane.lane_details['event_details'].find { |e| e['event_id'] == event_id } end def competing_waiting_list_position diff --git a/lib/lane.rb b/lib/lane.rb index 46c0bbad..d7894519 100644 --- a/lib/lane.rb +++ b/lib/lane.rb @@ -101,6 +101,7 @@ 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) diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index ba34b52b..8b166794 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -318,7 +318,6 @@ ].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