Test Relay, switch to runtime configuration.
This commit is contained in:
parent
e6ec01afb6
commit
1e9ced5af4
6 changed files with 99 additions and 8 deletions
|
|
@ -4,6 +4,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
|
||||
alias Pleroma.{Repo, User}
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
|
||||
describe "/relay" do
|
||||
test "with the relay active, it returns the relay user", %{conn: conn} do
|
||||
Config.put([:instance, :allow_relay], true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(activity_pub_path(conn, :relay))
|
||||
|> json_response(200)
|
||||
|
||||
assert res["id"] =~ "/relay"
|
||||
end
|
||||
|
||||
test "with the relay disabled, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :allow_relay], false)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(activity_pub_path(conn, :relay))
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname" do
|
||||
test "it returns a json representation of the user", %{conn: conn} do
|
||||
|
|
|
|||
11
test/web/activity_pub/relay_test.exs
Normal file
11
test/web/activity_pub/relay_test.exs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
defmodule Pleroma.Web.ActivityPub.RelayTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
test "gets an actor for the relay" do
|
||||
user = Relay.get_actor()
|
||||
|
||||
assert user.ap_id =~ "/relay"
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
defmodule Pleroma.Web.FederatorTest do
|
||||
alias Pleroma.Web.Federator
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Config
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
test "enqueues an element according to priority" do
|
||||
queue = [%{item: 1, priority: 2}]
|
||||
|
|
@ -17,4 +21,45 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
|
||||
end
|
||||
|
||||
describe "Publish an activity" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
|
||||
|
||||
relay_mock = {
|
||||
Pleroma.Web.ActivityPub.Relay,
|
||||
[],
|
||||
[publish: fn _activity -> send(self(), :relay_publish) end]
|
||||
}
|
||||
|
||||
%{activity: activity, relay_mock: relay_mock}
|
||||
end
|
||||
|
||||
test "with relays active, it publishes to the relay", %{
|
||||
activity: activity,
|
||||
relay_mock: relay_mock
|
||||
} do
|
||||
Config.put([:instance, :allow_relay], true)
|
||||
|
||||
with_mocks([relay_mock]) do
|
||||
Federator.handle(:publish, activity)
|
||||
end
|
||||
|
||||
assert_received :relay_publish
|
||||
end
|
||||
|
||||
test "with relays deactivated, it does not publish to the relay", %{
|
||||
activity: activity,
|
||||
relay_mock: relay_mock
|
||||
} do
|
||||
Config.put([:instance, :allow_relay], false)
|
||||
|
||||
with_mocks([relay_mock]) do
|
||||
Federator.handle(:publish, activity)
|
||||
end
|
||||
|
||||
refute_received :relay_publish
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue