# retoor from devplacepy.database import get_table from tests.api.sync.conftest import follow_record, seed_world, sync_ok def local(origin, uid): return get_table("sync_links").find_one(origin=origin, kind="users", origin_uid=uid)["local_uid"] def test_follow_unfollow_refollow_keeps_one_row_and_has_no_side_effects(client, admin, origin): seed_world(client, admin, origin) notifications = get_table("notifications").count() xp = get_table("users").find_one(uid=local(origin, "u1"))["xp"] created = sync_ok(client, admin, "follows", origin, [follow_record("f1")])["results"][0] assert created["status"] == "created" sync_ok(client, admin, "follows", origin, [follow_record("f1", updated_at="2025-02-01T00:00:00Z", deleted=True)]) assert get_table("follows").find_one(uid=created["local_uid"])["deleted_by"] == "sync" sync_ok(client, admin, "follows", origin, [follow_record("f1", updated_at="2025-03-01T00:00:00Z")]) assert get_table("follows").count(follower_uid=local(origin, "u2"), following_uid=local(origin, "u1")) == 1 assert get_table("follows").find_one(uid=created["local_uid"])["deleted_at"] is None assert get_table("notifications").count() == notifications assert get_table("users").find_one(uid=local(origin, "u1"))["xp"] == xp def test_self_follow_and_unknown_users(client, admin, origin): seed_world(client, admin, origin) body = sync_ok(client, admin, "follows", origin, [follow_record("f1", "u1", "u1"), follow_record("f2", "ghost", "u1"), follow_record("f3", "u2", "ghost")]) assert [(item["status"], item["reason"]) for item in body["results"]] == [ ("rejected", "self_follow"), ("deferred", "unknown_author"), ("deferred", "unknown_author"), ]