diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/repo/migrations/publisher_migration_change_test.exs | 43 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/publisher_test.exs | 76 | ||||
-rw-r--r-- | test/pleroma/web/common_api_test.exs | 32 |
3 files changed, 96 insertions, 55 deletions
diff --git a/test/pleroma/repo/migrations/publisher_migration_change_test.exs b/test/pleroma/repo/migrations/publisher_migration_change_test.exs new file mode 100644 index 000000000..9c035e604 --- /dev/null +++ b/test/pleroma/repo/migrations/publisher_migration_change_test.exs @@ -0,0 +1,43 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.PublisherMigrationChangeTest do + use Oban.Testing, repo: Pleroma.Repo + use Pleroma.DataCase + import Pleroma.Factory + import Pleroma.Tests.Helpers + + alias Pleroma.Activity + alias Pleroma.Workers.PublisherWorker + + setup_all do: require_migration("20240729163838_publisher_job_change") + + describe "up/0" do + test "migrates publisher jobs to new format", %{migration: migration} do + user = insert(:user) + + %Activity{id: activity_id, data: %{"id" => ap_id}} = + insert(:note_activity, user: user) + + {:ok, %{id: job_id}} = + PublisherWorker.new(%{ + "actor_id" => user.id, + "json" => "{}", + "id" => ap_id, + "inbox" => "https://example.com/inbox", + "unreachable_since" => nil + }) + |> Oban.insert() + + assert [%{id: ^job_id, args: %{"id" => ^ap_id}}] = all_enqueued(worker: PublisherWorker) + + assert migration.up() == :ok + + assert_enqueued( + worker: PublisherWorker, + args: %{"id" => ap_id, "activity_id" => activity_id} + ) + end + end +end diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 6f48a0227..569b6af1a 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -137,6 +137,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do test "publish to url with with different ports" do inbox80 = "http://42.site/users/nick1/inbox" inbox42 = "http://42.site:42/users/nick1/inbox" + activity = insert(:note_activity) mock(fn %{method: :post, url: "http://42.site:42/users/nick1/inbox"} -> @@ -146,23 +147,19 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do {:ok, %Tesla.Env{status: 200, body: "port 80"}} end) - actor = insert(:user) + _actor = insert(:user) assert {:ok, %{body: "port 42"}} = Publisher.publish_one(%{ inbox: inbox42, - json: "{}", - actor: actor, - id: 1, + activity_id: activity.id, unreachable_since: true }) assert {:ok, %{body: "port 80"}} = Publisher.publish_one(%{ inbox: inbox80, - json: "{}", - actor: actor, - id: 1, + activity_id: activity.id, unreachable_since: true }) end @@ -171,10 +168,13 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://200.site/users/nick1/inbox" + activity = insert(:note_activity) + + assert {:ok, _} = + Publisher.publish_one(%{inbox: inbox, activity_id: activity.id}) - assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert called(Instances.set_reachable(inbox)) end @@ -182,15 +182,14 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://200.site/users/nick1/inbox" + activity = insert(:note_activity) assert {:ok, _} = Publisher.publish_one(%{ inbox: inbox, - json: "{}", - actor: actor, - id: 1, + activity_id: activity.id, unreachable_since: NaiveDateTime.utc_now() }) @@ -201,15 +200,14 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://200.site/users/nick1/inbox" + activity = insert(:note_activity) assert {:ok, _} = Publisher.publish_one(%{ inbox: inbox, - json: "{}", - actor: actor, - id: 1, + activity_id: activity.id, unreachable_since: nil }) @@ -220,11 +218,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://404.site/users/nick1/inbox" + activity = insert(:note_activity) assert {:cancel, _} = - Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) + Publisher.publish_one(%{inbox: inbox, activity_id: activity.id}) assert called(Instances.set_unreachable(inbox)) end @@ -233,12 +232,16 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://connrefused.site/users/nick1/inbox" + activity = insert(:note_activity) assert capture_log(fn -> assert {:error, _} = - Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) + Publisher.publish_one(%{ + inbox: inbox, + activity_id: activity.id + }) end) =~ "connrefused" assert called(Instances.set_unreachable(inbox)) @@ -248,10 +251,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://200.site/users/nick1/inbox" + activity = insert(:note_activity) - assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) + assert {:ok, _} = + Publisher.publish_one(%{inbox: inbox, activity_id: activity.id}) refute called(Instances.set_unreachable(inbox)) end @@ -260,16 +265,15 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) + _actor = insert(:user) inbox = "http://connrefused.site/users/nick1/inbox" + activity = insert(:note_activity) assert capture_log(fn -> assert {:error, _} = Publisher.publish_one(%{ inbox: inbox, - json: "{}", - actor: actor, - id: 1, + activity_id: activity.id, unreachable_since: NaiveDateTime.utc_now() }) end) =~ "connrefused" @@ -309,8 +313,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do assert not called( Publisher.enqueue_one(%{ inbox: "https://domain.com/users/nick1/inbox", - actor_id: actor.id, - id: note_activity.data["id"] + activity_id: note_activity.id }) ) end @@ -346,8 +349,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Publisher.enqueue_one( %{ inbox: "https://domain.com/users/nick1/inbox", - actor_id: actor.id, - id: note_activity.data["id"] + activity_id: note_activity.id }, priority: 1 ) @@ -370,8 +372,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Publisher.enqueue_one( %{ inbox: :_, - actor_id: actor.id, - id: note_activity.data["id"] + activity_id: note_activity.id }, priority: 0 ) @@ -405,8 +406,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do assert called( Publisher.enqueue_one(%{ inbox: "https://domain.com/users/nick1/inbox", - actor_id: actor.id, - id: note_activity.data["id"] + activity_id: note_activity.id }) ) end @@ -456,8 +456,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Publisher.enqueue_one( %{ inbox: "https://domain.com/users/nick1/inbox", - actor_id: actor.id, - id: delete.data["id"] + activity_id: delete.id }, priority: 1 ) @@ -467,8 +466,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Publisher.enqueue_one( %{ inbox: "https://domain2.com/users/nick1/inbox", - actor_id: actor.id, - id: delete.data["id"] + activity_id: delete.id }, priority: 1 ) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index b6fba6999..4cdd3cffa 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1957,7 +1957,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user) - {:ok, %{data: %{"id" => ap_id}} = activity} = + {:ok, %{id: activity_id} = _activity} = CommonAPI.post(local_user, %{status: "Happy Friday everyone!"}) # Generate the publish_one jobs @@ -1971,7 +1971,7 @@ defmodule Pleroma.Web.CommonAPITest do state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^activity_id}} }, job ) @@ -1980,7 +1980,7 @@ defmodule Pleroma.Web.CommonAPITest do assert length(publish_one_jobs) == 2 # The delete should have triggered cancelling the publish_one jobs - assert {:ok, _delete} = CommonAPI.delete(activity.id, local_user) + assert {:ok, _delete} = CommonAPI.delete(activity_id, local_user) # all_enqueued/1 will not return cancelled jobs cancelled_jobs = @@ -1988,7 +1988,7 @@ defmodule Pleroma.Web.CommonAPITest do |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^activity_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2 @@ -2001,7 +2001,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(remote_user, %{status: "I like turtles!"}) - {:ok, %{data: %{"id" => ap_id}} = _favorite} = + {:ok, %{id: favorite_id} = _favorite} = CommonAPI.favorite(activity.id, local_user) # Generate the publish_one jobs @@ -2015,7 +2015,7 @@ defmodule Pleroma.Web.CommonAPITest do state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^favorite_id}} }, job ) @@ -2032,7 +2032,7 @@ defmodule Pleroma.Web.CommonAPITest do |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^favorite_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 1 @@ -2049,7 +2049,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(remote_one, %{status: "This is an unpleasant post"}) - {:ok, %{data: %{"id" => ap_id}} = _repeat} = + {:ok, %{id: repeat_id} = _repeat} = CommonAPI.repeat(activity.id, local_user) # Generate the publish_one jobs @@ -2063,7 +2063,7 @@ defmodule Pleroma.Web.CommonAPITest do state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^repeat_id}} }, job ) @@ -2080,7 +2080,7 @@ defmodule Pleroma.Web.CommonAPITest do |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^repeat_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2 @@ -2094,11 +2094,11 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user) - {:ok, activity} = + {:ok, %{id: activity_id}} = CommonAPI.post(remote_one, %{status: "Gang gang!!!!"}) - {:ok, %{data: %{"id" => ap_id}} = _react} = - CommonAPI.react_with_emoji(activity.id, local_user, "👍") + {:ok, %{id: react_id} = _react} = + CommonAPI.react_with_emoji(activity_id, local_user, "👍") # Generate the publish_one jobs ObanHelpers.perform_all() @@ -2111,7 +2111,7 @@ defmodule Pleroma.Web.CommonAPITest do state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^react_id}} }, job ) @@ -2120,7 +2120,7 @@ defmodule Pleroma.Web.CommonAPITest do assert length(publish_one_jobs) == 2 # The unreact should have triggered cancelling the publish_one jobs - assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity.id, local_user, "👍") + assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity_id, local_user, "👍") # all_enqueued/1 will not return cancelled jobs cancelled_jobs = @@ -2128,7 +2128,7 @@ defmodule Pleroma.Web.CommonAPITest do |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^react_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2 |