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 281c82a49b
commit fb572f5aa6
2 changed files with 25 additions and 12 deletions

View file

@ -763,12 +763,11 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data)
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}
@ -776,14 +775,10 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data)
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}
@ -804,7 +799,7 @@ def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => objec
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}
@ -824,7 +819,7 @@ def prepare_outgoing(%{"type" => "Accept"} = data) 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
@ -842,7 +837,7 @@ def prepare_outgoing(%{"type" => "Reject"} = data) 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

@ -374,6 +374,24 @@ test "it prepares a quote post" 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