ChatMessages: Fix pagination headers.

They used to contain the path parameter `id` as query param,
which would break the link.
This commit is contained in:
lain 2021-01-11 15:30:40 +01:00
parent be7a76abc0
commit e1a547d7d3
2 changed files with 5 additions and 5 deletions

View file

@ -67,7 +67,7 @@ def add_link_headers(conn, entries, extra_params) do
defp build_pagination_fields(conn, min_id, max_id, extra_params) do defp build_pagination_fields(conn, min_id, max_id, extra_params) do
params = params =
conn.params conn.params
|> Map.drop(Map.keys(conn.path_params)) |> Map.drop(Map.keys(conn.path_params) |> Enum.map(&String.to_atom/1))
|> Map.merge(extra_params) |> Map.merge(extra_params)
|> Map.drop(@id_keys) |> Map.drop(@id_keys)

View file

@ -211,12 +211,12 @@ test "it paginates", %{conn: conn, user: user} do
assert String.match?( assert String.match?(
next, next,
~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$) ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
) )
assert String.match?( assert String.match?(
prev, prev,
~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&min_id=.*; rel=\"prev\"$) ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*; rel=\"prev\"$)
) )
assert length(result) == 20 assert length(result) == 20
@ -229,12 +229,12 @@ test "it paginates", %{conn: conn, user: user} do
assert String.match?( assert String.match?(
next, next,
~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$) ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
) )
assert String.match?( assert String.match?(
prev, prev,
~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$) ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
) )
assert length(result) == 10 assert length(result) == 10