Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Jun 27, 2023
1 parent 4d1e7ba commit c7b774c
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 276 deletions.
3 changes: 1 addition & 2 deletions chats/apps/api/v1/external/rooms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ def create(self, validated_data):
raise ValidationError(
{"detail": _("Contact cannot be done outside working hours")}
)
elif sector.validate_agent_status is False:
elif sector.validate_agent_status() is False:
raise ValidationError(
{"detail": _("Contact cannot be done when agents are offline")}
)

# END Check work time

# get flowstart data
Expand Down
41 changes: 41 additions & 0 deletions chats/apps/rooms/tests/test_viewsets_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,44 @@ def test_add_agent_to_nonexistent_room(self):
)

self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)


class RoomsRoutingExternalTests(APITestCase):
fixtures = [
"chats/fixtures/fixture_sector.json",
]

def _create_room(self, token: str, data: dict):
url = reverse("external_rooms-list")
client = self.client
client.credentials(HTTP_AUTHORIZATION=f"Bearer {token}")

return client.post(url, data=data, format="json")

def test_create_external_room_can_open_offline(self):
data = {
"queue_uuid": "8590ad29-5629-448c-bfb6-1bfd5219b8ec",
"contact": {
"external_id": "953fdcc9-1f6f-4abd-b90e-10a35c1cc825",
"name": "Foo Bar",
"email": "[email protected]",
"phone": "+250788123123",
"custom_fields": {},
},
}
response = self._create_room("b5fab78a-4836-468c-96c4-f5b0bba3303a", data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_create_external_room_cannot_open_offline(self):
data = {
"queue_uuid": "605e21b0-4177-4eae-9cfb-529d9972a192",
"contact": {
"external_id": "a5ff0cd3-0bcd-4e91-8120-8718128cb1d9",
"name": "Foo Bar",
"email": "[email protected]",
"phone": "+250788123123",
"custom_fields": {},
},
}
response = self._create_room("b5fab78a-4836-468c-96c4-f5b0bba3303a", data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
20 changes: 20 additions & 0 deletions chats/apps/sectors/migrations/0006_sector_open_offline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.2 on 2023-06-27 13:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sectors", "0005_remove_sector_rooms_limit_greater_than_zero"),
]

operations = [
migrations.AddField(
model_name="sector",
name="open_offline",
field=models.BooleanField(
default=True, verbose_name="Open room when all agents are offline?"
),
),
]
Loading

0 comments on commit c7b774c

Please sign in to comment.