Fix ChatController tests validating prev/next URLs by sorting the query parameters before comparison
This commit is contained in:
parent
e7c6410192
commit
4cbf11d32c
@ -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(", ")
|
||||
|
||||
assert String.match?(
|
||||
next,
|
||||
~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$)
|
||||
)
|
||||
[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?(
|
||||
prev,
|
||||
~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
|
||||
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_url_sorted,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*&offset=\d+$)
|
||||
)
|
||||
|
||||
assert prev_rel =~ "prev"
|
||||
|
||||
assert length(result) == 10
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user