diff --git a/WcaOnRails/lib/results_validators/scrambles_validator.rb b/WcaOnRails/lib/results_validators/scrambles_validator.rb index d6b9916404..417f32c16f 100644 --- a/WcaOnRails/lib/results_validators/scrambles_validator.rb +++ b/WcaOnRails/lib/results_validators/scrambles_validator.rb @@ -7,6 +7,8 @@ class ScramblesValidator < GenericValidator UNEXPECTED_SCRAMBLES_FOR_ROUND_ERROR = "[%{round_id}] Too many scrambles. Use Scrambles Matcher to uncheck the unused scrambles." MISSING_SCRAMBLES_FOR_GROUP_ERROR = "[%{round_id}] Group %{group_id}: missing scrambles, detected only %{actual} instead of %{expected}." MISSING_SCRAMBLES_FOR_MULTI_ERROR = "[%{round_id}] While you may have multiple groups in 3x3x3 Multi-Blind, at least one of the groups must contain scrambles for all attempts." + MULTIPLE_FMC_GROUPS_WARNING = "[%{round_id}] There are multiple groups of FMC used. If one group of FMC was used, please use the Scrambles Matcher to uncheck the unused "\ + "scrambles. Otherwise, please include a comment to WRT explaining why multiple groups of FMC were used." @@desc = "This validator checks that all results have matching scrambles, and if possible, checks that the scrambles have the correct number of attempts compared to the expected round format." @@ -82,6 +84,11 @@ def validate(competition_ids: [], model: Result, results: nil) expected: expected_number_of_scrambles) end end + if round_id.start_with?("333fm") && scrambles_by_group_id.size > 1 + @warnings << ValidationWarning.new(:scrambles, competition_id, + MULTIPLE_FMC_GROUPS_WARNING, + round_id: round_id) + end if round_id.start_with?("333mbf") unless errors_for_round.size < scrambles_by_group_id.keys.size @errors << ValidationError.new(:scrambles, competition_id, diff --git a/WcaOnRails/spec/factories/results.rb b/WcaOnRails/spec/factories/results.rb index 8ba4e74ced..c07b980e34 100644 --- a/WcaOnRails/spec/factories/results.rb +++ b/WcaOnRails/spec/factories/results.rb @@ -33,6 +33,18 @@ value5 { 0 } end + trait :fm do + eventId { "333fm" } + formatId { "m" } + average { 3500 } + best { 35 } + value1 { best } + value2 { best } + value3 { best } + value4 { 0 } + value5 { 0 } + end + trait :mo3 do formatId { "m" } average { best } diff --git a/WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb b/WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb index aa0aeb1ce5..69869636ca 100644 --- a/WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb +++ b/WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb @@ -9,6 +9,7 @@ context "on InboxResult and Result" do let!(:competition1) { FactoryBot.create(:competition, :past, event_ids: ["333oh", "333mbf"]) } let!(:competition2) { FactoryBot.create(:competition, :past, event_ids: ["222", "333bf", "333mbf"]) } + let!(:competition3) { FactoryBot.create(:competition, :past, event_ids: ["333fm"]) } # The idea behind this variable is the following: the validator can be applied # on either a particular model for given competition ids, or on a set of results. @@ -16,8 +17,8 @@ let(:validator_args) { [InboxResult, Result].flat_map { |model| [ - { competition_ids: [competition1.id, competition2.id], model: model }, - { results: model.sorted_for_competitions([competition1.id, competition2.id]), model: model }, + { competition_ids: [competition1.id, competition2.id, competition3.id], model: model }, + { results: model.sorted_for_competitions([competition1.id, competition2.id, competition3.id]), model: model }, ] } } @@ -85,6 +86,32 @@ end end + it "correctly (in)validates multiple groups for 333fm" do + FactoryBot.create(:round, competition: competition3, event_id: "333fm", format_id: "m") + + [Result, InboxResult].each do |model| + result_kind = model.model_name.singular.to_sym + FactoryBot.create(result_kind, :fm, competition: competition3) + end + + # Create two groups in fmc: + create_scramble_set(3, competitionId: competition3.id, eventId: "333fm", groupId: "A") + create_scramble_set(3, competitionId: competition3.id, eventId: "333fm", groupId: "B") + + expected_warnings = [ + RV::ValidationWarning.new(:scrambles, competition3.id, + SV::MULTIPLE_FMC_GROUPS_WARNING, + round_id: "333fm-f"), + ] + + validator_args.each do |arg| + sv = SV.new.validate(arg) + expect(sv.warnings).to match_array(expected_warnings) + puts sv.errors + expect(sv.errors).to be_empty + end + end + it "correctly (in)validates multiple groups for 333mbf" do FactoryBot.create(:round, competition: competition1, event_id: "333mbf", format_id: "3") FactoryBot.create(:round, competition: competition2, event_id: "333mbf", format_id: "3")