aboutsummaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/captcha_mock.ex6
-rw-r--r--test/support/conn_case.ex26
-rw-r--r--test/support/factory.ex1
-rw-r--r--test/support/http_request_mock.ex16
4 files changed, 44 insertions, 5 deletions
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 6dae94edf..7b0c1d5af 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -6,12 +6,16 @@ defmodule Pleroma.Captcha.Mock do
alias Pleroma.Captcha.Service
@behaviour Service
+ @solution "63615261b77f5354fb8c4e4986477555"
+
+ def solution, do: @solution
+
@impl Service
def new,
do: %{
type: :mock,
token: "afa1815e14e29355e6c8f6b143a39fa2",
- answer_data: "63615261b77f5354fb8c4e4986477555",
+ answer_data: @solution,
url: "https://example.org/captcha.png"
}
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 781622476..fa30a0c41 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -51,7 +51,19 @@ defmodule Pleroma.Web.ConnCase do
%{user: user, token: token, conn: conn}
end
- defp json_response_and_validate_schema(conn, status \\ nil) do
+ defp request_content_type(%{conn: conn}) do
+ conn = put_req_header(conn, "content-type", "multipart/form-data")
+ [conn: conn]
+ end
+
+ defp json_response_and_validate_schema(
+ %{
+ private: %{
+ open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}
+ }
+ } = conn,
+ status
+ ) do
content_type =
conn
|> Plug.Conn.get_resp_header("content-type")
@@ -59,10 +71,12 @@ defmodule Pleroma.Web.ConnCase do
|> String.split(";")
|> List.first()
- status = status || conn.status
+ status = Plug.Conn.Status.code(status)
- %{private: %{open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}}} =
- conn
+ unless lookup[op_id].responses[status] do
+ err = "Response schema not found for #{conn.status} #{conn.method} #{conn.request_path}"
+ flunk(err)
+ end
schema = lookup[op_id].responses[status].content[content_type].schema
json = json_response(conn, status)
@@ -87,6 +101,10 @@ defmodule Pleroma.Web.ConnCase do
end
end
+ defp json_response_and_validate_schema(conn, _status) do
+ flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")
+ end
+
defp ensure_federating_or_authenticated(conn, url, user) do
initial_setting = Config.get([:instance, :federating])
on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)
diff --git a/test/support/factory.ex b/test/support/factory.ex
index f0b797fd4..495764782 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -32,6 +32,7 @@ defmodule Pleroma.Factory do
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"),
last_digest_emailed_at: NaiveDateTime.utc_now(),
+ last_refreshed_at: NaiveDateTime.utc_now(),
notification_settings: %Pleroma.User.NotificationSetting{}
}
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 20cb2b3d1..9624cb0f7 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -308,6 +308,22 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://peertube.social/accounts/craigmaloney", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/craigmaloney.json")
+ }}
+ end
+
+ def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/peertube-social.json")
+ }}
+ end
+
def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
{"accept", "application/activity+json"}
]) do