diff options
author | marcin mikołajczak <git@mkljczk.pl> | 2024-03-18 13:50:25 +0100 |
---|---|---|
committer | marcin mikołajczak <git@mkljczk.pl> | 2024-03-18 13:50:25 +0100 |
commit | 918c406a914d49b15beb3611e1c780d0e0d253cd (patch) | |
tree | f54000d2e2f19ad97c75f71f443cff6b9810f5ca /test/support/helpers.ex | |
parent | 90b442727e4e2e56b4b68a15172a5ef7516531df (diff) | |
parent | cf0aa1238ccd137219253d76355f2dc0f89679ac (diff) | |
download | pleroma-918c406a914d49b15beb3611e1c780d0e0d253cd.tar.gz pleroma-918c406a914d49b15beb3611e1c780d0e0d253cd.zip |
Merge remote-tracking branch 'origin/develop' into instance_rules
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat (limited to 'test/support/helpers.ex')
-rw-r--r-- | test/support/helpers.ex | 33 |
1 files changed, 33 insertions, 0 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 |