diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2020-01-19 22:04:14 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-01-19 22:04:14 +0300 |
commit | 0f1fc382d09ef7c364f3d19ef25b98d397b2eba4 (patch) | |
tree | 67b28c6abedd068ce68baf045e226211fc6b8bf9 | |
parent | d6a532bf0f280cc191a9f2c1f53af31c451481d9 (diff) | |
download | pleroma-0f1fc382d09ef7c364f3d19ef25b98d397b2eba4.tar.gz |
Add test case for attachment deletion when non-map data.url present in DB
-rw-r--r-- | test/object_test.exs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/object_test.exs b/test/object_test.exs index 997ec9691..9b4e6f0bf 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -143,6 +143,40 @@ defmodule Pleroma.ObjectTest do assert {:ok, files} = File.ls(uploads_dir) refute filename in files end + + test "with objects that have legacy data.url attribute" do + Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image.jpg"), + filename: "an_image.jpg" + } + + user = insert(:user) + + {:ok, %Object{} = attachment} = + Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id) + + {:ok, %Object{}} = Object.create(%{url: "https://google.com", actor: user.ap_id}) + + %{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} = + note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}}) + + uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) + + path = href |> Path.dirname() |> Path.basename() + + assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}") + + Object.delete(note) + + ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + + assert Object.get_by_id(attachment.id) == nil + + assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") + end end describe "normalizer" do |