-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement post-release one login email
- Loading branch information
Showing
9 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<% if @application_form.first_name.present? %> | ||
Hello <%= @application_form.first_name %>, | ||
<% end %> | ||
|
||
# How you sign in to Apply for teacher training has changed | ||
|
||
You need to sign in using GOV.UK One Login. You can create a GOV.UK One Login if you do not already have one. | ||
|
||
You should use the same email address to create your GOV.UK One Login that you used to sign in to Apply for teacher training before this change. This is so you keep the existing information in your account. | ||
|
||
If you use a different email address you’ll be able to transfer your account details after you sign in. | ||
|
||
# What is GOV.UK One Login? | ||
|
||
GOV.UK One Login allows you to sign in to some government services using the same email address and password. | ||
|
||
In the future you’ll be able to use your GOV.UK One Login to access all services on GOV.UK. | ||
|
||
<%= render 'unsubscribe_from_emails_like_this' %> |
42 changes: 42 additions & 0 deletions
42
app/workers/send_candidate_one_login_has_arrived_email_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class SendCandidateOneLoginHasArrivedEmailWorker | ||
include Sidekiq::Worker | ||
|
||
def perform | ||
return if should_not_perform? | ||
|
||
BatchDelivery.new(relation:, batch_size: 200).each do |batch_time, application_forms| | ||
SendOneLoginHasArrivedEmailBatchWorker.perform_at(batch_time, application_forms.pluck(:id)) | ||
end | ||
end | ||
|
||
def relation | ||
ApplicationForm | ||
.current_cycle | ||
.where(candidate_id: candidate_ids) | ||
.has_not_received_email('candidate_mailer', 'one_login_has_arrived') | ||
.distinct | ||
end | ||
|
||
private | ||
|
||
def candidate_ids | ||
Candidate | ||
.for_marketing_or_nudge_emails | ||
.where.missing(:one_login_auth) | ||
.pluck(:id) | ||
end | ||
|
||
def should_not_perform? | ||
FeatureFlag.inactive?(:one_login_candidate_sign_in) || OneLogin.bypass? | ||
end | ||
end | ||
|
||
class SendOneLoginHasArrivedEmailBatchWorker | ||
include Sidekiq::Worker | ||
|
||
def perform(application_form_ids) | ||
ApplicationForm.where(id: application_form_ids).find_each do |application_form| | ||
CandidateMailer.one_login_has_arrived(application_form).deliver_later | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
spec/workers/send_candidate_one_login_has_arrived_email_worker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe SendCandidateOneLoginHasArrivedEmailWorker do | ||
before { allow(OneLogin).to receive(:bypass?).and_return(false) } | ||
|
||
describe '#perform' do | ||
context 'feature flag is inactivated' do | ||
before { FeatureFlag.deactivate('one_login_candidate_sign_in') } | ||
|
||
it 'does not enqueue the batch worker' do | ||
create(:application_form) | ||
|
||
allow(SendOneLoginHasArrivedEmailBatchWorker).to receive(:perform_at) | ||
described_class.new.perform | ||
expect(SendOneLoginHasArrivedEmailBatchWorker).not_to have_received(:perform_at) | ||
end | ||
end | ||
|
||
context 'feature flag is activated' do | ||
before { FeatureFlag.activate('one_login_candidate_sign_in') } | ||
|
||
it 'enqueues the batch worker with expected application forms' do | ||
# Last year's application | ||
create(:application_form, recruitment_cycle_year: RecruitmentCycle.previous_year) | ||
# Unsubscribed candidate | ||
create(:application_form, candidate: build(:candidate, unsubscribed_from_emails: true)) | ||
# Candidate with submission blocked | ||
create(:application_form, candidate: build(:candidate, submission_blocked: true)) | ||
# Candidate with locked account | ||
create(:application_form, candidate: build(:candidate, account_locked: true)) | ||
# Candidate has already been sent the email | ||
create(:email, application_form: build(:application_form), mailer: 'candidate_mailer', mail_template: 'one_login_has_arrived') | ||
# Candidate who has a one_login_auth record | ||
with_one_login_auth = create(:candidate, one_login_auth: build(:one_login_auth)) | ||
create(:application_form, candidate: with_one_login_auth) | ||
|
||
should_receive = create(:application_form) | ||
|
||
allow(SendOneLoginHasArrivedEmailBatchWorker).to receive(:perform_at) | ||
described_class.new.perform | ||
expect(SendOneLoginHasArrivedEmailBatchWorker).to have_received(:perform_at).with(kind_of(Time), [should_receive.id]) | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
spec/workers/send_one_login_has_arrived_email_batch_worker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe SendOneLoginHasArrivedEmailBatchWorker do | ||
describe '#perform' do | ||
it 'enqueues candidate emails' do | ||
application_forms = create_list(:application_form, 2) | ||
|
||
expect { described_class.new.perform(application_forms.pluck(:id)) } | ||
.to have_enqueued_mail(CandidateMailer, :one_login_has_arrived).twice | ||
end | ||
end | ||
end |