Skip to content

Commit

Permalink
Add email to candidates about login changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Jan 15, 2025
1 parent c5136e6 commit 19c999c
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/mailers/candidate_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ def apply_to_multiple_courses_after_30_working_days(application_form)
)
end

def one_login_is_coming(application_form)
@application_form = application_form

email_for_candidate(
@application_form,
subject: I18n.t!('candidate_mailer.one_login_is_coming.subject'),
)
end

private

def email_for_candidate(application_form, args = {})
Expand Down
17 changes: 17 additions & 0 deletions app/views/candidate_mailer/one_login_is_coming.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hello <%= @application_form.first_name %>,

# How you sign in to Apply for teacher training is changing.

From 27 January you'll sign in using GOV.UK One Login. You'll be able to 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 use to sign in to Apply for teacher training. 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' %>
30 changes: 30 additions & 0 deletions app/workers/send_candidate_one_login_is_coming_email_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class SendCandidateOneLoginIsComingEmailWorker
include Sidekiq::Worker

def perform
return if FeatureFlag.active?(:one_login_candidate_sign_in)

BatchDelivery.new(relation:, batch_size: 200).each do |batch_time, application_forms|
SendOneLoginIsComingEmailBatchWorker.perform_at(batch_time, application_forms.pluck(:id))
end
end

def relation
ApplicationForm
.current_cycle
.joins(:candidate)
.merge(Candidate.for_marketing_or_nudge_emails)
.has_not_received_email('candidate_mailer', 'one_login_is_coming')
.distinct
end
end

class SendOneLoginIsComingEmailBatchWorker
include Sidekiq::Worker

def perform(application_form_ids)
ApplicationForm.where(id: application_form_ids).find_each do |application_form|
CandidateMailer.one_login_is_coming(application_form).deliver_later
end
end
end
1 change: 1 addition & 0 deletions config/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Clock
every(1.day, 'SendApplyToAnotherCourseWhenInactiveEmailToCandidatesWorker', at: '10:00') { SendApplyToAnotherCourseWhenInactiveEmailToCandidatesWorker.perform_async }
every(1.day, 'SendApplyToMultipleCoursesWhenInactiveEmailToCandidatesWorker', at: '10:00') { SendApplyToMultipleCoursesWhenInactiveEmailToCandidatesWorker.perform_async }
every(1.day, 'DfE::Analytics::EntityTableCheckJob', at: '00:30') { DfE::Analytics::EntityTableCheckJob.perform_later }
every(1.day, 'SendCandidateOneLoginIsComingEmailWorker', at: '00:31') { SendCandidateOneLoginIsComingEmailWorker.perform_async }

# End of cycle application choice status jobs
# Changes unsubmitted application choices to 'application_not_sent'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/emails/candidate_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ en:
subject: Get help with your personal statement
apply_to_course_after_inactivity:
subject: Increase your chances of receiving an offer for teacher training
one_login_is_coming:
subject: How you sign into Apply for teacher training is changing
5 changes: 5 additions & 0 deletions spec/mailers/previews/candidate_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@ def apply_to_multiple_courses_after_30_working_days
CandidateMailer.apply_to_multiple_courses_after_30_working_days(application_form)
end

def one_login_is_coming
application_form = FactoryBot.build(:application_form, first_name: 'Bob')
CandidateMailer.one_login_is_coming(application_form)
end

private

def candidate
Expand Down
1 change: 1 addition & 0 deletions spec/system/support_interface/docs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def and_i_see_the_provider_flow_documentation
def and_it_contains_documentation_for_all_emails
emails_outside_of_states = %w[
provider_mailer-fallback_sign_in_email
candidate_mailer-one_login_is_coming
candidate_mailer-eoc_first_deadline_reminder
candidate_mailer-eoc_second_deadline_reminder
candidate_mailer-application_deadline_has_passed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'rails_helper'

RSpec.describe SendCandidateOneLoginIsComingEmailWorker do
describe '#perform' do
context 'feature flag is activated' do
before { FeatureFlag.activate('one_login_candidate_sign_in') }

it 'does not enqueue the batch worker' do
create(:application_form)

allow(SendOneLoginIsComingEmailBatchWorker).to receive(:perform_at)
described_class.new.perform
expect(SendOneLoginIsComingEmailBatchWorker).not_to have_received(:perform_at)
end
end

context 'feature flag is deactivated' do
before { FeatureFlag.deactivate('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_is_coming')

should_receive = create(:application_form)

allow(SendOneLoginIsComingEmailBatchWorker).to receive(:perform_at)
described_class.new.perform
expect(SendOneLoginIsComingEmailBatchWorker).to have_received(:perform_at).with(kind_of(Time), [should_receive.id])
end
end
end
end
12 changes: 12 additions & 0 deletions spec/workers/send_one_login_is_coming_email_batch_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

RSpec.describe SendOneLoginIsComingEmailBatchWorker 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_is_coming).twice
end
end
end

0 comments on commit 19c999c

Please sign in to comment.