AdminAPI: list messages in a chat
This commit is contained in:
parent
c41430b23e
commit
f13b52a703
4 changed files with 107 additions and 2 deletions
|
|
@ -8,9 +8,11 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
|
@ -50,4 +52,56 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
|
|||
assert json_response_and_validate_schema(conn, :not_found) == %{"error" => "Not found"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/chats/:id/messages" do
|
||||
test "it paginates", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
Enum.each(1..30, fn _ ->
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, recipient, "hey")
|
||||
end)
|
||||
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 20
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages?max_id=#{List.last(result)["id"]}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 10
|
||||
end
|
||||
|
||||
test "it returns the messages for a given chat", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, other_user, "hey")
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, third_user, "hey")
|
||||
{:ok, _} = CommonAPI.post_chat_message(user, other_user, "how are you?")
|
||||
{:ok, _} = CommonAPI.post_chat_message(other_user, user, "fine, how about you?")
|
||||
|
||||
chat = Chat.get(user.id, other_user.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/chats/#{chat.id}/messages")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
result
|
||||
|> Enum.each(fn message ->
|
||||
assert message["chat_id"] == chat.id |> to_string()
|
||||
end)
|
||||
|
||||
assert length(result) == 3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue