Deliver emails for bundled notifications (initial WIP)

This commit is contained in:
Jorge Manrubia
2025-08-26 13:22:22 +02:00
parent 218519d075
commit cfafc54a81
16 changed files with 271 additions and 6 deletions
+35
View File
@@ -0,0 +1,35 @@
require "test_helper"
class Notification::BundleTest < ActiveSupport::TestCase
setup do
@user = users(:david)
end
test "new notifications are bundled" do
notification = assert_difference -> { @user.notification_bundles.pending.count }, 1 do
@user.notifications.create!(source: events(:logo_published), creator: @user)
end
bundle = @user.notification_bundles.pending.last
assert_includes bundle.notifications, notification
end
test "notifications are bundled withing the aggregation period" do
notification_1 = assert_difference -> { @user.notification_bundles.pending.count }, 1 do
@user.notifications.create!(source: events(:logo_published), creator: @user)
end
travel_to 3.hours.from_now
notification_2 = assert_no_difference -> { @user.notification_bundles.count } do
@user.notifications.create!(source: events(:logo_published), creator: @user)
end
travel_to 3.hours.from_now
notification_3 = assert_difference -> { @user.notification_bundles.pending.count }, 1 do
@user.notifications.create!(source: events(:logo_published), creator: @user)
end
bundle_1, bundle_2 = @user.notification_bundles.last(2)
end
end