From a09914beb2b54858a213e461577bb7564ca62f77 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Fri, 10 Nov 2023 14:42:53 -0500 Subject: [PATCH] Add test for mixed reactions handling --- tests/activities/models/test_reactions.py | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/activities/models/test_reactions.py b/tests/activities/models/test_reactions.py index ea073a1..328864e 100644 --- a/tests/activities/models/test_reactions.py +++ b/tests/activities/models/test_reactions.py @@ -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?