Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8KB

  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.ChatTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.Chat
  7. import Pleroma.Factory
  8. describe "creation and getting" do
  9. test "it only works if the recipient is a valid user (for now)" do
  10. user = insert(:user)
  11. assert {:error, _chat} = Chat.bump_or_create(user.id, "http://some/nonexisting/account")
  12. assert {:error, _chat} = Chat.get_or_create(user.id, "http://some/nonexisting/account")
  13. end
  14. test "it creates a chat for a user and recipient" do
  15. user = insert(:user)
  16. other_user = insert(:user)
  17. {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
  18. assert chat.id
  19. end
  20. test "it returns and bumps a chat for a user and recipient if it already exists" do
  21. user = insert(:user)
  22. other_user = insert(:user)
  23. {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
  24. {:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
  25. assert chat.id == chat_two.id
  26. end
  27. test "it returns a chat for a user and recipient if it already exists" do
  28. user = insert(:user)
  29. other_user = insert(:user)
  30. {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
  31. {:ok, chat_two} = Chat.get_or_create(user.id, other_user.ap_id)
  32. assert chat.id == chat_two.id
  33. end
  34. test "a returning chat will have an updated `update_at` field" do
  35. user = insert(:user)
  36. other_user = insert(:user)
  37. {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
  38. :timer.sleep(1500)
  39. {:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
  40. assert chat.id == chat_two.id
  41. assert chat.updated_at != chat_two.updated_at
  42. end
  43. end
  44. end