Skip to content

Commit

Permalink
improve tests slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Nov 28, 2024
1 parent ced492d commit 70787d1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions spec/jobs/send_daily_alert_email_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe SendDailyAlertEmailJob do
subject(:job) { described_class.perform_later }

let(:mail) { double(:mail) }
let(:mail) { double(:mail, deliver_later: nil) }

describe "#perform" do
context "with vacancies" do
Expand All @@ -16,7 +16,7 @@
create(:vacancy, :published_slugged, contact_number: "6", job_roles: %w[headteacher], phases: %w[primary], working_patterns: %w[full_time])
create(:vacancy, :published_slugged, contact_number: "7", job_roles: %w[headteacher], phases: %w[secondary], working_patterns: %w[part_time])
create(:vacancy, :published_slugged, contact_number: "8", organisations: [new_org], job_roles: %w[headteacher], phases: %w[secondary], working_patterns: %w[full_time])
create(:vacancy, :published_slugged, contact_number: "9", job_title: "This is a nice job", job_roles: %w[headteacher], phases: %w[secondary], working_patterns: %w[full_time])
create(:vacancy, :published_slugged, contact_number: "9", job_title: "This is a Really Nice job", job_roles: %w[headteacher], phases: %w[secondary], working_patterns: %w[full_time])
end

let(:new_org) { create(:school) }
Expand All @@ -31,12 +31,24 @@
let(:nice_job) { Vacancy.find_by!(contact_number: "9") }

context "with keyword" do
let(:subscription) { create(:subscription, keyword: "nice", frequency: :daily) }
let(:subscription) { create(:subscription, keyword: keyword, frequency: :daily) }

it "only finds the nice job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [nice_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
context "with plain keyword" do
let(:keyword) { "nice" }

it "only finds the nice job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [nice_job].pluck(:id)) { mail }
perform_enqueued_jobs { job }
end
end

context "with keyword caps and trailing space" do
let(:keyword) { "Nice " }

it "only finds the nice job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [nice_job].pluck(:id)) { mail }
perform_enqueued_jobs { job }
end
end
end

Expand All @@ -45,7 +57,6 @@

it "only finds the teaching job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [teacher_vacancy, ect_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -55,7 +66,6 @@

it "only finds the support job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [support_vacancy].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -65,7 +75,6 @@

it "only finds the visa job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [visa_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -75,7 +84,6 @@

it "only finds the ECT job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [ect_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -85,7 +93,6 @@

it "only finds the Maths job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [french_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -95,7 +102,6 @@

it "only finds the primary school job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [primary_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -105,7 +111,6 @@

it "only finds the part_time job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [part_time_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand All @@ -115,7 +120,6 @@

it "only finds the new_publisher job" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, [new_org_job].pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand Down Expand Up @@ -145,7 +149,6 @@

it "sends the vacancies in publish order descending" do
expect(Jobseekers::AlertMailer).to receive(:alert).with(subscription.id, expected_vacancies.pluck(:id)) { mail }
expect(mail).to receive(:deliver_later) { ActionMailer::MailDeliveryJob.new }
perform_enqueued_jobs { job }
end
end
Expand Down

0 comments on commit 70787d1

Please sign in to comment.