Merge branch 'tests/database-digest-tests' into 'develop'

Add more tests for Database tasks and DigestEmailWorker

See merge request pleroma/pleroma!1577
This commit is contained in:
lain 2019-08-19 16:10:00 +00:00
commit e5d2c0c669
4 changed files with 82 additions and 0 deletions

View File

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.DigestEmailWorker do defmodule Pleroma.DigestEmailWorker do
import Ecto.Query import Ecto.Query

View File

@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do defmodule Mix.Tasks.Pleroma.DatabaseTest do
alias Pleroma.Activity
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
@ -22,6 +23,52 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
:ok :ok
end 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 describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do test "following and followers count are updated" do
[user, user2] = insert_pair(:user) [user, user2] = insert_pair(:user)

View File

@ -0,0 +1,31 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.DigestEmailWorkerTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.DigestEmailWorker
alias Pleroma.User
alias Pleroma.Web.CommonAPI
test "it sends digest emails" do
user = insert(:user)
date =
Timex.now()
|> Timex.shift(days: -10)
|> Timex.to_naive_datetime()
user2 = insert(:user, last_digest_emailed_at: date)
User.switch_email_notifications(user2, "digest", true)
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
DigestEmailWorker.perform()
assert_received {:email, email}
assert email.to == [{user2.name, user2.email}]
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
end
end