Files

34 lines
2.0 KiB
Python
Raw Permalink Normal View History

# retoor <retoor@molodetz.nl>
from devplacepy.database import get_table
from tests.api.sync.conftest import reaction_record, seed_world, sync_ok
def local(origin, kind, origin_uid):
return get_table("sync_links").find_one(origin=origin, kind=kind, origin_uid=origin_uid)["local_uid"]
def test_reactions_are_created_toggled_and_revived(client, admin, origin):
seed_world(client, admin, origin)
created = sync_ok(client, admin, "reactions", origin, [reaction_record("r1")])["results"][0]
assert created["status"] == "created"
row = get_table("reactions").find_one(uid=created["local_uid"])
assert (row["emoji"], row["target_type"], row["target_uid"]) == ("🔥", "post", local(origin, "posts", "p1"))
sync_ok(client, admin, "reactions", origin, [reaction_record("r1", updated_at="2025-02-01T00:00:00Z", deleted=True)])
assert get_table("reactions").find_one(uid=created["local_uid"])["deleted_by"] == "sync"
sync_ok(client, admin, "reactions", origin, [reaction_record("r1", updated_at="2025-03-01T00:00:00Z")])
assert get_table("reactions").find_one(uid=created["local_uid"])["deleted_at"] is None
def test_a_different_emoji_is_a_different_reaction_and_text_is_refused(client, admin, origin):
seed_world(client, admin, origin)
body = sync_ok(client, admin, "reactions", origin, [reaction_record("r1"), reaction_record("r2", emoji="👍"), reaction_record("r3", emoji="nope")])
assert [item["status"] for item in body["results"]] == ["created", "created", "rejected"]
assert get_table("reactions").count(user_uid=local(origin, "users", "u2"), target_uid=local(origin, "posts", "p1")) == 2
def test_reactions_on_comments_and_projects_wait_for_their_target(client, admin, origin):
seed_world(client, admin, origin)
body = sync_ok(client, admin, "reactions", origin, [reaction_record("r1", target="c1", kind="comment"), reaction_record("r2", target="pr1", kind="project"), reaction_record("r3", target="ghost")])
assert [item["status"] for item in body["results"]] == ["created", "created", "deferred"]