Add tests

This commit is contained in:
Jorge Manrubia
2025-04-23 16:49:42 +02:00
parent 5749ad77e5
commit 2545604659
5 changed files with 60 additions and 10 deletions
+4
View File
@@ -0,0 +1,4 @@
logo_card_david_mention_by_jz:
source: logo (card)
mentioner: jz
mentionee: david
+1 -9
View File
@@ -5,19 +5,11 @@ class MentionsTest < ActiveSupport::TestCase
Current.session = sessions(:david)
end
test "collect mentions on create" do
test "create mentions when creating messages" do
assert_difference -> { Mention.count }, +1 do
perform_enqueued_jobs only: Mention::CreateJob do
collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?"
end
end
end
test "collect mentions on update" do
assert_difference -> { Mention.count }, +1 do
perform_enqueued_jobs only: Mention::CreateJob do
cards(:logo).update! description: "Did you finish up with the cleanup, @david?"
end
end
end
end
@@ -1,6 +1,6 @@
require "test_helper"
class NotifierTest < ActiveSupport::TestCase
class Notifier::EventNotifierTest < ActiveSupport::TestCase
test "for returns the matching notifier class for the event" do
assert_kind_of Notifier::EventNotifier, Notifier.for(events(:logo_published))
end
@@ -62,4 +62,20 @@ class NotifierTest < ActiveSupport::TestCase
assert_empty notifications
end
test "don't create notifications on publish for mentionees" do
users(:kevin).mentioned_by(users(:david), at: cards(:logo))
assert_no_difference -> { users(:kevin).notifications.count } do
Notifier.for(events(:logo_published)).notify
end
end
test "don't create notifications on comment for mentionees" do
users(:david).mentioned_by(users(:kevin), at: cards(:layout))
assert_no_difference -> { users(:david).notifications.count } do
Notifier.for(events(:layout_commented)).notify
end
end
end
@@ -0,0 +1,27 @@
require "test_helper"
class Notifier::EventNotifierTest < ActiveSupport::TestCase
test "for returns the matching notifier class for the mention" do
assert_kind_of Notifier::MentionNotifier, Notifier.for(mentions(:logo_card_david_mention_by_jz))
end
test "notify the mentionee" do
users(:kevin).mentioned_by(users(:david), at: cards(:logo))
assert_no_difference -> { users(:kevin).notifications.count } do
Notifier.for(mentions(:logo_card_david_mention_by_jz)).notify
end
end
test "create notifications for mentionee" do
assert_no_difference -> { users(:david).notifications.count } do
Notifier.for(events(:layout_commented)).notify
end
end
test "don't create notifications for self-mentions" do
assert_no_difference -> { users(:jz).notifications.count } do
Notifier.for(events(:layout_commented)).notify
end
end
end
+11
View File
@@ -4,4 +4,15 @@ class User::MentionableTest < ActiveSupport::TestCase
test "mentionable handles" do
assert_equal [ "dhh", "david", "davidh" ], User.new(name: "David Heinemeier-Hansson").mentionable_handles
end
test "mentioned by" do
assert_difference -> { users(:david).mentions.count }, +1 do
users(:david).mentioned_by users(:jz), at: cards(:logo)
end
# No dups
assert_no_difference -> { users(:david).mentions.count }, +1 do
users(:david).mentioned_by users(:jz), at: cards(:logo)
end
end
end