From f7ca93b2fa01f5139e7123cd3150e45d56c31a9c Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 21 Sep 2020 13:33:29 -0400 Subject: [PATCH] FIX: Do not downcase group name in notification payload Followup to 3d39b4bb --- app/services/post_alerter.rb | 2 +- spec/services/post_alerter_spec.rb | 41 +++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 6b497b0445a..837bbff3769 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -223,7 +223,7 @@ class PostAlerter topic.allowed_groups.map do |g| { group_id: g.id, - group_name: g.name.downcase, + group_name: g.name, inbox_count: DB.query_single(sql, group_id: g.id).first.to_i } end diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 412027b32f8..92d90e86d4e 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -71,19 +71,36 @@ describe PostAlerter do end - it "triggers :before_create_notifications_for_users" do - pm = Fabricate(:topic, archetype: 'private_message', category_id: nil) - op = Fabricate(:post, user: pm.user, topic: pm) - user1 = Fabricate(:user) - user2 = Fabricate(:user) - group = Fabricate(:group, users: [user2]) - pm.allowed_users << user1 - pm.allowed_groups << group - events = DiscourseEvent.track_events do - PostAlerter.post_created(op) + context "group inboxes" do + fab!(:user1) { Fabricate(:user) } + fab!(:user2) { Fabricate(:user) } + fab!(:group) { Fabricate(:group, users: [user2], name: "TestGroup") } + fab!(:pm) { Fabricate(:topic, archetype: 'private_message', category_id: nil, allowed_groups: [group]) } + fab!(:op) { Fabricate(:post, user: pm.user, topic: pm) } + + it "triggers :before_create_notifications_for_users" do + pm.allowed_users << user1 + events = DiscourseEvent.track_events do + PostAlerter.post_created(op) + end + + expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user1], op]) + expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user2], op]) + + end + + it "triggers group summary notification" do + TopicUser.change(user2.id, pm.id, notification_level: TopicUser.notification_levels[:tracking]) + + PostAlerter.post_created(op) + group_summary_notification = Notification.where(user_id: user2.id) + + expect(group_summary_notification.count).to eq(1) + expect(group_summary_notification.first.notification_type).to eq(Notification.types[:group_message_summary]) + + notification_payload = JSON.parse(group_summary_notification.first.data) + expect(notification_payload["group_name"]).to eq(group.name) end - expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user1], op]) - expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user2], op]) end end