From 70787d1fea05d3f8e9e52c2b28236ffee535d05f Mon Sep 17 00:00:00 2001 From: starswan Date: Thu, 28 Nov 2024 12:02:34 +0000 Subject: [PATCH] improve tests slightly --- spec/jobs/send_daily_alert_email_job_spec.rb | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/spec/jobs/send_daily_alert_email_job_spec.rb b/spec/jobs/send_daily_alert_email_job_spec.rb index 46dc20afd1..a960a3d1dd 100644 --- a/spec/jobs/send_daily_alert_email_job_spec.rb +++ b/spec/jobs/send_daily_alert_email_job_spec.rb @@ -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 @@ -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) } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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