aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/web/websub/websub_controller_test.exs8
-rw-r--r--test/web/websub/websub_test.exs48
2 files changed, 47 insertions, 9 deletions
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 584db0a19..9a0a5c61b 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -1,8 +1,6 @@
defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.Repo
- alias Pleroma.Web.Websub.WebsubServerSubscription
test "websub subscription request", %{conn: conn} do
user = insert(:user)
@@ -21,11 +19,5 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
|> post(path, data)
assert response(conn, 202) == "Accepted"
- subscription = Repo.one!(WebsubServerSubscription)
- assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
- assert subscription.state == "requested"
- assert subscription.secret == "a random secret"
- assert subscription.callback == "http://example.org/sub"
- assert subscription.valid_until == NaiveDateTime.add(subscription.inserted_at, 100)
end
end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 36ea82299..5fe91d0f8 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -1,6 +1,12 @@
+defmodule Pleroma.Web.WebsubMock do
+ def verify(sub) do
+ {:ok, sub}
+ end
+end
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
alias Pleroma.Web.Websub
+ alias Pleroma.Web.Websub.WebsubServerSubscription
import Pleroma.Factory
test "a verification of a request that is accepted" do
@@ -29,7 +35,6 @@ defmodule Pleroma.Web.WebsubTest do
test "a verification of a request that doesn't return 200" do
sub = insert(:websub_subscription)
- topic = sub.topic
getter = fn (_path, _headers, _options) ->
{:ok, %HTTPoison.Response{
@@ -41,4 +46,45 @@ defmodule Pleroma.Web.WebsubTest do
{:error, sub} = Websub.verify(sub, getter)
assert sub.state == "rejected"
end
+
+ test "an incoming subscription request" do
+ user = insert(:user)
+
+ data = %{
+ "hub.callback" => "http://example.org/sub",
+ "hub.mode" => "subscription",
+ "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
+ "hub.secret" => "a random secret",
+ "hub.lease_seconds" => "100"
+ }
+
+
+ {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
+ assert subscription.state == "requested"
+ assert subscription.secret == "a random secret"
+ assert subscription.callback == "http://example.org/sub"
+ end
+
+ test "an incoming subscription request for an existing subscription" do
+ user = insert(:user)
+ sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
+
+ data = %{
+ "hub.callback" => sub.callback,
+ "hub.mode" => "subscription",
+ "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
+ "hub.secret" => "a random secret",
+ "hub.lease_seconds" => "100"
+ }
+
+
+ {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
+ assert subscription.state == sub.state
+ assert subscription.secret == "a random secret"
+ assert subscription.callback == sub.callback
+ assert length(Repo.all(WebsubServerSubscription)) == 1
+ assert subscription.id == sub.id
+ end
end