Files
fizzy/test/models/notification_test.rb
T
2025-07-23 17:28:15 -05:00

42 lines
1.2 KiB
Ruby

require "test_helper"
class NotificationTest < ActiveSupport::TestCase
test "unread marks notification as unread" do
notification = notifications(:logo_published_kevin)
notification.read # Mark as read first
assert_changes -> { notification.reload.read? }, from: true, to: false do
notification.unread
end
end
test "unread broadcasts to notifications" do
notification = notifications(:logo_published_kevin)
notification.read # Mark as read first
assert_turbo_stream_broadcasts([ notification.user, :notifications ], count: 1) do
notification.unread
end
end
test "read marks notification as read" do
notification = notifications(:logo_published_kevin)
# Ensure it starts as unread
notification.update!(read_at: nil)
assert_changes -> { notification.reload.read? }, from: false, to: true do
notification.read
end
end
test "read broadcasts to notifications" do
notification = notifications(:logo_published_kevin)
# Ensure it starts as unread
notification.update!(read_at: nil)
assert_turbo_stream_broadcasts([ notification.user, :notifications ], count: 1) do
notification.read
end
end
end