Chats: Add API specs.
This commit is contained in:
parent
a185b5455f
commit
97ad0c4597
7 changed files with 346 additions and 33 deletions
|
|
@ -5,8 +5,14 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Web.ApiSpec
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ChatResponse
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ChatsResponse
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ChatMessagesResponse
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import OpenApiSpex.TestAssertions
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "POST /api/v1/pleroma/chats/:id/messages" do
|
||||
|
|
@ -24,6 +30,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|
||||
assert result["content"] == "Hallo!!"
|
||||
assert result["chat_id"] == chat.id |> to_string()
|
||||
assert_schema(result, "ChatMessageResponse", ApiSpec.spec())
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -45,6 +52,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert length(result) == 20
|
||||
assert_schema(result, "ChatMessagesResponse", ApiSpec.spec())
|
||||
|
||||
result =
|
||||
conn
|
||||
|
|
@ -52,6 +60,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert length(result) == 10
|
||||
assert_schema(result, "ChatMessagesResponse", ApiSpec.spec())
|
||||
end
|
||||
|
||||
test "it returns the messages for a given chat", %{conn: conn, user: user} do
|
||||
|
|
@ -76,6 +85,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
end)
|
||||
|
||||
assert length(result) == 3
|
||||
assert_schema(result, "ChatMessagesResponse", ApiSpec.spec())
|
||||
|
||||
# Trying to get the chat of a different user
|
||||
result =
|
||||
|
|
@ -99,6 +109,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert result["id"]
|
||||
assert_schema(result, "ChatResponse", ApiSpec.spec())
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -117,6 +128,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert length(result) == 20
|
||||
assert_schema(result, "ChatsResponse", ApiSpec.spec())
|
||||
|
||||
result =
|
||||
conn
|
||||
|
|
@ -124,6 +136,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert length(result) == 10
|
||||
|
||||
assert_schema(result, "ChatsResponse", ApiSpec.spec())
|
||||
end
|
||||
|
||||
test "it return a list of chats the current user is participating in, in descending order of updates",
|
||||
|
|
@ -154,6 +168,34 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
chat_3.id |> to_string(),
|
||||
chat_1.id |> to_string()
|
||||
]
|
||||
|
||||
assert_schema(result, "ChatsResponse", ApiSpec.spec())
|
||||
end
|
||||
end
|
||||
|
||||
describe "schemas" do
|
||||
test "Chat example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = ChatResponse.schema()
|
||||
assert_schema(schema.example, "ChatResponse", api_spec)
|
||||
end
|
||||
|
||||
test "Chats example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = ChatsResponse.schema()
|
||||
assert_schema(schema.example, "ChatsResponse", api_spec)
|
||||
end
|
||||
|
||||
test "ChatMessage example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = ChatMessageResponse.schema()
|
||||
assert_schema(schema.example, "ChatMessageResponse", api_spec)
|
||||
end
|
||||
|
||||
test "ChatsMessage example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = ChatMessagesResponse.schema()
|
||||
assert_schema(schema.example, "ChatMessagesResponse", api_spec)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue