diff options
author | marcin mikołajczak <me@mkljczk.pl> | 2024-01-19 16:36:37 +0000 |
---|---|---|
committer | marcin mikołajczak <me@mkljczk.pl> | 2024-01-19 16:36:37 +0000 |
commit | 250a4873a6f50f71cb5c387de46d711dc1bd1a39 (patch) | |
tree | 15364aea4ca2ad364517099f090716de0900b8ef /test/support | |
parent | 51aef6b78dcf709872de32a02533e943f08858d4 (diff) | |
parent | 81a13b4b9eb066e7827251c054eb04fd70613532 (diff) | |
download | pleroma-250a4873a6f50f71cb5c387de46d711dc1bd1a39.tar.gz pleroma-250a4873a6f50f71cb5c387de46d711dc1bd1a39.zip |
Merge branch 'develop' into 'post-languages'
# Conflicts:
# lib/pleroma/web/activity_pub/transmogrifier.ex
# test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs
Diffstat (limited to 'test/support')
-rw-r--r-- | test/support/helpers.ex | 33 | ||||
-rw-r--r-- | test/support/http_request_mock.ex | 4 |
2 files changed, 35 insertions, 2 deletions
diff --git a/test/support/helpers.ex b/test/support/helpers.ex index e3bfa73d2..7fa6c31a4 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -10,6 +10,39 @@ defmodule Pleroma.Tests.Helpers do require Logger + @doc "Accepts two URLs/URIs and sorts the query parameters before comparing" + def uri_equal?(a, b) do + a_sorted = uri_query_sort(a) + b_sorted = uri_query_sort(b) + + match?(^a_sorted, b_sorted) + end + + @doc "Accepts a URL/URI and sorts the query parameters" + def uri_query_sort(uri) do + parsed = URI.parse(uri) + + sorted_query = + String.split(parsed.query, "&") + |> Enum.sort() + |> Enum.join("&") + + parsed + |> Map.put(:query, sorted_query) + |> URI.to_string() + end + + @doc "Returns the value of the specified query parameter for the provided URL" + def get_query_parameter(url, param) do + url + |> URI.parse() + |> Map.get(:query) + |> URI.query_decoder() + |> Enum.to_list() + |> Enum.into(%{}, fn {x, y} -> {x, y} end) + |> Map.get(param) + end + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 11cc2eb94..f76128312 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -178,7 +178,7 @@ defmodule HttpRequestMock do end def get( - "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la", + "https://social.heldscal.la/.well-known/webfinger?resource=nonexistent@social.heldscal.la", _, _, [{"accept", "application/xrd+xml,application/jrd+json"}] @@ -186,7 +186,7 @@ defmodule HttpRequestMock do {:ok, %Tesla.Env{ status: 200, - body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml") + body: File.read!("test/fixtures/tesla_mock/nonexistent@social.heldscal.la.xml") }} end |