From 32608c240072991b8f9748bd04e03928340d5e30 Mon Sep 17 00:00:00 2001 From: dessanhemrayev Date: Sat, 10 Aug 2024 01:04:41 +0300 Subject: [PATCH] [FIX] helpdesk_mgmt_templates: fix tests --- .../tests/test_helpdesk_ticket.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/helpdesk_mgmt_templates/tests/test_helpdesk_ticket.py b/helpdesk_mgmt_templates/tests/test_helpdesk_ticket.py index 74e72ef7b5..b6a4949713 100644 --- a/helpdesk_mgmt_templates/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt_templates/tests/test_helpdesk_ticket.py @@ -19,6 +19,18 @@ def setUpClass(cls): cls.category_2 = helpdesk_ticket_category_obj.create( {"name": "Category 2", "template_description": "

Description 2

"} ) + cls.category_3 = helpdesk_ticket_category_obj.create( + {"name": "Category 3", "template_description": "

Description 3

"} + ) + helpdesk_ticket_team = cls.env["helpdesk.ticket.team"] + + cls.team_c = helpdesk_ticket_team.create( + { + "name": "Team C", + "user_ids": [(6, 0, [cls.user_team.id])], + "category_ids": [(6, 0, [cls.category_1.id, cls.category_3.id])], + } + ) def test_set_category(self): """ @@ -59,3 +71,59 @@ def test_set_category(self): " to the template_description of Category 1" ), ) + + def test_check_available_team_categories(self): + """ + Test the availability of team categories and + their correct linking to the team and ticket. + """ + # Check that initially, a team should not have categories attached to it. + self.assertFalse( + self.ticket_a_user_own.helpdesk_ticket_category_ids, + msg="A team should not have categories attached to it.", + ) + + # Assign a team to the ticket and check that the categories are linked to the team. + self.ticket_a_user_own.team_id = self.team_c.id + related_category_ids = [self.category_1.id, self.category_3.id] + self.assertEqual( + self.ticket_a_user_own.helpdesk_ticket_category_ids.ids, + related_category_ids, + msg="Categories should be linked to the team.", + ) + + # Set the category_id of the ticket to the first category in the linked categories. + self.ticket_a_user_own.category_id = ( + self.ticket_a_user_own.helpdesk_ticket_category_ids[0] + ) + + # Check that the category_id has been correctly set. + self.assertEqual( + self.ticket_a_user_own.category_id.id, + self.category_1.id, + msg=f"The category ID #{self.category_1.id} was not correctly set", + ) + + def test_create_ticket_with_category(self): + """ + Test the creation of a ticket with a specific category and + verify that the category is correctly set. + """ + # Create a ticket with a specific category + ticket = self.env["helpdesk.ticket"].create( + { + "name": f"Ticket {self.team_c.name} (test)", + "team_id": self.team_c.id, + "user_id": False, + "description": "Test", + "category_id": self.category_1.id, + "priority": "1", + } + ) + + # Check that the category_id has been correctly set + self.assertEqual( + ticket.category_id.id, + self.category_1.id, + msg=f"The category ID #{self.category_1.id} was not correctly set", + )