Skip to content

Commit

Permalink
Allow qualification on the day of the deadline (#9412)
Browse files Browse the repository at this point in the history
* Allow qualification on the day of the deadline

* fixed tests to support on or beore

* Update spec_helper.rb

---------

Co-authored-by: Duncan <[email protected]>
Co-authored-by: Duncan <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 9acf597 commit c81e14d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/qualification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.load(json)

def can_register?(user, event_id)
return false if user.person.nil?
before_deadline_results = user.person.results.in_event(event_id).before(self.when_date)
before_deadline_results = user.person.results.in_event(event_id).on_or_before(self.when_date)
# Allow any competitor with a result to register when type == "ranking" or type == "anyResult".
# When type == "ranking", the results need to be manually cleared out later.
case self.wcif_type
Expand Down
32 changes: 30 additions & 2 deletions spec/lib/qualification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@
expect(qualification.can_register?(user, '333')).to be true
end

# User's qualifying result was achieved on the 2nd
it "requires end date before" do
# Result must be achieved by the 3rd - user qualifies because result achieved before whenDate
input = {
'resultType' => 'single',
'type' => 'attemptResult',
Expand All @@ -211,6 +213,7 @@
expect(qualification).to be_valid
expect(qualification.can_register?(user, '333')).to be true

# Result must be achieved by the 2nd - user qualifies because result achieved on whenDate
input = {
'resultType' => 'single',
'type' => 'attemptResult',
Expand All @@ -219,6 +222,17 @@
}
qualification = Qualification.load(input)
expect(qualification).to be_valid
expect(qualification.can_register?(user, '333')).to be true

# Result must be achieved by the 1st - user does not qualify because result achieved after whenDate
input = {
'resultType' => 'single',
'type' => 'attemptResult',
'whenDate' => '2021-03-01',
'level' => 1150,
}
qualification = Qualification.load(input)
expect(qualification).to be_valid
expect(qualification.can_register?(user, '333')).to be false
end
end
Expand Down Expand Up @@ -331,7 +345,9 @@
expect(qualification.can_register?(user, '333')).to be true
end

it "requires end date before" do
# User's qualifying result was achieved on the 2nd
it "supports achieving result on qualification date" do
# Result must be achieved by the 3rd - user qualifies because result achieved before whenDate
input = {
'resultType' => 'average',
'type' => 'attemptResult',
Expand All @@ -342,11 +358,23 @@
expect(qualification).to be_valid
expect(qualification.can_register?(user, '333oh')).to be true

# Result must be achieved by the 2nd - user qualifies because result achieved on whenDate
input = {
'resultType' => 'average',
'type' => 'attemptResult',
'whenDate' => '2021-03-02',
'level' => 2510,
'level' => 2500,
}
qualification = Qualification.load(input)
expect(qualification).to be_valid
expect(qualification.can_register?(user, '333oh')).to be true

# Result must be achieved by the 1st - user does not qualify because result achieved after whenDate
input = {
'resultType' => 'average',
'type' => 'attemptResult',
'whenDate' => '2021-03-01',
'level' => 2500,
}
qualification = Qualification.load(input)
expect(qualification).to be_valid
Expand Down

0 comments on commit c81e14d

Please sign in to comment.