From 348b2f270ebfad9c9cb62f6eb5c2503379dfcf45 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Feb 2025 16:58:13 +0930 Subject: [PATCH] test(core): Confirm on category change to ticket that an action comment is created ref: #577 closes #537 --- .../unit/ticket/test_ticket_permission.py | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index d8040a02..ea6f677b 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -527,6 +527,94 @@ class ActionComments(SetUp): assert self.item.status == Ticket.TicketStatus.All.NEW + + def test_ticket_action_comment_category_added(self): + """Action Comment test + Confirm an' action comment is created when a `category` is added + """ + + self.item.category = self.category + + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item.pk, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + for comment in comments: + + if re.match(r"changed category from none to \$ticket_category-" + str(self.category.id) , str(comment.body).lower()): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_category_remove(self): + """Action Comment test + Confirm an action comment is created when the `category` is removed + """ + + self.item.category = self.category + + self.item.save() + + self.item.category = None + + self.item.save() + + + comments = TicketComment.objects.filter( + ticket=self.item.pk, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + for comment in comments: + + if re.match(r"changed category from \$ticket_category-" + str(self.category.id) + " to none", str(comment.body).lower()): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_category_change(self): + """Action Comment test + Confirm an action comment is created when a `category` is changed + """ + + self.item.category = self.category + + self.item.save() + + + self.item.category = self.category_two + + self.item.save() + + + comments = TicketComment.objects.filter( + ticket=self.item.pk, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + for comment in comments: + + if re.match(r"changed category from \$ticket_category-" + str(self.category.id) + r" to \$ticket_category-" + str(self.category_two.id) , str(comment.body).lower()): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_subscribed_users_added_user_subscribed(self): """Action Comment test Confirm a 'user subscribed' action comment is created when a user is added as subscribed