Skip to content

Commit c68796f

Browse files
committed
feat: add helpdesk chat participants api with unit and e2e tests
1 parent ec60985 commit c68796f

File tree

8 files changed

+254
-0
lines changed

8 files changed

+254
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCollectionMixin,
4+
AsyncCreateMixin,
5+
AsyncDeleteMixin,
6+
AsyncUpdateMixin,
7+
CollectionMixin,
8+
CreateMixin,
9+
DeleteMixin,
10+
UpdateMixin,
11+
)
12+
from mpt_api_client.models import Model
13+
14+
15+
class ChatParticipant(Model):
16+
"""Helpdesk Chat Participant resource."""
17+
18+
19+
class ChatParticipantsServiceConfig:
20+
"""Helpdesk Chat Participants service configuration."""
21+
22+
_endpoint = "/public/v1/helpdesk/chats/{chat_id}/participants"
23+
_model_class = ChatParticipant
24+
_collection_key = "data"
25+
26+
27+
class ChatParticipantsService(
28+
CreateMixin[ChatParticipant],
29+
UpdateMixin[ChatParticipant],
30+
DeleteMixin,
31+
CollectionMixin[ChatParticipant],
32+
Service[ChatParticipant],
33+
ChatParticipantsServiceConfig,
34+
):
35+
"""Helpdesk Chat Participants service."""
36+
37+
38+
class AsyncChatParticipantsService(
39+
AsyncCreateMixin[ChatParticipant],
40+
AsyncUpdateMixin[ChatParticipant],
41+
AsyncDeleteMixin,
42+
AsyncCollectionMixin[ChatParticipant],
43+
AsyncService[ChatParticipant],
44+
ChatParticipantsServiceConfig,
45+
):
46+
"""Async Helpdesk Chat Participants service."""

mpt_api_client/resources/helpdesk/chats.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
AsyncChatMessagesService,
1919
ChatMessagesService,
2020
)
21+
from mpt_api_client.resources.helpdesk.chat_participants import (
22+
AsyncChatParticipantsService,
23+
ChatParticipantsService,
24+
)
2125

2226

2327
class Chat(Model):
@@ -52,6 +56,12 @@ def links(self, chat_id: str) -> ChatLinksService:
5256
"""Return chat links service."""
5357
return ChatLinksService(http_client=self.http_client, endpoint_params={"chat_id": chat_id})
5458

59+
def participants(self, chat_id: str) -> ChatParticipantsService:
60+
"""Return chat participants service."""
61+
return ChatParticipantsService(
62+
http_client=self.http_client, endpoint_params={"chat_id": chat_id}
63+
)
64+
5565

5666
class AsyncChatsService(
5767
AsyncCreateMixin[Chat],
@@ -74,3 +84,9 @@ def links(self, chat_id: str) -> AsyncChatLinksService:
7484
return AsyncChatLinksService(
7585
http_client=self.http_client, endpoint_params={"chat_id": chat_id}
7686
)
87+
88+
def participants(self, chat_id: str) -> AsyncChatParticipantsService:
89+
"""Return async chat participants service."""
90+
return AsyncChatParticipantsService(
91+
http_client=self.http_client, endpoint_params={"chat_id": chat_id}
92+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pytest
2+
3+
from tests.e2e.helper import (
4+
async_create_fixture_resource_and_delete,
5+
create_fixture_resource_and_delete,
6+
)
7+
8+
9+
@pytest.fixture
10+
def chat_participants_service(mpt_ops, chat_id):
11+
return mpt_ops.helpdesk.chats.participants(chat_id)
12+
13+
14+
@pytest.fixture
15+
def async_chat_participants_service(async_mpt_ops, chat_id):
16+
return async_mpt_ops.helpdesk.chats.participants(chat_id)
17+
18+
19+
@pytest.fixture
20+
def chat_participant_data(account_id, user_id):
21+
return {
22+
"identity": {"id": user_id},
23+
"account": {"id": account_id},
24+
}
25+
26+
27+
@pytest.fixture
28+
def created_chat_participant(chat_participants_service, chat_participant_data):
29+
with create_fixture_resource_and_delete(
30+
chat_participants_service, chat_participant_data
31+
) as chat_participant:
32+
yield chat_participant
33+
34+
35+
@pytest.fixture
36+
async def async_created_chat_participant(async_chat_participants_service, chat_participant_data):
37+
async with async_create_fixture_resource_and_delete(
38+
async_chat_participants_service, chat_participant_data
39+
) as chat_participant:
40+
yield chat_participant
41+
42+
43+
@pytest.fixture
44+
def invalid_chat_participant_id():
45+
return "CHP-0000-0000-0000"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
async def test_list_chat_participants(async_chat_participants_service):
9+
result = await async_chat_participants_service.fetch_page(limit=1)
10+
11+
assert len(result) > 0
12+
13+
14+
def test_create_chat_participant(async_created_chat_participant): # noqa: AAA01
15+
assert async_created_chat_participant.id is not None
16+
17+
18+
async def test_update_chat_participant(
19+
async_chat_participants_service, async_created_chat_participant
20+
):
21+
result = await async_chat_participants_service.update(
22+
async_created_chat_participant.id,
23+
{"status": "Active"},
24+
)
25+
26+
assert result.id == async_created_chat_participant.id
27+
28+
29+
async def test_delete_chat_participant(
30+
async_chat_participants_service, async_created_chat_participant
31+
):
32+
result = async_created_chat_participant
33+
34+
await async_chat_participants_service.delete(result.id)
35+
36+
37+
async def test_update_chat_participant_not_found(
38+
async_chat_participants_service, invalid_chat_participant_id
39+
):
40+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
41+
await async_chat_participants_service.update(
42+
invalid_chat_participant_id,
43+
{"status": "Active"},
44+
)
45+
46+
47+
async def test_delete_chat_participant_not_found(
48+
async_chat_participants_service, invalid_chat_participant_id
49+
):
50+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
51+
await async_chat_participants_service.delete(invalid_chat_participant_id)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
def test_list_chat_participants(chat_participants_service):
9+
result = chat_participants_service.fetch_page(limit=1)
10+
11+
assert len(result) > 0
12+
13+
14+
def test_create_chat_participant(created_chat_participant): # noqa: AAA01
15+
assert created_chat_participant.id is not None
16+
17+
18+
def test_update_chat_participant(chat_participants_service, created_chat_participant):
19+
result = chat_participants_service.update(created_chat_participant.id, {"status": "Active"})
20+
21+
assert result.id == created_chat_participant.id
22+
23+
24+
def test_delete_chat_participant(chat_participants_service, created_chat_participant):
25+
result = created_chat_participant
26+
27+
chat_participants_service.delete(result.id)
28+
29+
30+
def test_update_chat_participant_not_found(chat_participants_service, invalid_chat_participant_id):
31+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
32+
chat_participants_service.update(invalid_chat_participant_id, {"status": "Active"})
33+
34+
35+
def test_delete_chat_participant_not_found(chat_participants_service, invalid_chat_participant_id):
36+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
37+
chat_participants_service.delete(invalid_chat_participant_id)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.helpdesk.chat_participants import (
4+
AsyncChatParticipantsService,
5+
ChatParticipantsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def chat_participants_service(http_client) -> ChatParticipantsService:
11+
return ChatParticipantsService(
12+
http_client=http_client, endpoint_params={"chat_id": "CHT-0000-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_chat_participants_service(async_http_client) -> AsyncChatParticipantsService:
18+
return AsyncChatParticipantsService(
19+
http_client=async_http_client, endpoint_params={"chat_id": "CHT-0000-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(chat_participants_service) -> None:
24+
result = (
25+
chat_participants_service.path
26+
== "/public/v1/helpdesk/chats/CHT-0000-0000-0001/participants"
27+
)
28+
29+
assert result is True
30+
31+
32+
def test_async_endpoint(async_chat_participants_service) -> None:
33+
result = (
34+
async_chat_participants_service.path
35+
== "/public/v1/helpdesk/chats/CHT-0000-0000-0001/participants"
36+
)
37+
38+
assert result is True
39+
40+
41+
@pytest.mark.parametrize("method", ["create", "update", "delete", "iterate"])
42+
def test_methods_present(chat_participants_service, method: str) -> None:
43+
result = hasattr(chat_participants_service, method)
44+
45+
assert result is True
46+
47+
48+
@pytest.mark.parametrize("method", ["create", "update", "delete", "iterate"])
49+
def test_async_methods_present(async_chat_participants_service, method: str) -> None:
50+
result = hasattr(async_chat_participants_service, method)
51+
52+
assert result is True

tests/unit/resources/helpdesk/test_chats.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
AsyncChatMessagesService,
99
ChatMessagesService,
1010
)
11+
from mpt_api_client.resources.helpdesk.chat_participants import (
12+
AsyncChatParticipantsService,
13+
ChatParticipantsService,
14+
)
1115
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService
1216

1317

@@ -46,6 +50,7 @@ def test_async_mixins_present(async_chats_service, method):
4650
[
4751
("messages", ChatMessagesService),
4852
("links", ChatLinksService),
53+
("participants", ChatParticipantsService),
4954
],
5055
)
5156
def test_property_services(chats_service, service_method, expected_service_class):
@@ -60,6 +65,7 @@ def test_property_services(chats_service, service_method, expected_service_class
6065
[
6166
("messages", AsyncChatMessagesService),
6267
("links", AsyncChatLinksService),
68+
("participants", AsyncChatParticipantsService),
6369
],
6470
)
6571
def test_async_property_services(async_chats_service, service_method, expected_service_class):

0 commit comments

Comments
 (0)