From 78b7fe0f3da0ac4a87fccf4d7c8663f4e184ce1a Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Tue, 14 Jan 2025 13:08:13 +0000 Subject: [PATCH] Fix tests --- test/fixtures/events.yml | 2 +- test/models/notifier/assigned_test.rb | 11 ++++++----- test/models/notifier/commented_test.rb | 19 +++++++++++++++++++ test/models/notifier/created_test.rb | 6 +++--- test/models/notifier/popped_test.rb | 14 ++++++++++++-- 5 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 test/models/notifier/commented_test.rb diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index 8cf272f34..f1232faa6 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -56,7 +56,7 @@ layout_created: layout_commented: creator: david - action: comment + action: commented summary: layout_initial_activity particulars: <%= { comment_id: ActiveRecord::FixtureSet.identify(:layout_overflowing_david) }.to_json %> created_at: <%= 1.week.ago %> diff --git a/test/models/notifier/assigned_test.rb b/test/models/notifier/assigned_test.rb index 367531b0b..73a6a1236 100644 --- a/test/models/notifier/assigned_test.rb +++ b/test/models/notifier/assigned_test.rb @@ -1,7 +1,7 @@ require "test_helper" class Notifier::AssignedTest < ActiveSupport::TestCase - test "generate creates a notification for each recipient" do + test "creates a notification for the assignee" do assert_difference -> { Notification.count }, 1 do assert_difference -> { users(:kevin).notifications.count }, 1 do Notifier.for(events(:logo_assignment_km)).generate @@ -9,17 +9,18 @@ class Notifier::AssignedTest < ActiveSupport::TestCase end end - test "generate does not notify for self-assignments" do - event = EventSummary.last.events.create! action: :assigned, creator: users(:kevin), particulars: { assignee_ids: [ users(:kevin).id ] } + test "does not notify for self-assignments" do + event = EventSummary.last.events.create! action: :assigned, creator: users(:kevin), + particulars: { assignee_ids: [ users(:kevin).id ] } assert_no_difference -> { Notification.count } do Notifier.for(event).generate end end - test "generate populates the notification details" do + test "links to the bubble" do Notifier.for(events(:logo_assignment_km)).generate - assert_equal "assigned you: The logo isn't big enough", Notification.last.body + assert_equal bubbles(:logo), Notification.last.resource end end diff --git a/test/models/notifier/commented_test.rb b/test/models/notifier/commented_test.rb new file mode 100644 index 000000000..b56275a6b --- /dev/null +++ b/test/models/notifier/commented_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +class Notifier::CommentedTest < ActiveSupport::TestCase + test "creates a notification for each recipient" do + assert_difference -> { Notification.count }, 2 do + assert_difference -> { users(:kevin).notifications.count }, 1 do + assert_difference -> { users(:jz).notifications.count }, 1 do + Notifier.for(events(:layout_commented)).generate + end + end + end + end + + test "links to the bubble" do + Notifier.for(events(:layout_commented)).generate + + assert_equal comments(:layout_overflowing_david), Notification.last.resource + end +end diff --git a/test/models/notifier/created_test.rb b/test/models/notifier/created_test.rb index b9ae7e7b8..47bad1a05 100644 --- a/test/models/notifier/created_test.rb +++ b/test/models/notifier/created_test.rb @@ -1,7 +1,7 @@ require "test_helper" class Notifier::CreatedTest < ActiveSupport::TestCase - test "generate creates a notification for each recipient" do + test "creates a notification for each recipient" do assert_difference -> { Notification.count }, 2 do assert_difference -> { users(:kevin).notifications.count }, 1 do assert_difference -> { users(:jz).notifications.count }, 1 do @@ -11,9 +11,9 @@ class Notifier::CreatedTest < ActiveSupport::TestCase end end - test "generate populates the notification details" do + test "links to the bubble" do Notifier.for(events(:logo_created)).generate - assert_equal "created: The logo isn't big enough", Notification.last.body + assert_equal bubbles(:logo), Notification.last.resource end end diff --git a/test/models/notifier/popped_test.rb b/test/models/notifier/popped_test.rb index ca1289135..842a3f675 100644 --- a/test/models/notifier/popped_test.rb +++ b/test/models/notifier/popped_test.rb @@ -1,9 +1,19 @@ require "test_helper" class Notifier::PoppedTest < ActiveSupport::TestCase - test "generate populates the notification details" do + test "creates a notification for each recipient" do + assert_difference -> { Notification.count }, 2 do + assert_difference -> { users(:david).notifications.count }, 1 do + assert_difference -> { users(:jz).notifications.count }, 1 do + Notifier.for(events(:shipping_popped)).generate + end + end + end + end + + test "links to the bubble" do Notifier.for(events(:shipping_popped)).generate - assert_equal "popped: We need to ship the app", Notification.last.body + assert_equal bubbles(:shipping), Notification.last.resource end end