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
101 lines
3.0 KiB
Ruby
101 lines
3.0 KiB
Ruby
require "test_helper"
|
|
|
|
class Notification::Push::WebTest < ActiveSupport::TestCase
|
|
setup do
|
|
@user = users(:david)
|
|
@notification = @user.notifications.create!(
|
|
source: events(:logo_published),
|
|
creator: users(:jason)
|
|
)
|
|
|
|
@user.push_subscriptions.create!(
|
|
endpoint: "https://fcm.googleapis.com/fcm/send/test123",
|
|
p256dh_key: "test_key",
|
|
auth_key: "test_auth"
|
|
)
|
|
|
|
@web_push_pool = mock("web_push_pool")
|
|
Rails.configuration.x.stubs(:web_push_pool).returns(@web_push_pool)
|
|
end
|
|
|
|
test "pushes to web when user has subscriptions" do
|
|
@web_push_pool.expects(:queue).once.with do |payload, subscriptions|
|
|
payload.is_a?(Hash) &&
|
|
payload[:title].present? &&
|
|
payload[:body].present? &&
|
|
payload[:url].present? &&
|
|
subscriptions.count == 1
|
|
end
|
|
|
|
Notification::Push::Web.new(@notification).push
|
|
end
|
|
|
|
test "does not push when user has no subscriptions" do
|
|
@user.push_subscriptions.delete_all
|
|
@web_push_pool.expects(:queue).never
|
|
|
|
Notification::Push::Web.new(@notification).push
|
|
end
|
|
|
|
test "does not push for cancelled accounts" do
|
|
@user.account.cancel(initiated_by: @user)
|
|
@web_push_pool.expects(:queue).never
|
|
|
|
Notification::Push::Web.new(@notification).push
|
|
end
|
|
|
|
test "does not push when creator is system user" do
|
|
@notification.update!(creator: users(:system))
|
|
@web_push_pool.expects(:queue).never
|
|
|
|
Notification::Push::Web.new(@notification).push
|
|
end
|
|
|
|
test "payload includes card title for card events" do
|
|
@web_push_pool.expects(:queue).once.with do |payload, _|
|
|
payload[:title] == @notification.card.title
|
|
end
|
|
|
|
Notification::Push::Web.new(@notification).push
|
|
end
|
|
|
|
test "payload for comment includes RE prefix" do
|
|
event = events(:layout_commented)
|
|
notification = @user.notifications.create!(source: event, creator: event.creator)
|
|
|
|
@web_push_pool.expects(:queue).once.with do |payload, _|
|
|
payload[:title].start_with?("RE:")
|
|
end
|
|
|
|
Notification::Push::Web.new(notification).push
|
|
end
|
|
|
|
test "payload for assignment includes assigned message" do
|
|
event = events(:logo_assignment_david)
|
|
notification = @user.notifications.create!(source: event, creator: event.creator)
|
|
|
|
@web_push_pool.expects(:queue).once.with do |payload, _|
|
|
payload[:body].include?("Assigned to you")
|
|
end
|
|
|
|
Notification::Push::Web.new(notification).push
|
|
end
|
|
|
|
test "payload for mention includes mentioner name" do
|
|
mention = mentions(:logo_card_david_mention_by_jz)
|
|
notification = @user.notifications.create!(source: mention, creator: users(:jz))
|
|
|
|
@web_push_pool.expects(:queue).once.with do |payload, _|
|
|
payload[:title].include?("mentioned you")
|
|
end
|
|
|
|
Notification::Push::Web.new(notification).push
|
|
end
|
|
|
|
test "push_later enqueues Notification::WebPushJob" do
|
|
assert_enqueued_with(job: Notification::WebPushJob, args: [ @notification ]) do
|
|
Notification::Push::Web.push_later(@notification)
|
|
end
|
|
end
|
|
end
|