diff --git a/app/jobs/notification/web_push_job.rb b/app/jobs/notification/web_push_job.rb index cd30e3581..3fb83a513 100644 --- a/app/jobs/notification/web_push_job.rb +++ b/app/jobs/notification/web_push_job.rb @@ -1,5 +1,5 @@ class Notification::WebPushJob < ApplicationJob def perform(notification) - Notification::Push::Web.new(notification).push + Notification::PushTarget::Web.new(notification).push end end diff --git a/app/models/notification/push.rb b/app/models/notification/push_target.rb similarity index 91% rename from app/models/notification/push.rb rename to app/models/notification/push_target.rb index 5def39e5b..26fd2b263 100644 --- a/app/models/notification/push.rb +++ b/app/models/notification/push_target.rb @@ -1,4 +1,4 @@ -class Notification::Push +class Notification::PushTarget attr_reader :notification delegate :card, to: :notification diff --git a/app/models/notification/push/web.rb b/app/models/notification/push_target/web.rb similarity index 86% rename from app/models/notification/push/web.rb rename to app/models/notification/push_target/web.rb index 664473101..fe9b72587 100644 --- a/app/models/notification/push/web.rb +++ b/app/models/notification/push_target/web.rb @@ -1,4 +1,4 @@ -class Notification::Push::Web < Notification::Push +class Notification::PushTarget::Web < Notification::PushTarget def self.push_later(notification) Notification::WebPushJob.perform_later(notification) end diff --git a/app/models/notification/pushable.rb b/app/models/notification/pushable.rb index a780b11c5..8b90a36ba 100644 --- a/app/models/notification/pushable.rb +++ b/app/models/notification/pushable.rb @@ -16,10 +16,9 @@ module Notification::Pushable private def resolve_push_target(target) - if target.is_a?(Symbol) - "Notification::Push::#{target.to_s.classify}".constantize + if target.is_a?(Notification::PushTarget) then target else - target + "Notification::PushTarget::#{target.to_s.classify}".constantize end end end diff --git a/saas/app/jobs/notification/native_push_job.rb b/saas/app/jobs/notification/native_push_job.rb index c6f08f840..e06fc18d2 100644 --- a/saas/app/jobs/notification/native_push_job.rb +++ b/saas/app/jobs/notification/native_push_job.rb @@ -1,5 +1,5 @@ class Notification::NativePushJob < ApplicationJob def perform(notification) - Notification::Push::Native.new(notification).push + Notification::PushTarget::Native.new(notification).push end end diff --git a/saas/app/models/notification/push/native.rb b/saas/app/models/notification/push_target/native.rb similarity index 97% rename from saas/app/models/notification/push/native.rb rename to saas/app/models/notification/push_target/native.rb index 2d0836b85..2eb4e5ef2 100644 --- a/saas/app/models/notification/push/native.rb +++ b/saas/app/models/notification/push_target/native.rb @@ -1,4 +1,4 @@ -class Notification::Push::Native < Notification::Push +class Notification::PushTarget::Native < Notification::PushTarget def self.push_later(notification) Notification::NativePushJob.perform_later(notification) end diff --git a/saas/test/models/notification/push/native_test.rb b/saas/test/models/notification/push_target/native_test.rb similarity index 81% rename from saas/test/models/notification/push/native_test.rb rename to saas/test/models/notification/push_target/native_test.rb index 0cff2336a..b684ec11a 100644 --- a/saas/test/models/notification/push/native_test.rb +++ b/saas/test/models/notification/push_target/native_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class Notification::Push::NativeTest < ActiveSupport::TestCase +class Notification::PushTarget::NativeTest < ActiveSupport::TestCase setup do @user = users(:kevin) @identity = @user.identity @@ -14,7 +14,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase notification = notifications(:logo_assignment_kevin) @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(notification) + push = Notification::PushTarget::Native.new(notification) assert_equal "assignment", push.send(:notification_category) end @@ -23,7 +23,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase notification = notifications(:layout_commented_kevin) @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(notification) + push = Notification::PushTarget::Native.new(notification) assert_equal "comment", push.send(:notification_category) end @@ -32,7 +32,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase notification = notifications(:logo_card_david_mention_by_jz) notification.user.identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(notification) + push = Notification::PushTarget::Native.new(notification) assert_equal "mention", push.send(:notification_category) end @@ -40,7 +40,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "notification_category returns card for other card events" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) assert_equal "card", push.send(:notification_category) end @@ -49,7 +49,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase notification = notifications(:logo_assignment_kevin) @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(notification) + push = Notification::PushTarget::Native.new(notification) assert_equal "time-sensitive", push.send(:interruption_level) end @@ -57,7 +57,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "interruption_level is active for non-assignments" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) assert_equal "active", push.send(:interruption_level) end @@ -67,7 +67,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") assert_native_push_delivery(count: 1) do - Notification::Push::Native.new(@notification).push + Notification::PushTarget::Native.new(@notification).push end end @@ -75,7 +75,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase @identity.devices.delete_all assert_no_native_push_delivery do - Notification::Push::Native.new(@notification).push + Notification::PushTarget::Native.new(@notification).push end end @@ -85,7 +85,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase @notification.update!(creator: users(:system)) assert_no_native_push_delivery do - Notification::Push::Native.new(@notification).push + Notification::PushTarget::Native.new(@notification).push end end @@ -96,14 +96,14 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase @identity.devices.create!(token: "token2", platform: "google", name: "Pixel") assert_native_push_delivery(count: 2) do - Notification::Push::Native.new(@notification).push + Notification::PushTarget::Native.new(@notification).push end end test "native notification includes required fields" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_not_nil native.title @@ -114,7 +114,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "native notification sets thread_id from card" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_equal @notification.card.id, native.thread_id @@ -124,7 +124,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase notification = notifications(:logo_assignment_kevin) notification.user.identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(notification) + push = Notification::PushTarget::Native.new(notification) native = push.send(:native_notification) assert native.high_priority @@ -133,7 +133,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "native notification sets normal priority for non-assignments" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_not native.high_priority @@ -142,7 +142,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "native notification includes apple-specific fields" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_equal 1, native.apple_data.dig(:aps, :"mutable-content") @@ -153,7 +153,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "native notification sets android notification to nil for data-only" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_nil native.google_data.dig(:android, :notification) @@ -162,7 +162,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "native notification includes data payload" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - push = Notification::Push::Native.new(@notification) + push = Notification::PushTarget::Native.new(@notification) native = push.send(:native_notification) assert_not_nil native.data[:url] @@ -172,7 +172,7 @@ class Notification::Push::NativeTest < ActiveSupport::TestCase test "push_later enqueues Notification::NativePushJob" do assert_enqueued_with(job: Notification::NativePushJob, args: [ @notification ]) do - Notification::Push::Native.push_later(@notification) + Notification::PushTarget::Native.push_later(@notification) end end end diff --git a/test/models/notification/push/web_test.rb b/test/models/notification/push_target/web_test.rb similarity index 80% rename from test/models/notification/push/web_test.rb rename to test/models/notification/push_target/web_test.rb index 4c81d6719..abf95f386 100644 --- a/test/models/notification/push/web_test.rb +++ b/test/models/notification/push_target/web_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class Notification::Push::WebTest < ActiveSupport::TestCase +class Notification::PushTarget::WebTest < ActiveSupport::TestCase setup do @user = users(:david) @notification = @user.notifications.create!( @@ -27,28 +27,28 @@ class Notification::Push::WebTest < ActiveSupport::TestCase subscriptions.count == 1 end - Notification::Push::Web.new(@notification).push + Notification::PushTarget::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 + Notification::PushTarget::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 + Notification::PushTarget::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 + Notification::PushTarget::Web.new(@notification).push end test "payload includes card title for card events" do @@ -56,7 +56,7 @@ class Notification::Push::WebTest < ActiveSupport::TestCase payload[:title] == @notification.card.title end - Notification::Push::Web.new(@notification).push + Notification::PushTarget::Web.new(@notification).push end test "payload for comment includes RE prefix" do @@ -67,7 +67,7 @@ class Notification::Push::WebTest < ActiveSupport::TestCase payload[:title].start_with?("RE:") end - Notification::Push::Web.new(notification).push + Notification::PushTarget::Web.new(notification).push end test "payload for assignment includes assigned message" do @@ -78,7 +78,7 @@ class Notification::Push::WebTest < ActiveSupport::TestCase payload[:body].include?("Assigned to you") end - Notification::Push::Web.new(notification).push + Notification::PushTarget::Web.new(notification).push end test "payload for mention includes mentioner name" do @@ -89,12 +89,12 @@ class Notification::Push::WebTest < ActiveSupport::TestCase payload[:title].include?("mentioned you") end - Notification::Push::Web.new(notification).push + Notification::PushTarget::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) + Notification::PushTarget::Web.push_later(@notification) end end end diff --git a/test/models/notification/pushable_test.rb b/test/models/notification/pushable_test.rb index 2f99ac2c5..898061b51 100644 --- a/test/models/notification/pushable_test.rb +++ b/test/models/notification/pushable_test.rb @@ -35,7 +35,7 @@ class Notification::PushableTest < ActiveSupport::TestCase Notification.register_push_target(:web) - assert_includes Notification.push_targets, Notification::Push::Web + assert_includes Notification.push_targets, Notification::PushTarget::Web ensure Notification.push_targets = original_targets end