discourse/spec/services/upcoming_changes/track_spec.rb
Martin Brennan 02edc8a05b
FEATURE: Change upcoming change available notification cadence (#40157)
Since we have been using the upcoming change system
more heavily, we noticed that notifications for available changes
(i.e. changes that have been added at promotion status - 1 OR
changes that recently reached promotion status - 1) are crowding
the admin's notifications a lot.

To address this, we already allowed admins to opt out of these
in 0c46a2e805 . However, we also
want to reduce the cadence of these notifications for admins who do want
to opt out completely.

This commit changes upcoming change available notifications to be
collected & sent in a weekly job, rather than in the job that runs
every 20 minutes & logs added/status changed events.

This weekly job will also handle consolidating existing unread upcoming
change available notifications, and making sure that we do not send
N new notifications per change when an admin has no existing unread
notification.

Upcoming change promoted notifications will still happen "instantly"
2026-05-25 09:38:33 +10:00

63 lines
1.9 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe UpcomingChanges::Track do
fab!(:admin_1, :admin)
fab!(:admin_2, :admin)
describe ".call" do
subject(:result) { described_class.call }
let(:added_changes_result) { [:added_change] }
let(:removed_changes_result) { [:removed_change] }
let(:status_changes_result) { { status_change: :data } }
before do
allow(UpcomingChanges::Action::TrackAddedChanges).to receive(:call).and_return(
added_changes_result,
)
allow(UpcomingChanges::Action::TrackRemovedChanges).to receive(:call).and_return(
removed_changes_result,
)
allow(UpcomingChanges::Action::TrackStatusChanges).to receive(:call).and_return(
status_changes_result,
)
end
it "runs successfully" do
expect(result).to run_successfully
end
it "calls TrackAddedChanges with correct arguments" do
result
expect(UpcomingChanges::Action::TrackAddedChanges).to have_received(:call) do |args|
expect(args[:all_admins]).to contain_exactly(admin_1, admin_2)
end
end
it "calls TrackRemovedChanges" do
result
expect(UpcomingChanges::Action::TrackRemovedChanges).to have_received(:call)
end
it "calls TrackStatusChanges with correct arguments" do
result
expect(UpcomingChanges::Action::TrackStatusChanges).to have_received(:call) do |args|
expect(args[:all_admins]).to contain_exactly(admin_1, admin_2)
expect(args[:added_changes]).to eq([:added_change])
expect(args[:removed_changes]).to eq([:removed_change])
end
end
it "populates the context with results from actions" do
expect(result).to have_attributes(
added_changes: [:added_change],
removed_changes: [:removed_change],
status_changes: {
status_change: :data,
},
)
end
end
end