aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mix/tasks/pleroma/database_test.exs21
-rw-r--r--test/pleroma/activity_test.exs23
-rw-r--r--test/pleroma/migration_helper/object_id_test.exs15
-rw-r--r--test/pleroma/pagination_test.exs10
-rw-r--r--test/pleroma/user_test.exs20
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs7
-rw-r--r--test/pleroma/web/admin_api/controllers/report_controller_test.exs2
8 files changed, 57 insertions, 43 deletions
diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs
index 7a1a759da..d3b503a64 100644
--- a/test/mix/tasks/pleroma/database_test.exs
+++ b/test/mix/tasks/pleroma/database_test.exs
@@ -6,7 +6,6 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
use Pleroma.DataCase, async: true
use Oban.Testing, repo: Pleroma.Repo
- alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
@@ -24,26 +23,6 @@ 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)
diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs
index 4f9144f91..7d0e427fa 100644
--- a/test/pleroma/activity_test.exs
+++ b/test/pleroma/activity_test.exs
@@ -51,7 +51,8 @@ defmodule Pleroma.ActivityTest do
{:ok, bookmark3} = Bookmark.create(user3.id, activity.id)
queried_activity =
- Ecto.Query.from(Pleroma.Activity)
+ Activity
+ |> Ecto.Query.where(id: ^activity.id)
|> Activity.with_preloaded_bookmark(user3)
|> Repo.one()
@@ -64,17 +65,19 @@ defmodule Pleroma.ActivityTest do
annoyed_user = insert(:user)
{:ok, _} = ThreadMute.add_mute(annoyed_user.id, activity.data["context"])
+ query = Ecto.Query.where(Activity, id: ^activity.id)
+
activity_with_unset_thread_muted_field =
- Ecto.Query.from(Activity)
+ query
|> Repo.one()
activity_for_user =
- Ecto.Query.from(Activity)
+ query
|> Activity.with_set_thread_muted_field(user)
|> Repo.one()
activity_for_annoyed_user =
- Ecto.Query.from(Activity)
+ query
|> Activity.with_set_thread_muted_field(annoyed_user)
|> Repo.one()
@@ -90,7 +93,7 @@ defmodule Pleroma.ActivityTest do
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
queried_activity =
- Ecto.Query.from(Pleroma.Activity)
+ Ecto.Query.where(Activity, id: ^activity.id)
|> Activity.with_preloaded_bookmark(user)
|> Repo.one()
@@ -103,7 +106,7 @@ defmodule Pleroma.ActivityTest do
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
queried_activity =
- Ecto.Query.from(Pleroma.Activity)
+ Ecto.Query.where(Activity, id: ^activity.id)
|> Repo.one()
assert Activity.get_bookmark(queried_activity, user) == bookmark
@@ -266,7 +269,11 @@ defmodule Pleroma.ActivityTest do
insert(:add_activity, user: user, note: note)
insert(:add_activity, user: user)
- assert Repo.aggregate(Activity, :count, :id) == 4
+ activities_query =
+ Activity
+ |> Ecto.Query.where(fragment("data->>'type' IN ('Create', 'Add')"))
+
+ assert Repo.aggregate(activities_query, :count, :id) == 4
add_query =
Activity.add_by_params_query(note.data["object"], user.ap_id, user.featured_address)
@@ -276,6 +283,6 @@ defmodule Pleroma.ActivityTest do
Repo.delete_all(add_query)
assert Repo.aggregate(add_query, :count, :id) == 0
- assert Repo.aggregate(Activity, :count, :id) == 2
+ assert Repo.aggregate(activities_query, :count, :id) == 2
end
end
diff --git a/test/pleroma/migration_helper/object_id_test.exs b/test/pleroma/migration_helper/object_id_test.exs
new file mode 100644
index 000000000..ddd2cfbd4
--- /dev/null
+++ b/test/pleroma/migration_helper/object_id_test.exs
@@ -0,0 +1,15 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.MigrationHelper.ObjectIdTest do
+ use Pleroma.DataCase, async: true
+ alias Pleroma.MigrationHelper.ObjectId
+
+ test "flake_from_time/1" do
+ now = NaiveDateTime.utc_now()
+ id = ObjectId.flake_from_time(now)
+
+ assert FlakeId.flake_id?(id)
+ end
+end
diff --git a/test/pleroma/pagination_test.exs b/test/pleroma/pagination_test.exs
index bc26c8b46..6e5c767e6 100644
--- a/test/pleroma/pagination_test.exs
+++ b/test/pleroma/pagination_test.exs
@@ -18,7 +18,7 @@ defmodule Pleroma.PaginationTest do
end
test "paginates by min_id", %{notes: notes} do
- id = Enum.at(notes, 2).id |> Integer.to_string()
+ id = Enum.at(notes, 2).id
%{total: total, items: paginated} =
Pagination.fetch_paginated(Object, %{min_id: id, total: true})
@@ -28,7 +28,7 @@ defmodule Pleroma.PaginationTest do
end
test "paginates by since_id", %{notes: notes} do
- id = Enum.at(notes, 2).id |> Integer.to_string()
+ id = Enum.at(notes, 2).id
%{total: total, items: paginated} =
Pagination.fetch_paginated(Object, %{since_id: id, total: true})
@@ -38,7 +38,7 @@ defmodule Pleroma.PaginationTest do
end
test "paginates by max_id", %{notes: notes} do
- id = Enum.at(notes, 1).id |> Integer.to_string()
+ id = Enum.at(notes, 1).id
%{total: total, items: paginated} =
Pagination.fetch_paginated(Object, %{max_id: id, total: true})
@@ -48,7 +48,7 @@ defmodule Pleroma.PaginationTest do
end
test "paginates by min_id & limit", %{notes: notes} do
- id = Enum.at(notes, 2).id |> Integer.to_string()
+ id = Enum.at(notes, 2).id
paginated = Pagination.fetch_paginated(Object, %{min_id: id, limit: 1})
@@ -56,7 +56,7 @@ defmodule Pleroma.PaginationTest do
end
test "handles id gracefully", %{notes: notes} do
- id = Enum.at(notes, 1).id |> Integer.to_string()
+ id = Enum.at(notes, 1).id
paginated =
Pagination.fetch_paginated(Object, %{
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 0345a9290..3f31a2b26 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -19,6 +19,8 @@ defmodule Pleroma.UserTest do
import ExUnit.CaptureLog
import Swoosh.TestAssertions
+ require Ecto.Query
+
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
@@ -436,7 +438,11 @@ defmodule Pleroma.UserTest do
{:ok, registered_user} = User.register(cng)
ObanHelpers.perform_all()
- activity = Repo.one(Pleroma.Activity)
+ activity =
+ Activity
+ |> Ecto.Query.where(fragment("data->>'type' = 'Create'"))
+ |> Repo.one()
+
assert registered_user.ap_id in activity.recipients
assert Object.normalize(activity, fetch: false).data["content"] =~ "direct message"
assert activity.actor == welcome_user.ap_id
@@ -452,7 +458,11 @@ defmodule Pleroma.UserTest do
{:ok, registered_user} = User.register(cng)
ObanHelpers.perform_all()
- activity = Repo.one(Pleroma.Activity)
+ activity =
+ Activity
+ |> Ecto.Query.where(fragment("data->>'type' = 'Create'"))
+ |> Repo.one()
+
assert registered_user.ap_id in activity.recipients
assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message"
assert activity.actor == welcome_user.ap_id
@@ -491,7 +501,11 @@ defmodule Pleroma.UserTest do
{:ok, registered_user} = User.register(cng)
ObanHelpers.perform_all()
- activity = Repo.one(Pleroma.Activity)
+ activity =
+ Activity
+ |> Ecto.Query.where(fragment("data->>'type' = 'Create'"))
+ |> Repo.one()
+
assert registered_user.ap_id in activity.recipients
assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message"
assert activity.actor == welcome_user.ap_id
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
index 50315e21f..30ea6be50 100644
--- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
@@ -1143,7 +1143,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
- assert Pleroma.Repo.aggregate(Activity, :count, :id) == 2
+ assert Pleroma.Repo.aggregate(Object, :count, :id) == 4
ObanHelpers.perform_all()
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 574ef0d71..7313ed42e 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -1394,8 +1394,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
ActivityPub.fetch_activities([user1.ap_id | User.following(user1)], %{user: user1})
|> Enum.map(fn a -> a.id end)
- assert [public_activity.id, private_activity_1.id] == activities
- assert length(activities) == 2
+ assert [public_activity.id, private_activity_1.id, private_activity_3.id] == activities
+ assert length(activities) == 3
end
end
@@ -1514,8 +1514,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
content: content
})
- assert Repo.aggregate(Activity, :count, :id) == 1
- assert Repo.aggregate(Object, :count, :id) == 2
+ assert Repo.aggregate(Object, :count, :id) == 3
assert Repo.aggregate(Notification, :count, :id) == 0
end
end
diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
index 99cc7bbd0..e480a0118 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
@@ -363,7 +363,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
[note, _] = notes
assert note["user"]["nickname"] == admin.nickname
- assert note["content"] == "this is disgusting!"
+ assert note["content"] =~ "this is disgusting"
assert note["created_at"]
assert response["total"] == 1
end