summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-01-15 17:12:06 -0500
committerMark Felder <feld@feld.me>2024-01-15 17:12:06 -0500
commit4cbf11d32c9c37f3175e4d7bab04be64a9fe27d4 (patch)
treed886c68da497aa7ea0d41e41f072516344b3c10f /test
parente7c6410192cfb115246acd4f9bf80f0c42aece90 (diff)
Fix ChatController tests validating prev/next URLs by sorting the query parameters before comparison
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs47
1 files changed, 38 insertions, 9 deletions
diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
index e17d9d7cb..0d3452559 100644
--- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
alias Pleroma.Chat
alias Pleroma.Chat.MessageReference
alias Pleroma.Object
+ alias Pleroma.Tests.Helpers
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -212,18 +213,32 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
result = json_response_and_validate_schema(response, 200)
[next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ")
- api_endpoint = "/api/v1/pleroma/chats/"
+ api_endpoint = Pleroma.Web.Endpoint.url() <> "/api/v1/pleroma/chats/"
+
+ [next_url, next_rel] = String.split(next, ";")
+ next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<")
+
+ next_url_sorted = Helpers.uri_query_sort(next_url)
assert String.match?(
- next,
- ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$)
+ next_url_sorted,
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$)
)
+ assert next_rel =~ "next"
+
+ [prev_url, prev_rel] = String.split(prev, ";")
+ prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<")
+
+ prev_url_sorted = Helpers.uri_query_sort(prev_url)
+
assert String.match?(
- prev,
- ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&min_id=.*; rel=\"prev\"$)
+ prev_url_sorted,
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*&offset=\d+$)
)
+ assert prev_rel =~ "prev"
+
assert length(result) == 20
response = get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}")
@@ -231,16 +246,30 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
result = json_response_and_validate_schema(response, 200)
[next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ")
+ [next_url, next_rel] = String.split(next, ";")
+ next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<")
+
+ next_url_sorted = Helpers.uri_query_sort(next_url)
+
assert String.match?(
- next,
- ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$)
+ next_url_sorted,
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$)
)
+ assert next_rel =~ "next"
+
+ [prev_url, prev_rel] = String.split(prev, ";")
+ prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<")
+
+ prev_url_sorted = Helpers.uri_query_sort(prev_url)
+
assert String.match?(
- prev,
- ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
+ prev_url_sorted,
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*&offset=\d+$)
)
+ assert prev_rel =~ "prev"
+
assert length(result) == 10
end