aboutsummaryrefslogtreecommitdiff
path: root/test/tasks
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-08-22 20:59:58 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-08-22 20:59:58 +0300
commit256ff09aa8068166a9f83e3159f060fd4598af76 (patch)
treea5e5efa83241f28d8d241b9d2d95ca4ceaefd286 /test/tasks
parent8778c16dac1789eeb6dd51524573163216200b5d (diff)
parent73884441f31092bdb2f509950daf9bd3889a9a8b (diff)
downloadpleroma-256ff09aa8068166a9f83e3159f060fd4598af76.tar.gz
[#1149] Merge remote-tracking branch 'remotes/upstream/develop' into 1149-oban-job-queue
# Conflicts: # lib/pleroma/application.ex # lib/pleroma/scheduled_activity_worker.ex # lib/pleroma/web/federator/retry_queue.ex # lib/pleroma/web/oauth/token/clean_worker.ex # test/user_test.exs # test/web/federator_test.exs
Diffstat (limited to 'test/tasks')
-rw-r--r--test/tasks/config_test.exs9
-rw-r--r--test/tasks/database_test.exs47
-rw-r--r--test/tasks/digest_test.exs54
-rw-r--r--test/tasks/relay_test.exs23
-rw-r--r--test/tasks/robots_txt_test.exs8
5 files changed, 131 insertions, 10 deletions
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index a9b79eb5b..9cd47380c 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -11,21 +11,20 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
Mix.shell(Mix.Shell.Process)
temp_file = "config/temp.exported_from_db.secret.exs"
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
-
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
on_exit(fn ->
Mix.shell(Mix.Shell.IO)
Application.delete_env(:pleroma, :first_setting)
Application.delete_env(:pleroma, :second_setting)
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
:ok = File.rm(temp_file)
end)
{:ok, temp_file: temp_file}
end
+ clear_config_all([:instance, :dynamic_configuration]) do
+ Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ end
+
test "settings are migrated to db" do
assert Repo.all(Config) == []
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs
index a8f25f500..a9925c361 100644
--- a/test/tasks/database_test.exs
+++ b/test/tasks/database_test.exs
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do
+ alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
@@ -22,6 +23,52 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
:ok
end
+ describe "running remove_embedded_objects" do
+ test "it replaces objects with references" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ new_data = Map.put(activity.data, "object", activity.object.data)
+
+ {:ok, activity} =
+ activity
+ |> Activity.change(%{data: new_data})
+ |> Repo.update()
+
+ assert is_map(activity.data["object"])
+
+ Mix.Tasks.Pleroma.Database.run(["remove_embedded_objects"])
+
+ activity = Activity.get_by_id_with_object(activity.id)
+ assert is_binary(activity.data["object"])
+ end
+ end
+
+ describe "prune_objects" do
+ test "it prunes old objects from the database" do
+ insert(:note)
+ deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1
+
+ date =
+ Timex.now()
+ |> Timex.shift(days: -deadline)
+ |> Timex.to_naive_datetime()
+ |> NaiveDateTime.truncate(:second)
+
+ %{id: id} =
+ :note
+ |> insert()
+ |> Ecto.Changeset.change(%{inserted_at: date})
+ |> Repo.update!()
+
+ assert length(Repo.all(Object)) == 2
+
+ Mix.Tasks.Pleroma.Database.run(["prune_objects"])
+
+ assert length(Repo.all(Object)) == 1
+ refute Object.get_by_id(id)
+ end
+ end
+
describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do
[user, user2] = insert_pair(:user)
diff --git a/test/tasks/digest_test.exs b/test/tasks/digest_test.exs
new file mode 100644
index 000000000..96d762685
--- /dev/null
+++ b/test/tasks/digest_test.exs
@@ -0,0 +1,54 @@
+defmodule Mix.Tasks.Pleroma.DigestTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ import Swoosh.TestAssertions
+
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.Web.CommonAPI
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "pleroma.digest test" do
+ test "Sends digest to the given user" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ Enum.each(0..10, fn i ->
+ {:ok, _activity} =
+ CommonAPI.post(user1, %{
+ "status" => "hey ##{i} @#{user2.nickname}!"
+ })
+ end)
+
+ yesterday =
+ NaiveDateTime.add(
+ NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
+ -60 * 60 * 24,
+ :second
+ )
+
+ {:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
+
+ :ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
+
+ ObanHelpers.perform_all()
+
+ assert_receive {:mix_shell, :info, [message]}
+ assert message =~ "Digest email have been sent"
+
+ assert_email_sent(
+ to: {user2.name, user2.email},
+ html_body: ~r/here is what you've missed!/i
+ )
+ end
+ end
+end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 9d260da3e..0d341c8d6 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -69,4 +69,27 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
assert undo_activity.data["object"] == cancelled_activity.data
end
end
+
+ describe "mix pleroma.relay list" do
+ test "Prints relay subscription list" do
+ :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
+
+ refute_receive {:mix_shell, :info, _}
+
+ Pleroma.Web.ActivityPub.Relay.get_actor()
+ |> Ecto.Changeset.change(
+ following: [
+ "http://test-app.com/user/test1",
+ "http://test-app.com/user/test1",
+ "http://test-app-42.com/user/test1"
+ ]
+ )
+ |> Pleroma.User.update_and_set_cache()
+
+ :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
+
+ assert_receive {:mix_shell, :info, ["test-app.com"]}
+ assert_receive {:mix_shell, :info, ["test-app-42.com"]}
+ end
+ end
end
diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs
index 78a3f17b4..917df2675 100644
--- a/test/tasks/robots_txt_test.exs
+++ b/test/tasks/robots_txt_test.exs
@@ -4,17 +4,17 @@
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
use ExUnit.Case
+ use Pleroma.Tests.Helpers
alias Mix.Tasks.Pleroma.RobotsTxt
+ clear_config([:instance, :static_dir])
+
test "creates new dir" do
path = "test/fixtures/new_dir/"
file_path = path <> "robots.txt"
-
- static_dir = Pleroma.Config.get([:instance, :static_dir])
Pleroma.Config.put([:instance, :static_dir], path)
on_exit(fn ->
- Pleroma.Config.put([:instance, :static_dir], static_dir)
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
end)
@@ -29,11 +29,9 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "to existance folder" do
path = "test/fixtures/"
file_path = path <> "robots.txt"
- static_dir = Pleroma.Config.get([:instance, :static_dir])
Pleroma.Config.put([:instance, :static_dir], path)
on_exit(fn ->
- Pleroma.Config.put([:instance, :static_dir], static_dir)
:ok = File.rm(file_path)
end)