|
|
|
@ -304,7 +304,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET /api/v1/pleroma/chats" do
|
|
|
|
|
for tested_endpoint <- ["/api/v1/pleroma/chats", "/api/v2/pleroma/chats"] do
|
|
|
|
|
describe "GET #{tested_endpoint}" do
|
|
|
|
|
setup do: oauth_access(["read:chats"])
|
|
|
|
|
|
|
|
|
|
test "it does not return chats with deleted users", %{conn: conn, user: user} do
|
|
|
|
@ -316,7 +317,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 0
|
|
|
|
@ -329,7 +330,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 1
|
|
|
|
@ -338,7 +339,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 0
|
|
|
|
@ -351,7 +352,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 1
|
|
|
|
@ -360,19 +361,20 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 0
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats?with_muted=true")
|
|
|
|
|
|> get("#{unquote(tested_endpoint)}?with_muted=true")
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if tested_endpoint == "/api/v1/pleroma/chats" do
|
|
|
|
|
test "it returns all chats", %{conn: conn, user: user} do
|
|
|
|
|
Enum.each(1..30, fn _ ->
|
|
|
|
|
recipient = insert(:user)
|
|
|
|
@ -381,11 +383,34 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 30
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
test "it paginates chats", %{conn: conn, user: user} do
|
|
|
|
|
Enum.each(1..30, fn _ ->
|
|
|
|
|
recipient = insert(:user)
|
|
|
|
|
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 20
|
|
|
|
|
last_id = List.last(result)["id"]
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get(unquote(tested_endpoint) <> "?max_id=#{last_id}")
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
assert length(result) == 10
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "it return a list of chats the current user is participating in, in descending order of updates",
|
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
@ -405,7 +430,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
ids = Enum.map(result, & &1["id"])
|
|
|
|
@ -432,7 +457,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
|
conn
|
|
|
|
|
|> get("/api/v1/pleroma/chats")
|
|
|
|
|
|> get(unquote(tested_endpoint))
|
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
|
|
account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
|
|
|
|
@ -440,3 +465,4 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|