-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dddeb7f
commit 0bccca2
Showing
4 changed files
with
121 additions
and
27 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
spec/notifications/publishers/job_application_data_expiry_notification_spec.rb
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
spec/notifications/publishers/job_application_data_expiry_notifier_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,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 |
51 changes: 51 additions & 0 deletions
51
spec/notifications/publishers/job_application_received_notifier_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,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 |
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