Skip to content

Commit

Permalink
Add test for mixed reactions handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AstraLuma committed Nov 10, 2023
1 parent a1ef87e commit 43f9174
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/activities/models/test_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,53 @@ def test_react_stats_multiple(
assert post.stats["likes"] == 1


@pytest.mark.django_db
@pytest.mark.parametrize("local", [True, False])
def test_react_stats_mixed(
identity: Identity,
other_identity: Identity,
remote_identity: Identity,
stator,
local: bool,
):
"""
Ensures that mixed Likes and Reactions get aggregated
"""
post = Post.create_local(author=identity, content="I love birds!")
for i, reaction in enumerate("abc"):
if local:
PostService(post).like_as(other_identity, reaction)
else:
message = {
"id": f"test{i}",
"type": "Like",
"actor": remote_identity.actor_uri,
"object": post.object_uri,
"content": reaction,
}
InboxMessage.objects.create(message=message)

if local:
PostService(post).like_as(other_identity)
else:
message = {
"id": "test",
"type": "Like",
"actor": remote_identity.actor_uri,
"object": post.object_uri,
}
InboxMessage.objects.create(message=message)

# Run stator thrice - to receive the post, make fanouts and then process them
for _ in range(4):
stator.run_single_cycle()

post.refresh_from_db()

assert post.stats["reactions"] == {"a": 1, "b": 1, "c": 1, "": 1}
assert post.stats["likes"] == 1


# TODO: Test that multiple reactions can be added and deleted correctly

# TODO: How should plain likes and reactions from the same source be handled?
Expand Down

0 comments on commit 43f9174

Please sign in to comment.