Files
fizzy/test/models/notifier_test.rb
T
Kevin McConnell 0820badcc3 Add involvement types to accesses
This provides a way to set the level of involvement that a user has with
a collection, and from which we determine the level of notifications to
send. Users can be access-only, watching, or being notified about
everything.

If you're access-only, you won't get an notifications. If you're
watching, you'll only get notifications for the items you're watching
(which includes the items you've been assigned, have commented on, etc).
If you're set to everything you'll get notifications about all activity
in that collection.

This change replaces our previous concept of subscriptions. Where
previously you'd subscribe to a collection to get notifications in it,
now you'll simply set the notification level on your access.
2025-04-03 16:35:13 +01:00

68 lines
2.2 KiB
Ruby

require "test_helper"
class NotifierTest < ActiveSupport::TestCase
test "for returns the matching notifier class for the event" do
assert_kind_of Notifier::Published, Notifier.for(events(:logo_published))
end
test "for does not raise an error when the event is not notifiable" do
assert_nothing_raised do
assert_no_difference -> { Notification.count } do
Notifier.for(events(:logo_boost_dhh))
end
end
end
test "generate does not create notifications if the event was system-generated" do
bubbles(:logo).drafted!
events(:logo_published).update!(creator: accounts("37s").users.system)
assert_no_difference -> { Notification.count } do
Notifier.for(events(:logo_published)).generate
end
end
test "creates a notification for each watcher, other than the event creator" do
notifications = Notifier.for(events(:layout_commented)).generate
assert_equal [ users(:kevin) ], notifications.map(&:user)
end
test "does not create a notification for access-only users" do
buckets(:writebook).access_for(users(:kevin)).access_only!
notifications = Notifier.for(events(:layout_commented)).generate
assert_equal [ users(:kevin) ], notifications.map(&:user)
end
test "the published event creates notifications for subscribers as well as watchers" do
notifications = Notifier.for(events(:logo_published)).generate
assert_equal users(:kevin, :jz).sort, notifications.map(&:user).sort
end
test "links to the bubble" do
Notifier.for(events(:logo_published)).generate
assert_equal bubbles(:logo), Notification.last.resource
end
test "assignment events only create a notification for the assignee" do
buckets(:writebook).access_for(users(:jz)).watching!
buckets(:writebook).access_for(users(:kevin)).everything!
notifications = Notifier.for(events(:logo_assignment_jz)).generate
assert_equal [ users(:jz) ], notifications.map(&:user)
end
test "assignment events do not notify users who are access-only for the collection" do
buckets(:writebook).access_for(users(:jz)).access_only!
notifications = Notifier.for(events(:logo_assignment_jz)).generate
assert_empty notifications
end
end