Skip to content

Commit c553c5f

Browse files
committed
Adding logic to prevent email being scheduled if user can start exam
1 parent cbe3187 commit c553c5f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

app/jobs/cs_accelerator/check_next_steps_job.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ class CheckNextStepsJob < ApplicationJob
33
queue_as :default
44

55
def perform(achievement_id)
6+
programme = Programme.cs_accelerator
67
achievement = Achievement.find(achievement_id)
78
user = achievement.user
8-
enrolment = user.user_programme_enrolments.find_by(programme_id: Programme.cs_accelerator.id)
9+
enrolment = user.user_programme_enrolments.find_by(programme_id: programme.id)
910

1011
return unless enrolment
12+
return if programme.enough_credits_for_test?(user)
1113
return if enrolment.current_state == "complete"
1214

1315
AchievementMailer.with(user_id: user.id).completed_course.deliver_now

spec/jobs/cs_accelerator/check_next_steps_job_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
enrolment
2323
end
2424

25-
it "sends online course completion emails" do
25+
it "sends email for face-to-face course" do
2626
expect { described_class.perform_now(achievement.id) }
2727
.to change { ActionMailer::Base.deliveries.count }.by(1)
2828
end
2929

30-
it "sends face to face course completion emails" do
30+
it "sends email for online course" do
3131
expect { described_class.perform_now(achievement_2.id) }
3232
.to change { ActionMailer::Base.deliveries.count }.by(1)
3333
end
@@ -36,7 +36,6 @@
3636
context "when the user has completed CSA" do
3737
before do
3838
user
39-
allow_any_instance_of(Programmes::CSAccelerator).to receive(:enough_activities_for_test?).with(user).and_return(true)
4039
allow_any_instance_of(Programmes::CSAccelerator).to receive(:user_meets_completion_requirement?).with(user).and_return(true)
4140
enrolment.transition_to(:complete)
4241
end
@@ -51,6 +50,24 @@
5150
.not_to change { ActionMailer::Base.deliveries.count }
5251
end
5352
end
53+
54+
context "when the user has enough credits for the exam" do
55+
before do
56+
user
57+
allow_any_instance_of(Programmes::CSAccelerator).to receive(:enough_credits_for_test?).with(user).and_return(true)
58+
end
59+
60+
it "does not send the online course completion emails" do
61+
expect { described_class.perform_now(achievement.id) }
62+
.not_to change { ActionMailer::Base.deliveries.count }
63+
end
64+
65+
it "does not send the face to face course completion emails" do
66+
expect { described_class.perform_now(achievement_2.id) }
67+
.not_to change { ActionMailer::Base.deliveries.count }
68+
end
69+
end
70+
5471
end
5572

5673
context "when the user is not enrolled on CSA" do

0 commit comments

Comments
 (0)