1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Object.UpdaterTest do
7 use Oban.Testing, repo: Pleroma.Repo
11 alias Pleroma.Object.Updater
13 describe "make_update_object_data/3" do
16 %{original_data: note.data}
19 test "it makes an updated field", %{original_data: original_data} do
20 new_data = Map.put(original_data, "content", "new content")
22 date = Pleroma.Web.ActivityPub.Utils.make_date()
23 update_object_data = Updater.make_update_object_data(original_data, new_data, date)
24 assert %{"updated" => ^date} = update_object_data
27 test "it creates formerRepresentations", %{original_data: original_data} do
28 new_data = Map.put(original_data, "content", "new content")
30 date = Pleroma.Web.ActivityPub.Utils.make_date()
31 update_object_data = Updater.make_update_object_data(original_data, new_data, date)
33 history_item = original_data |> Map.drop(["id", "formerRepresentations"])
36 "formerRepresentations" => %{
38 "orderedItems" => [^history_item]
40 } = update_object_data
44 describe "make_new_object_data_from_update_object/2" do
45 test "it reuses formerRepresentations if it exists" do
46 %{data: original_data} = insert(:note)
50 |> Map.put("content", "edited")
52 date = Pleroma.Web.ActivityPub.Utils.make_date()
53 update_object_data = Updater.make_update_object_data(original_data, new_data, date)
55 history = update_object_data["formerRepresentations"]["orderedItems"]
60 ["formerRepresentations", "orderedItems"],
61 history ++ [Map.put(original_data, "summary", "additional summary")]
63 |> put_in(["formerRepresentations", "totalItems"], length(history) + 1)
66 updated_data: updated_data,
68 used_history_in_new_object?: used_history_in_new_object?
69 } = Updater.make_new_object_data_from_update_object(original_data, update_object_data)
72 assert used_history_in_new_object?
73 assert updated_data["formerRepresentations"] == update_object_data["formerRepresentations"]