Skip to content

Commit 6646e63

Browse files
lilyydulilydu
andauthored
[api/tests]: add message_reaction and sent_activity tests (#117)
Co-authored-by: lilydu <[email protected]>
1 parent 019cb9f commit 6646e63

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
# pyright: basic
6+
7+
from datetime import datetime
8+
9+
import pytest
10+
from microsoft.teams.api.activities import MessageReactionActivityInput
11+
from microsoft.teams.api.models import (
12+
Account,
13+
MessageReaction,
14+
)
15+
16+
17+
@pytest.fixture
18+
def mock_reaction_activity(mock_account: Account) -> MessageReactionActivityInput:
19+
"""Create a mock MessageReactionActivityInput for testing."""
20+
return MessageReactionActivityInput(
21+
id="1",
22+
from_=mock_account,
23+
type="messageReaction",
24+
timestamp=datetime.now(),
25+
reactions_added=[],
26+
reactions_removed=[],
27+
)
28+
29+
30+
@pytest.mark.unit
31+
class TestMessageReactionActivityInput:
32+
"""Unit tests for MessageReactionActivityInput class."""
33+
34+
def test_should_update_reaction_activity(
35+
self, mock_reaction_activity: MessageReactionActivityInput, mock_account: Account
36+
) -> None:
37+
updated_activity = mock_reaction_activity.with_recipient(mock_account).with_service_url("http://localhost")
38+
assert updated_activity.recipient == mock_account
39+
assert updated_activity.service_url == "http://localhost"
40+
41+
def test_should_add_reaction(self, mock_reaction_activity: MessageReactionActivityInput) -> None:
42+
reaction = MessageReaction(type="like")
43+
mock_reaction_activity.add_reaction(reaction)
44+
assert mock_reaction_activity.reactions_added and len(mock_reaction_activity.reactions_added) == 1
45+
assert mock_reaction_activity.reactions_added[0].type == "like"
46+
47+
def test_should_remove_reaction(self, mock_reaction_activity: MessageReactionActivityInput) -> None:
48+
reaction = MessageReaction(type="like")
49+
mock_reaction_activity.add_reaction(reaction)
50+
mock_reaction_activity.remove_reaction(reaction)
51+
assert not mock_reaction_activity.reactions_added
52+
assert mock_reaction_activity.reactions_removed and len(mock_reaction_activity.reactions_removed) == 1
53+
assert mock_reaction_activity.reactions_removed[0].type == "like"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
# pyright: basic
6+
7+
import pytest
8+
from microsoft.teams.api.activities import ActivityParams, MessageActivityInput, SentActivity
9+
10+
11+
@pytest.fixture
12+
def mock_new_activity_params() -> ActivityParams:
13+
"""Create a mock ActivityParams for testing."""
14+
return MessageActivityInput(
15+
id="updated-id", type="message", text="updated message", locale="en-US", reply_to_id="activity-3"
16+
)
17+
18+
19+
@pytest.fixture
20+
def mock_sent_activity(mock_new_activity_params: ActivityParams) -> SentActivity:
21+
"""Create a mock SentActivity for testing."""
22+
return SentActivity(
23+
id="sent-1",
24+
activity_params=mock_new_activity_params,
25+
)
26+
27+
28+
@pytest.mark.unit
29+
class TestSentActivity:
30+
"""Unit tests for SentActivity class."""
31+
32+
def test_should_merge_sent_activity(self, mock_sent_activity: SentActivity) -> None:
33+
old_params = MessageActivityInput(
34+
text="old message",
35+
)
36+
merged_activity = SentActivity.merge(old_params, mock_sent_activity)
37+
assert merged_activity.id == "sent-1"
38+
assert merged_activity.activity_params.id == "updated-id"
39+
assert merged_activity.activity_params.type == "message"
40+
assert merged_activity.activity_params.text == "updated message"
41+
assert merged_activity.activity_params.locale == "en-US"
42+
assert merged_activity.activity_params.reply_to_id == "activity-3"

0 commit comments

Comments
 (0)