05819f84a2
Replace NotificationPusher with a cleaner architecture: - Add Notification::Pushable concern with push target registry - Add Notification::Push base class with template methods - Add Notification::Push::Web for web push (OSS) - Add Notification::Push::Native for native push (SaaS) - Add Notification::WebPushJob and Notification::NativePushJob Key design: - Registry pattern: Notification.register_push_target(:web) - Template method: push calls should_push? then perform_push - Subclasses override should_push? (with super) and perform_push - Each target handles its own job enqueueing Also: - Add Notification#pushable? for checking push eligibility - Add Notification#identity delegation to user - Reorganize tests to match new class structure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Tidy up saas engine a bit more
59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
require "test_helper"
|
|
|
|
class Notification::PushableTest < ActiveSupport::TestCase
|
|
setup do
|
|
@user = users(:david)
|
|
@notification = @user.notifications.create!(
|
|
source: events(:logo_published),
|
|
creator: users(:jason)
|
|
)
|
|
end
|
|
|
|
test "push_later calls push_later on all registered targets" do
|
|
target = mock("push_target")
|
|
target.expects(:push_later).with(@notification)
|
|
|
|
original_targets = Notification.push_targets
|
|
Notification.push_targets = [ target ]
|
|
|
|
@notification.push_later
|
|
ensure
|
|
Notification.push_targets = original_targets
|
|
end
|
|
|
|
test "push_later is called after notification is created" do
|
|
Notification.any_instance.expects(:push_later)
|
|
|
|
@user.notifications.create!(
|
|
source: events(:logo_published),
|
|
creator: users(:jason)
|
|
)
|
|
end
|
|
|
|
test "register_push_target accepts symbols" do
|
|
original_targets = Notification.push_targets.dup
|
|
|
|
Notification.register_push_target(:web)
|
|
|
|
assert_includes Notification.push_targets, Notification::Push::Web
|
|
ensure
|
|
Notification.push_targets = original_targets
|
|
end
|
|
|
|
test "pushable? returns true for normal notifications" do
|
|
assert @notification.pushable?
|
|
end
|
|
|
|
test "pushable? returns false when creator is system user" do
|
|
@notification.update!(creator: users(:system))
|
|
|
|
assert_not @notification.pushable?
|
|
end
|
|
|
|
test "pushable? returns false for cancelled accounts" do
|
|
@user.account.cancel(initiated_by: @user)
|
|
|
|
assert_not @notification.pushable?
|
|
end
|
|
end
|