X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Ftasks%2Fdatabase_test.exs;h=292a5ef5f3edaf4b09537308ebd22c530ff38fe8;hb=858dbe43607b31cba8c319755c92099cd2c9f5c1;hp=0c7883f332966a54f51dff8256a81605a8ab0c46;hpb=e14cae25aa42fba21bd573ffd45ec1176da7da83;p=akkoma
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs
index 0c7883f33..292a5ef5f 100644
--- a/test/tasks/database_test.exs
+++ b/test/tasks/database_test.exs
@@ -1,16 +1,17 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do
+ use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- use Pleroma.DataCase
-
import Pleroma.Factory
setup_all do
@@ -26,7 +27,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
describe "running remove_embedded_objects" do
test "it replaces objects with references" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
new_data = Map.put(activity.data, "object", activity.object.data)
{:ok, activity} =
@@ -99,10 +100,10 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
test "it turns OrderedCollection likes into empty arrays" do
[user, user2] = insert_pair(:user)
- {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, %{object: object2}} = CommonAPI.post(user, %{"status" => "test test"})
+ {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"})
+ {:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"})
- CommonAPI.favorite(id, user2)
+ CommonAPI.favorite(user2, id)
likes = %{
"first" =>
@@ -127,4 +128,48 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
assert Enum.empty?(Object.get_by_id(object2.id).data["likes"])
end
end
+
+ describe "ensure_expiration" do
+ test "it adds to expiration old statuses" do
+ activity1 = insert(:note_activity)
+
+ {:ok, inserted_at, 0} = DateTime.from_iso8601("2015-01-23T23:50:07Z")
+ activity2 = insert(:note_activity, %{inserted_at: inserted_at})
+
+ %{id: activity_id3} = insert(:note_activity)
+
+ expires_at = DateTime.add(DateTime.utc_now(), 60 * 61)
+
+ Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
+ activity_id: activity_id3,
+ expires_at: expires_at
+ })
+
+ Mix.Tasks.Pleroma.Database.run(["ensure_expiration"])
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PurgeExpiredActivity,
+ args: %{activity_id: activity1.id},
+ scheduled_at:
+ activity1.inserted_at
+ |> DateTime.from_naive!("Etc/UTC")
+ |> Timex.shift(days: 365)
+ )
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PurgeExpiredActivity,
+ args: %{activity_id: activity2.id},
+ scheduled_at:
+ activity2.inserted_at
+ |> DateTime.from_naive!("Etc/UTC")
+ |> Timex.shift(days: 365)
+ )
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PurgeExpiredActivity,
+ args: %{activity_id: activity_id3},
+ scheduled_at: expires_at
+ )
+ end
+ end
end