Skip to content

Commit

Permalink
add conditional check for cutoff date
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyheadford committed May 22, 2024
1 parent ce8219a commit 49976ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/services/mentors/check_training_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
module Mentors
class CheckTrainingCompletion < BaseService
EARLY_ROLL_OUT_COMPLETION_DATE = Date.new(2021, 4, 19)
# hard coded for 2024 as we don't know what is required next year as yet
# this is the date when we will no longer accept 2021 declarations
DECLARATION_WINDOW_CLOSE_DATE = Date.new(2024, 7, 31)

def call
return unless mentor_profile.mentor?
return if marked_as_started_not_completed_after_declaration_window_closes?

set_completion_values!
end
Expand Down Expand Up @@ -39,6 +43,13 @@ def completed_declaration
@completed_declaration ||= find_valid_declaration
end

def marked_as_started_not_completed_after_declaration_window_closes?
return false if Time.zone.today < DECLARATION_WINDOW_CLOSE_DATE

# eg. set as complete via csv or manually for the rule 3 category (started but not completed)
mentor_profile.mentor_completion_date.present? && mentor_profile.started_not_completed?
end

def find_valid_declaration
mentor_profile
.participant_declarations
Expand Down
36 changes: 36 additions & 0 deletions spec/services/mentors/check_training_completion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@
expect(mentor_profile.mentor_completion_reason).to be_blank
end
end

context "when the mentor is marked as started_not_completed before the declaration cutoff date", travel_to: Mentors::CheckTrainingCompletion::DECLARATION_WINDOW_CLOSE_DATE - 1.day do
before do
mentor_profile.complete_training!(completion_date: 1.week.ago,
completion_reason: :started_not_completed)
end

it "changes the completion date to the declaration date" do
service_call
expect(mentor_profile.mentor_completion_date.to_date).to eq declaration.declaration_date.to_date
end

it "changes to completion_reason to completed declaration received" do
service_call
expect(mentor_profile).to be_completed_declaration_received
end
end

context "when the mentor is marked as started_not_completed after the declaration cutoff date", travel_to: Mentors::CheckTrainingCompletion::DECLARATION_WINDOW_CLOSE_DATE + 1.day do
before do
mentor_profile.complete_training!(completion_date: 1.week.ago.to_date,
completion_reason: :started_not_completed)
end

it "does not change the completion date" do
expect {
service_call
}.not_to change { mentor_profile.mentor_completion_date }
end

it "does not change the completion_reason" do
expect {
service_call
}.not_to change { mentor_profile.mentor_completion_reason }
end
end
end

context "when the mentor has not completed training" do
Expand Down

0 comments on commit 49976ec

Please sign in to comment.