From ec34de0c1fd58942c8ecefddef92696750b70420 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 16:58:38 +0300 Subject: WebSub fix test --- test/web/websub/websub_test.exs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index da7bc9112..0b8bfda2d 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -10,6 +10,18 @@ defmodule Pleroma.Web.WebsubTest do alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} import Pleroma.Factory alias Pleroma.Web.Router.Helpers + import Tesla.Mock + + setup do + mock fn + %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")} + %{method: :post, url: "http://example.org/needs_refresh"} -> + %Tesla.Env{status: 200, body: ""} + end + + :ok + end test "a verification of a request that is accepted" do sub = insert(:websub_subscription) @@ -26,8 +38,8 @@ defmodule Pleroma.Web.WebsubTest do assert String.to_integer(seconds) > 0 {:ok, - %HTTPoison.Response{ - status_code: 200, + %Tesla.Env{ + status: 200, body: challenge }} end @@ -41,8 +53,8 @@ defmodule Pleroma.Web.WebsubTest do getter = fn _path, _headers, _options -> {:ok, - %HTTPoison.Response{ - status_code: 500, + %Tesla.Env{ + status: 500, body: "" }} end @@ -113,12 +125,7 @@ defmodule Pleroma.Web.WebsubTest do test "discovers the hub and canonical url" do topic = "https://mastodon.social/users/lambadalambda.atom" - getter = fn ^topic -> - doc = File.read!("test/fixtures/lambadalambda.atom") - {:ok, %{status_code: 200, body: doc}} - end - - {:ok, discovered} = Websub.gather_feed_data(topic, getter) + {:ok, discovered} = Websub.gather_feed_data(topic) expected = %{ "hub" => "https://mastodon.social/api/push", @@ -158,7 +165,7 @@ defmodule Pleroma.Web.WebsubTest do websub.id ) - {:ok, %{status_code: 202}} + {:ok, %{status: 202}} end task = Task.async(fn -> Websub.request_subscription(websub, poster) end) @@ -209,6 +216,7 @@ defmodule Pleroma.Web.WebsubTest do insert(:websub_client_subscription, %{ valid_until: NaiveDateTime.add(now, 2 * day), topic: "http://example.org/still_good", + hub: "http://example.org/still_good", state: "accepted" }) @@ -216,6 +224,7 @@ defmodule Pleroma.Web.WebsubTest do insert(:websub_client_subscription, %{ valid_until: NaiveDateTime.add(now, day - 100), topic: "http://example.org/needs_refresh", + hub: "http://example.org/needs_refresh", state: "accepted" }) -- cgit v1.2.3 From 87109482f336422186981c80eb3c3023637f09e8 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 17:08:36 +0300 Subject: status_code -> status --- test/web/websub/websub_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 0b8bfda2d..f3d2da81a 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -184,7 +184,7 @@ defmodule Pleroma.Web.WebsubTest do websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) poster = fn ^hub, {:form, _data}, _headers -> - {:ok, %{status_code: 202}} + {:ok, %{status: 202}} end {:error, websub} = Websub.request_subscription(websub, poster, 1000) @@ -193,7 +193,7 @@ defmodule Pleroma.Web.WebsubTest do websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) poster = fn ^hub, {:form, _data}, _headers -> - {:ok, %{status_code: 400}} + {:ok, %{status: 400}} end {:error, websub} = Websub.request_subscription(websub, poster, 1000) -- cgit v1.2.3 From c508d41c349c3034211f41281cfe60c70a020575 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 18:17:26 +0300 Subject: add http requests mock --- test/web/websub/websub_test.exs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index f3d2da81a..47d1a88e1 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -13,13 +13,7 @@ defmodule Pleroma.Web.WebsubTest do import Tesla.Mock setup do - mock fn - %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} -> - %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")} - %{method: :post, url: "http://example.org/needs_refresh"} -> - %Tesla.Env{status: 200, body: ""} - end - + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) :ok end -- cgit v1.2.3