Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMacPherson committed Jun 19, 2024
1 parent dddeb7f commit 0bccca2
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 27 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "rails_helper"

RSpec.describe Publishers::JobApplicationDataExpiryNotifier do
let(:organisation) { create(:school) }
let(:publisher) { create(:publisher) }
let(:vacancy) { create(:vacancy, publisher: publisher, organisations: [organisation]) }

describe "#message" do
subject { Noticed::Notification.last.message }

let(:data_expiration_date) { (vacancy.expires_at + 1.year).to_date }
let(:vacancy_applications_link) { "/organisation/jobs/#{vacancy.id}/job_applications" }

before do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end

it "returns the correct message" do
expect(subject).to include(vacancy.job_title)
.and include(format_date(data_expiration_date))
.and include(vacancy_applications_link)
end
end

describe "#timestamp" do
context "when the notification is delivered today" do
before do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end

it "returns the correct timestamp" do
expect(publisher.notifications.first.timestamp).to include("Today at")
end
end

context "when the notification was delivered yesterday" do
before do
travel_to 1.day.ago do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end
publisher.notifications.first.update(created_at: Time.now - 1.day)
end

it "returns the correct timestamp" do
expect(publisher.notifications.first.timestamp).to include("Yesterday at")
end
end

context "when the notification was delivered before yesterday" do
before do
travel_to DateTime.new(2000, 0o1, 0o1, 14, 30) do
described_class
.with(vacancy: vacancy, publisher: publisher)
.deliver(publisher)
end
publisher.notifications.first.update(created_at: DateTime.new(2000, 0o1, 0o1, 14, 30))
end

it "returns the correct timestamp" do
expect(publisher.notifications.first.timestamp).to eq("1 January at 2:30pm")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "rails_helper"

RSpec.describe Publishers::JobApplicationReceivedNotifier do
let(:vacancy) { create(:vacancy, :published, organisations: [build(:school)]) }
let(:publisher) { vacancy.publisher }
let(:job_application) { create(:job_application, :status_submitted, vacancy: vacancy) }

describe "#timestamp" do
context "when the notification is delivered today" do
before do
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(publisher)
end

it "returns the correct timestamp" do
expect(publisher.notifications.last.timestamp).to match(/Today at/)
end
end

context "when the notification was delivered yesterday" do
before do
travel_to 1.day.ago do
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(publisher)
end
publisher.notifications.last.update(created_at: Time.current - 1.day)
end

it "returns the correct timestamp" do
expect(publisher.notifications.last.timestamp).to match(/Yesterday at/)
end
end

context "when the notification was delivered before yesterday" do
before do
travel_to DateTime.new(2000, 0o1, 0o1, 14, 30) do
described_class
.with(vacancy: job_application.vacancy, job_application: job_application)
.deliver(publisher)
end
publisher.notifications.last.update(created_at: DateTime.new(2000, 0o1, 0o1, 14, 30))
end

it "returns the correct timestamp" do
expect(publisher.notifications.last.timestamp).to match("1 January at 2:30pm")
end
end
end
end
1 change: 0 additions & 1 deletion spec/requests/publishers/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
let(:organisation) { build(:school) }
let(:vacancy) { create(:vacancy, organisations: [organisation]) }
let(:job_application) { create(:job_application, vacancy: vacancy) }
# let!(:notification) { create(:notification, :job_application_received, recipient: publisher, params: { vacancy: vacancy, job_application: job_application }) }

before do
Publishers::JobApplicationReceivedNotifier.with(vacancy: vacancy, job_application: job_application).deliver(publisher)
Expand Down

0 comments on commit 0bccca2

Please sign in to comment.