1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ChatTest do
6 use Pleroma.DataCase, async: true
10 import Pleroma.Factory
12 describe "creation and getting" do
13 test "it only works if the recipient is a valid user (for now)" do
16 assert {:error, _chat} = Chat.bump_or_create(user.id, "http://some/nonexisting/account")
17 assert {:error, _chat} = Chat.get_or_create(user.id, "http://some/nonexisting/account")
20 test "it creates a chat for a user and recipient" do
22 other_user = insert(:user)
24 {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
29 test "it returns a chat for a user and recipient if it already exists" do
31 other_user = insert(:user)
33 {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
34 {:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
36 assert chat.id == chat_two.id
39 test "a returning chat will have an updated `update_at` field and an incremented unread count" do
41 other_user = insert(:user)
43 {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
44 assert chat.unread == 1
46 {:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
47 assert chat_two.unread == 2
49 assert chat.id == chat_two.id
50 assert chat.updated_at != chat_two.updated_at