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 defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
5 use Pleroma.Web.ConnCase, async: true
11 describe "POST /api/v1/pleroma/chats/by-ap-id/:id" do
12 test "it creates or returns a chat", %{conn: conn} do
14 other_user = insert(:user)
18 |> assign(:user, user)
19 |> post("/api/v1/pleroma/chats/by-ap-id/#{URI.encode_www_form(other_user.ap_id)}")
26 describe "GET /api/v1/pleroma/chats" do
27 test "it return a list of chats the current user is participating in, in descending order of updates",
31 jafnhar = insert(:user)
34 {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
36 {:ok, _chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
38 {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
42 {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
46 |> assign(:user, user)
47 |> get("/api/v1/pleroma/chats")
50 ids = Enum.map(result, & &1["id"])
52 assert ids == [chat_2.id, chat_3.id, chat_1.id]