test/federator: deduplicate html_mfm test payloads
Some checks are pending
ci/woodpecker/pr/build-amd64 Pipeline is pending approval
ci/woodpecker/pr/build-arm64 Pipeline is pending approval
ci/woodpecker/pr/docs Pipeline is pending approval
ci/woodpecker/pr/lint Pipeline is pending approval
ci/woodpecker/pr/test/1 Pipeline is pending approval
ci/woodpecker/pr/test/2 Pipeline is pending approval
ci/woodpecker/pull_request_closed/lint Pipeline was successful
ci/woodpecker/pull_request_closed/test/1 Pipeline was successful
ci/woodpecker/pull_request_closed/test/2 Pipeline was successful
ci/woodpecker/pull_request_closed/build-arm64 Pipeline was successful
ci/woodpecker/pull_request_closed/build-amd64 Pipeline was successful
ci/woodpecker/pull_request_closed/docs Pipeline was successful

This commit is contained in:
Oneric 2025-06-22 16:09:18 +02:00
parent 81285d06be
commit 1c2407c129

View file

@ -135,8 +135,8 @@ test "successfully processes incoming AP docs with correct origin" do
assert {:cancel, :already_present} = ObanHelpers.perform(job)
end
test "properly processes objects with the htmlMfm attribute true" do
params = %{
defp mfm_activity(object_overrides \\ %{}) do
%{
"@context" => "https://www.w3.org/ns/activitystreams",
"actor" => "http://mastodon.example.org/users/admin",
"type" => "Create",
@ -145,17 +145,20 @@ test "properly processes objects with the htmlMfm attribute true" do
"type" => "Note",
"content" => "<p this-should-be-scrubbed-away>this is the original content</p>",
"source" => %{
"content" =>
"this source content is irrelevant because the object content should be kept",
"content" => "this is the source content",
"mediaType" => "text/x.misskeymarkdown"
},
"htmlMfm" => true,
"id" => "http://mastodon.example.org/users/admin/objects/1",
"attributedTo" => "http://mastodon.example.org/users/admin",
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
|> Map.update!("object", fn obj -> Map.merge(obj, object_overrides) end)
end
test "properly processes objects with the htmlMfm attribute true" do
params = mfm_activity(%{"htmlMfm" => true})
{:ok, job} = Federator.incoming_ap_doc(params)
{:ok, %Pleroma.Activity{data: %{"object" => object_ap_id}}} = ObanHelpers.perform(job)
@ -165,30 +168,12 @@ test "properly processes objects with the htmlMfm attribute true" do
assert html_mfm == true
refute content =~ "this-should-be-scrubbed-away"
refute content =~ "source content is irrelevant"
refute content =~ "this is the source content"
assert content =~ "this is the original content"
end
test "properly processes objects with the htmlMfm attribute false" do
params = %{
"@context" => "https://www.w3.org/ns/activitystreams",
"actor" => "http://mastodon.example.org/users/admin",
"type" => "Create",
"id" => "http://mastodon.example.org/users/admin/activities/1",
"object" => %{
"type" => "Note",
"content" => "<p this-should-be-scrubbed-away>this is the original content</p>",
"source" => %{
"content" => "<p this-should-be-scrubbed-away>$[spin the source content is used]</p>",
"mediaType" => "text/x.misskeymarkdown"
},
"htmlMfm" => false,
"id" => "http://mastodon.example.org/users/admin/objects/1",
"attributedTo" => "http://mastodon.example.org/users/admin",
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
params = mfm_activity(%{"htmlMfm" => false})
{:ok, job} = Federator.incoming_ap_doc(params)
{:ok, %Pleroma.Activity{data: %{"object" => object_ap_id}}} = ObanHelpers.perform(job)
@ -198,29 +183,12 @@ test "properly processes objects with the htmlMfm attribute false" do
assert html_mfm == false
refute content =~ "this-should-be-scrubbed-away"
assert content =~ "the source content is used"
assert content =~ "this is the source content"
refute content =~ "this is the original content"
end
test "properly processes objects with the htmlMfm attribute not set" do
params = %{
"@context" => "https://www.w3.org/ns/activitystreams",
"actor" => "http://mastodon.example.org/users/admin",
"type" => "Create",
"id" => "http://mastodon.example.org/users/admin/activities/1",
"object" => %{
"type" => "Note",
"content" => "<p this-should-be-scrubbed-away>this is the original content</p>",
"source" => %{
"content" => "<p this-should-be-scrubbed-away>$[spin the source content is used]</p>",
"mediaType" => "text/x.misskeymarkdown"
},
"id" => "http://mastodon.example.org/users/admin/objects/1",
"attributedTo" => "http://mastodon.example.org/users/admin",
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
params = mfm_activity()
{:ok, job} = Federator.incoming_ap_doc(params)
{:ok, %Pleroma.Activity{data: %{"object" => object_ap_id}}} = ObanHelpers.perform(job)
@ -228,9 +196,9 @@ test "properly processes objects with the htmlMfm attribute not set" do
%Pleroma.Object{data: %{"content" => content} = data} =
Pleroma.Object.get_by_ap_id(object_ap_id)
assert Map.get(data, "htmlMfm") == nil
refute Map.has_key?(data, "htmlMfm")
refute content =~ "this-should-be-scrubbed-away"
assert content =~ "the source content is used"
assert content =~ "this is the source content"
refute content =~ "this is the original content"
end