Skip to content

Commit bdda404

Browse files
committed
chore: added test case to check if multiple notifications are not sent on adding mention when edited
1 parent fd94e0b commit bdda404

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

helpdesk/helpdesk/doctype/hd_ticket_comment/test_hd_ticket_comment.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_reactions,
1212
toggle_reaction,
1313
)
14+
from helpdesk.mixins.mentions import HasMentions
1415
from helpdesk.test_utils import create_agent
1516

1617

@@ -299,6 +300,84 @@ def test_no_notification_for_self_reaction(self):
299300

300301
frappe.delete_doc("HD Ticket Comment", agent_comment.name, force=True)
301302

303+
def test_if_repeated_notification_sent_on_mention_add(self):
304+
agent_one = self.agent_emails[0]
305+
frappe.set_user(agent_one)
306+
self.assign_agent(agent_one)
307+
308+
agent_comment = frappe.get_doc(
309+
{
310+
"doctype": "HD Ticket Comment",
311+
"reference_ticket": self.test_ticket.name,
312+
"content": """
313+
<p>
314+
Hello
315+
<span class="mention"
316+
data-type="mention"
317+
318+
data-label="Test User Two">
319+
@Test User Two
320+
</span>
321+
</p>
322+
""",
323+
"commented_by": agent_one,
324+
"owner": agent_one,
325+
}
326+
)
327+
328+
agent_comment.insert(ignore_permissions=True)
329+
print(agent_comment)
330+
331+
notifications = frappe.get_all(
332+
"HD Notification",
333+
filters={
334+
"reference_comment": agent_comment.name,
335+
"notification_type": "Mention",
336+
},
337+
fields=["name", "user_to"],
338+
)
339+
print(notifications)
340+
# notification one created should be equal to 1
341+
self.assertEqual(len(notifications), 1)
342+
self.assertEqual(notifications[0].user_to, "[email protected]")
343+
344+
agent_comment.content = """
345+
<p>
346+
Hello
347+
<span class="mention"
348+
data-type="mention"
349+
350+
data-label="Test User Two">
351+
@Test User Two
352+
</span>
353+
<span class="mention"
354+
data-type="mention"
355+
356+
data-label="Test User One">
357+
@Test User One
358+
</span>
359+
</p>
360+
"""
361+
362+
agent_comment.save(ignore_permissions=True)
363+
agent_comment.reload()
364+
notifications_updated = frappe.get_all(
365+
"HD Notification",
366+
filters={
367+
"reference_comment": agent_comment.name,
368+
"notification_type": "Mention",
369+
},
370+
fields=["user_to"],
371+
)
372+
print("notificationsnow", notifications_updated)
373+
print(agent_comment)
374+
375+
user_emails = {n.user_to for n in notifications_updated}
376+
377+
self.assertEqual(len(notifications_updated), 2)
378+
self.assertIn("[email protected]", user_emails)
379+
self.assertIn("[email protected]", user_emails)
380+
302381
def test_grouped_notifications(self):
303382
test_users = self.agent_emails[3:6]
304383

helpdesk/mixins/mentions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ def notify_mentions(self, original_content=None):
3636
if self.doctype == "HD Ticket Comment":
3737
values.reference_comment = self.name
3838
values.reference_ticket = self.reference_ticket
39-
if frappe.db.exists("HD Notification", values):
40-
# avoid loop notification at first mention
39+
if frappe.db.exists(
40+
"HD Notification",
41+
{
42+
"reference_comment": self.name,
43+
"user_to": mention.email,
44+
"notification_type": "Mention",
45+
},
46+
):
47+
# avoid loop of notification to quit at first mention
4148
continue
4249
frappe.get_doc(values).insert()

0 commit comments

Comments
 (0)