From 885ba3a46f8653f74f998245f0acf983672ecacc Mon Sep 17 00:00:00 2001 From: Oneric Date: Mon, 1 Dec 2025 18:25:58 +0100 Subject: [PATCH] test: add more representation tests for perpare_outgoing Port of commit 272799da6242dbf7387d2d42dfc98512cd7efd7e from Akkoma PR 1018. Changes from Akkoma commit: - changed order of arguments in CommonAPI.(un)block, because Akkoma hasn't backported our change for the unified arg order yet In particular this covers the case e88f36f72b5317debafcc4209b91eb35ad8f0691 was meant to fix and --- .../web/activity_pub/transmogrifier_test.exs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index e34a101b2..108f17caf 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -611,6 +611,70 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do } = prepared["object"] end + test "Correctly handles Undo activities" do + blocked = insert(:user) + blocker = insert(:user, local: true) + + blocked_ap_id = blocked.ap_id + blocker_ap_id = blocker.ap_id + + {:ok, %Activity{} = block_activity} = CommonAPI.block(blocked, blocker) + {:ok, %Activity{} = undo_activity} = CommonAPI.unblock(blocked, blocker) + {:ok, data} = Transmogrifier.prepare_outgoing(undo_activity.data) + + block_ap_id = block_activity.data["id"] + assert is_binary(block_ap_id) + + assert match?( + %{ + "@context" => [_ | _], + "type" => "Undo", + "id" => "http://localhost" <> _, + "actor" => ^blocker_ap_id, + "object" => ^block_ap_id, + "to" => [^blocked_ap_id], + "cc" => [], + "bto" => [], + "bcc" => [] + }, + data + ) + end + + test "Correctly handles EmojiReact activities" do + user = insert(:user, local: true) + note_activity = insert(:note_activity) + + user_ap_id = user.ap_id + user_followers = user.follower_address + note_author = note_activity.data["actor"] + note_ap_id = note_activity.data["object"] + + assert is_binary(note_author) + assert is_binary(note_ap_id) + + {:ok, react_activity} = CommonAPI.react_with_emoji(note_activity.id, user, "🐈") + {:ok, data} = Transmogrifier.prepare_outgoing(react_activity.data) + + assert match?( + %{ + "@context" => [_ | _], + "type" => "EmojiReact", + "actor" => ^user_ap_id, + "to" => [^user_followers, ^note_author], + "cc" => ["https://www.w3.org/ns/activitystreams#Public"], + "bto" => [], + "bcc" => [], + "content" => "🐈", + "context" => "2hu", + "id" => "http://localhost" <> _, + "object" => ^note_ap_id, + "tag" => [] + }, + data + ) + end + test "it prepares a quote post" do user = insert(:user)