-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email draft applications before deadline (#7085)
- Loading branch information
Showing
8 changed files
with
98 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
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 |
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,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 |
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
7 changes: 7 additions & 0 deletions
7
app/views/jobseekers/vacancy_mailer/draft_application_only.text.erb
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,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) %> |
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
50 changes: 50 additions & 0 deletions
50
spec/jobs/send_email_for_draft_job_applications_job_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,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 |