Add test for tombstoned deliveries

This commit is contained in:
FloatingGhost 2022-12-01 13:39:12 +00:00
parent 7f7669b3db
commit 9c0c27e7b0
4 changed files with 30 additions and 5 deletions

View file

@ -10,8 +10,6 @@ defmodule Pleroma.Object.Pruner do
import Ecto.Query import Ecto.Query
def prune_tombstoned_deliveries do def prune_tombstoned_deliveries do
before_time = cutoff()
from(d in Delivery) from(d in Delivery)
|> join(:inner, [d], o in Object, on: d.object_id == o.id) |> join(:inner, [d], o in Object, on: d.object_id == o.id)
|> where([d, o], fragment("?->>'type' = ?", o.data, "Tombstone")) |> where([d, o], fragment("?->>'type' = ?", o.data, "Tombstone"))

View file

@ -1,8 +1,7 @@
defmodule Pleroma.Object.PrunerTest do defmodule Pleroma.Object.PrunerTest do
use Pleroma.DataCase, async: true use Pleroma.DataCase, async: true
alias Pleroma.Object alias Pleroma.Delivery
alias Pleroma.Repo
alias Pleroma.Object.Pruner alias Pleroma.Object.Pruner
import Pleroma.Factory import Pleroma.Factory
@ -21,4 +20,22 @@ test "it prunes old delete objects" do
refute Object.get_by_id(old_tombstone.id) refute Object.get_by_id(old_tombstone.id)
end end
end end
describe "prune_tombstoned_deliveries" do
test "it prunes old tombstone deliveries" do
user = insert(:user)
tombstone = insert(:tombstone)
tombstoned = insert(:delivery, object: tombstone, user: user)
note = insert(:note)
not_tombstoned = insert(:delivery, object: note, user: user)
Pruner.prune_tombstoned_deliveries()
|> IO.inspect()
refute Repo.get(Delivery, tombstoned.id)
assert Repo.get(Delivery, not_tombstoned.id)
end
end
end end

View file

@ -226,7 +226,7 @@ test "resets the user's default post expiry", %{conn: conn} do
test "does not allow negative integers other than -1 for TTL", %{conn: conn} do test "does not allow negative integers other than -1 for TTL", %{conn: conn} do
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"status_ttl_days" => "-2"}) conn = patch(conn, "/api/v1/accounts/update_credentials", %{"status_ttl_days" => "-2"})
assert user_data = json_response_and_validate_schema(conn, 403) assert json_response_and_validate_schema(conn, 403)
end end
test "updates the user's AKAs", %{conn: conn} do test "updates the user's AKAs", %{conn: conn} do

View file

@ -704,4 +704,14 @@ def frontend_setting_profile_factory(params \\ %{}) do
} }
|> Map.merge(params) |> Map.merge(params)
end end
def delivery_factory(params \\ %{}) do
object = Map.get(params, :object, build(:note))
user = Map.get(params, :user, build(:user))
%Pleroma.Delivery{
object: object,
user: user
}
end
end end