From d013e270ba2e70aa470fa669be1f3748e447c52d Mon Sep 17 00:00:00 2001 From: helllllllder Date: Fri, 13 Oct 2023 13:25:28 -0300 Subject: [PATCH] feat: add tests --- chats/apps/queues/models.py | 2 +- chats/apps/queues/tests/test_models.py | 52 +++++++++++++++++- chats/fixtures/fixture_project.json | 74 ++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 chats/fixtures/fixture_project.json diff --git a/chats/apps/queues/models.py b/chats/apps/queues/models.py index 812394ea..3b3a7f41 100644 --- a/chats/apps/queues/models.py +++ b/chats/apps/queues/models.py @@ -68,7 +68,7 @@ def available_agents(self): routing_option = self.project.routing_option rooms_count_filter = models.Q(rooms__is_active=True) - if routing_option == "full_context": + if routing_option == "general": rooms_count_filter = ( models.Q(rooms__ended_at__date__gte=timezone.now().date()) | rooms_count_filter diff --git a/chats/apps/queues/tests/test_models.py b/chats/apps/queues/tests/test_models.py index 7431e6ba..a5b7e5b9 100644 --- a/chats/apps/queues/tests/test_models.py +++ b/chats/apps/queues/tests/test_models.py @@ -90,7 +90,7 @@ def setUp(self): ) -class QueueAvailableAgentsTestCase(QueueSetUpMixin, TestCase): +class QueueAvailableAgentsDefaultTestCase(QueueSetUpMixin, TestCase): def test_available_agents_returns_online_agents(self): self.agent_permission.status = "ONLINE" self.agent_permission.save() @@ -144,6 +144,56 @@ def tests_if_when_there_are_2_agents_it_returns_sorted_by_active_rooms_count(sel self.assertEqual(self.agent_2, self.queue.available_agents.first()) +class QueueAvailableAgentsGaneralTestCase(TestCase): + fixtures = ["chats/fixtures/fixture_app.json", "chats/fixtures/fixture_room.json"] + + def setUp(self): + self.queue = Queue.objects.get(pk="f2519480-7e58-4fc4-9894-9ab1769e29cf") + self.project = Project.objects.get(pk="34a93b52-231e-11ed-861d-0242ac120002") + self.project.config = {"routing_option": "general"} + self.project.save() + self.sector = self.queue.sector + self.sector.rooms_limit = 4 + self.sector.save() + + def test_1_online_user_with_3_active_1_closed(self): + user = User.objects.get(email="amywong@chats.weni.ai") + Room.objects.update(user=user) + Room.objects.first().close() + self.project.permissions.filter(user=user).update(status="ONLINE") + + available_agents = self.queue.available_agents + + self.assertEqual(available_agents.count(), 0) + + def test_1_online_user_with_2_active_1_closed(self): + user = User.objects.get(email="amywong@chats.weni.ai") + user.rooms.first().close() + self.project.permissions.filter(user=user).update(status="ONLINE") + + available_agents = self.queue.available_agents + + self.assertEqual(available_agents.count(), 1) + self.assertEqual(available_agents.first().active_rooms_count, 3) + + def test_2_online_users_with_2_active_1_closed_second_agent_empty(self): + """ + Verify if the first in queue will be the agent with the least rooms + """ + user = User.objects.get(email="amywong@chats.weni.ai") + user.rooms.first().close() + self.project.permissions.filter(user=user).update(status="ONLINE") + self.project.permissions.filter(user__email="linalawson@chats.weni.ai").update( + status="ONLINE" + ) + + available_agents = self.queue.available_agents + + self.assertEqual(available_agents.count(), 2) + self.assertEqual(available_agents.first().active_rooms_count, 0) + self.assertEqual(available_agents.first().email, "linalawson@chats.weni.ai") + + class PropertyTests(QueueSetUpMixin, APITestCase): def test_name_property(self): """ diff --git a/chats/fixtures/fixture_project.json b/chats/fixtures/fixture_project.json new file mode 100644 index 00000000..dd6a44e5 --- /dev/null +++ b/chats/fixtures/fixture_project.json @@ -0,0 +1,74 @@ +[ + { + "model": "projects.project", + "pk": "c599ecd2-8536-49f5-93f9-3c4fa09c22f9", + "fields": { + "created_on": "2022-08-24T19:22:15.781Z", + "modified_on": "2022-08-24T19:22:15.781Z", + "name": "General routing", + "timezone": "America/Sao_Paulo", + "date_format": "D", + "config": { + "routing_option": "general" + } + } + }, + { + "model": "projects.projectpermission", + "pk": "6ea2e553-a7c1-428d-ab8e-45cbd99c309d", + "fields": { + "created_on": "2022-08-24T20:27:42.814Z", + "modified_on": "2022-08-24T20:27:42.815Z", + "project": "c599ecd2-8536-49f5-93f9-3c4fa09c22f9", + "user": "agentqueue@chats.weni.ai", + "role": 1 + } + }, + { + "model": "projects.projectpermission", + "pk": "334549ea-3c8e-4a23-94cb-3cb0a28cbb28", + "fields": { + "created_on": "2022-08-24T20:25:54.375Z", + "modified_on": "2022-08-24T20:25:54.375Z", + "project": "c599ecd2-8536-49f5-93f9-3c4fa09c22f9", + "user": "johndoe@chats.weni.ai", + "role": 2 + } + }, + { + "model": "projects.projectpermission", + "pk": "e1d1cdb4-2a54-4bc8-8d63-6c680ffe589e", + "fields": { + "created_on": "2022-08-24T20:25:36.278Z", + "modified_on": "2022-08-24T20:25:36.278Z", + "project": "c599ecd2-8536-49f5-93f9-3c4fa09c22f9", + "user": "foobar@chats.weni.ai", + "role": 2 + } + }, + { + "model": "sectors.sector", + "pk": "86792083-021d-4e89-b91f-b367d2948aa1", + "fields": { + "created_on": "2022-08-24T20:59:49.115Z", + "modified_on": "2022-08-24T20:59:49.115Z", + "name": "Limited sector", + "project": "c599ecd2-8536-49f5-93f9-3c4fa09c22f9", + "rooms_limit": 3, + "open_offline": false, + "work_start": "08:00:00", + "work_end": "17:00:00", + "is_deleted": false + } + }, + { + "model": "queues.queue", + "pk": "30a237dd-bbff-42ea-ae4a-78675da12529", + "fields": { + "created_on": "2022-08-24T21:40:15.274Z", + "modified_on": "2022-08-24T21:40:15.274Z", + "sector": "86792083-021d-4e89-b91f-b367d2948aa1", + "name": "New routing queue" + } + } +]