Fix adding language to json ld header, add transmogrifier test

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-03-07 14:05:45 +01:00
parent 05cb931e4d
commit a6e066a77d
2 changed files with 25 additions and 12 deletions

View file

@ -751,12 +751,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
object_id
|> Object.normalize(fetch: false)
|> Map.get(:data)
|> prepare_object
data =
data
|> Map.put("object", object)
|> Map.merge(Utils.make_json_ld_header(data))
|> Map.put("object", prepare_object(object))
|> Map.merge(Utils.make_json_ld_header(object))
|> Map.delete("bcc")
{:ok, data}
@ -764,14 +763,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def prepare_outgoing(%{"type" => "Update", "object" => %{"type" => objtype} = object} = data)
when objtype in Pleroma.Constants.updatable_object_types() do
object =
object
|> prepare_object
data =
data
|> Map.put("object", object)
|> Map.merge(Utils.make_json_ld_header(data))
|> Map.put("object", prepare_object(object))
|> Map.merge(Utils.make_json_ld_header(object))
|> Map.delete("bcc")
{:ok, data}
@ -792,7 +787,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
data =
data
|> strip_internal_fields
|> Map.merge(Utils.make_json_ld_header(data))
|> Map.merge(Utils.make_json_ld_header())
|> Map.delete("bcc")
{:ok, data}
@ -812,7 +807,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
data =
data
|> Map.put("object", object)
|> Map.merge(Utils.make_json_ld_header(data))
|> Map.merge(Utils.make_json_ld_header())
{:ok, data}
end
@ -830,7 +825,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
data =
data
|> Map.put("object", object)
|> Map.merge(Utils.make_json_ld_header(data))
|> Map.merge(Utils.make_json_ld_header())
{:ok, data}
end

View file

@ -384,6 +384,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["object"]["quoteUrl"] == quote_id
assert modified["object"]["quoteUri"] == quote_id
end
test "it adds language of the object to its json-ld context" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "Cześć", language: "pl"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.object.data)
assert [_, _, %{"@language" => "pl"}] = modified["@context"]
end
test "it adds language of the object to Create activity json-ld context" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "Cześć", language: "pl"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert [_, _, %{"@language" => "pl"}] = modified["@context"]
end
end
describe "actor rewriting" do