Skip to content

Commit

Permalink
Email draft applications before deadline (#7085)
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan authored Sep 25, 2024
1 parent b017627 commit f74edcb
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/jobs/send_email_for_draft_job_applications_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class SendEmailForDraftJobApplicationsJob < ApplicationJob
queue_as :default

def perform
threshold = Date.today + 10.days

Vacancy.includes({ job_applications: :jobseeker })
.where("expires_at between ? and ?", threshold, threshold + 1.day)
.find_each do |vacancy|
vacancy.job_applications.draft.each do |job_application|
Jobseekers::VacancyMailer.draft_application_only(job_application).deliver_later
end
end
end
end
10 changes: 10 additions & 0 deletions app/mailers/jobseekers/vacancy_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Jobseekers::VacancyMailer < Jobseekers::BaseMailer
def draft_application_only(job_application)
@job_application = job_application
@vacancy = job_application.vacancy
@to = job_application.email

view_mail(template, to: @to,
subject: I18n.t("jobseekers.vacancy_mailer.draft_application_only.subject", date: @vacancy.expires_at.to_date, job_title: job_application.vacancy.job_title))
end
end
1 change: 1 addition & 0 deletions app/models/job_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class JobApplication < ApplicationRecord

scope :submitted_yesterday, -> { submitted.where("DATE(submitted_at) = ?", Date.yesterday) }
scope :after_submission, -> { where(status: %w[submitted reviewed shortlisted unsuccessful withdrawn]) }
scope :draft, -> { where(status: "draft") }

validates :email_address, email_address: true

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# <%= t(".intro", job_title: @vacancy.job_title, school: @vacancy.organisation.name, date: @vacancy.expires_at.to_date.to_formatted_s) %>
<%= t(".body", link_to: notify_link(jobseekers_job_application_review_url(@job_application), t(".complete"))) %>
<%= t(".outro", link_to: home_page_link) %>
<%= t("shared.jobseeker_footer", home_page_link: home_page_link) %>
1 change: 1 addition & 0 deletions config/analytics_custom_events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ shared:
- jobseeker_subscription_confirmation
- jobseeker_subscription_update
- jobseeker_unlock_instructions
- jobseeker_draft_application_only
- publisher_applications_received
- publisher_invite_to_apply
- publisher_job_application_data_expiry
Expand Down
9 changes: 9 additions & 0 deletions config/locales/mailers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ en:
link_text: view your draft application
subject: Update on %{job_title} at %{organisation_name}

vacancy_mailer:
draft_application_only:
subject: Apply for %{job_title} before %{date}
intro: The deadline to apply for %{job_title} at %{school} is %{date}
body: You started an application for this role, but have not submitted it yet. If you want to apply, there is still time to %{link_to}.
outro: Or search on %{link_to}
complete: complete your application
apply_for_more_jobs: apply for more jobs on Teaching Vacancies

subscription_mailer:
confirmation:
create_account:
Expand Down
5 changes: 5 additions & 0 deletions config/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ send_inactive_account_email:
class: 'SendInactiveAccountEmailJob'
queue: low

send_draft_applications_email:
cron: '20 11 * * *'
class: 'SendEmailForDraftJobApplicationsJob'
queue: default

send_account_confirmation_reminder_email:
cron: '0 9 * * *'
class: 'SendAccountConfirmationReminderEmailJob'
Expand Down
50 changes: 50 additions & 0 deletions spec/jobs/send_email_for_draft_job_applications_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require "rails_helper"

RSpec.describe SendEmailForDraftJobApplicationsJob, type: :job do
let(:jobseeker) { create(:jobseeker) }
let(:vacancy) { create(:vacancy, expires_at: Date.today + time_left + 2.hours) }
let(:job_application) { JobApplication.last }

include Rails.application.routes.url_helpers

before do
create(:job_application, :status_draft, vacancy: vacancy, jobseeker: jobseeker)
end

context "when vacancy has 10 days left" do
let(:time_left) { 10.days }

before do
expect(Jobseekers::VacancyMailer).to receive(:draft_application_only).with(job_application).at_least(:once).and_call_original
end

it "sends an email containing a link to review the job application" do
expect {
perform_enqueued_jobs { described_class.perform_later }
}.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(ActionMailer::Base.deliveries.last.body).to include(jobseekers_job_application_review_url(job_application))
end
end

context "when vacancy has 9 days left" do
let(:time_left) { 9.days }
before do
expect(Jobseekers::VacancyMailer).not_to receive(:draft_application_only)
end

it "doesnt send an email" do
perform_enqueued_jobs { described_class.perform_later }
end
end

context "when vacancy has 11 days left" do
let(:time_left) { 11.days }
before do
expect(Jobseekers::VacancyMailer).not_to receive(:draft_application_only)
end

it "doesnt send an email" do
perform_enqueued_jobs { described_class.perform_later }
end
end
end

0 comments on commit f74edcb

Please sign in to comment.