Chat API: Align more to Pleroma/Mastodon API.
[akkoma] / test / web / pleroma_api / views / chat_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Chat
9 alias Pleroma.Web.MastodonAPI.AccountView
10 alias Pleroma.Web.PleromaAPI.ChatView
11
12 import Pleroma.Factory
13
14 test "it represents a chat" do
15 user = insert(:user)
16 recipient = insert(:user)
17
18 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
19
20 represented_chat = ChatView.render("show.json", chat: chat)
21
22 assert represented_chat == %{
23 id: "#{chat.id}",
24 account: AccountView.render("show.json", user: recipient),
25 unread: 0
26 }
27 end
28 end