aboutsummaryrefslogtreecommitdiff
path: root/test/web/matrix_controller_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/matrix_controller_test.exs')
-rw-r--r--test/web/matrix_controller_test.exs143
1 files changed, 0 insertions, 143 deletions
diff --git a/test/web/matrix_controller_test.exs b/test/web/matrix_controller_test.exs
deleted file mode 100644
index c8273641b..000000000
--- a/test/web/matrix_controller_test.exs
+++ /dev/null
@@ -1,143 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MatrixControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Chat
- alias Pleroma.Chat.MessageReference
- alias Pleroma.Object
- import Pleroma.Factory
-
- setup do
- %{user: user, conn: conn} = oauth_access(["read"])
- other_user = insert(:user)
- third_user = insert(:user)
-
- {:ok, chat_activity} = CommonAPI.post_chat_message(user, other_user, "Hey")
- {:ok, chat_activity_two} = CommonAPI.post_chat_message(third_user, user, "Henlo")
-
- chat = Chat.get(user.id, other_user.ap_id)
- chat_two = Chat.get(user.id, third_user.ap_id)
-
- chat_object = Object.normalize(chat_activity)
- cmr = MessageReference.for_chat_and_object(chat, chat_object)
-
- chat_object_two = Object.normalize(chat_activity_two)
- cmr_two = MessageReference.for_chat_and_object(chat_two, chat_object_two)
-
- %{
- user: user,
- other_user: other_user,
- third_user: third_user,
- conn: conn,
- chat_activity: chat_activity,
- chat_activity_two: chat_activity_two,
- chat: chat,
- chat_two: chat_two,
- cmr: cmr,
- cmr_two: cmr_two
- }
- end
-
- describe "setting read markers" do
- test "it sets all messages up to a point as read", %{
- conn: conn,
- cmr: cmr,
- chat: chat,
- user: user,
- other_user: other_user
- } do
- {:ok, chat_activity} = CommonAPI.post_chat_message(other_user, user, "morning weebs 2")
- chat_object = Object.normalize(chat_activity)
-
- conn
- |> post("/_matrix/client/r0/rooms/#{chat.id}/read_markers", %{"m.fully_read": cmr.id})
-
- cmr_two = MessageReference.for_chat_and_object(chat, chat_object)
- assert cmr_two.unread
-
- cmr = MessageReference.get_by_id(cmr.id)
- refute cmr.unread
- end
- end
-
- describe "sync" do
- test "without options, it returns all chat messages the user has", %{
- conn: conn,
- chat: chat,
- chat_two: chat_two,
- cmr: cmr,
- cmr_two: cmr_two
- } do
- %{
- "next_batch" => next_batch,
- "rooms" => %{
- "join" => joined_rooms
- }
- } =
- conn
- |> get("_matrix/client/r0/sync")
- |> json_response(200)
-
- assert chat_room = joined_rooms[chat.id]
- assert chat_room_two = joined_rooms[chat_two.id]
-
- assert [message] = chat_room["timeline"]["events"]
- assert [message_two] = chat_room_two["timeline"]["events"]
-
- assert message["content"]["formatted_body"] == "Hey"
- assert message_two["content"]["formatted_body"] == "Henlo"
-
- assert message["event_id"] == cmr.id
- assert message_two["event_id"] == cmr_two.id
-
- # Next batch contains the largest ChatMessageReference id
-
- assert next_batch == cmr_two.id
- end
-
- test "given a `since` option, it only returns chat messages after that point", %{
- conn: conn,
- cmr_two: cmr_two,
- chat: chat,
- chat_two: chat_two,
- user: user,
- other_user: other_user
- } do
- {:ok, _} = CommonAPI.post_chat_message(user, other_user, "morning weebs")
-
- %{
- "rooms" => %{
- "join" => joined_rooms
- }
- } =
- conn
- |> get("_matrix/client/r0/sync?since=#{cmr_two.id}")
- |> json_response(200)
-
- assert joined_rooms[chat_two.id]
- assert chat_room = joined_rooms[chat.id]
- assert [message] = chat_room["timeline"]["events"]
- assert message["content"]["body"] == "morning weebs"
- end
- end
-
- describe "room messages" do
- test "it returns messages", %{
- conn: conn,
- chat: chat
- } do
- res =
- conn
- |> get("_matrix/client/r0/rooms/#{chat.id}/messages")
- |> json_response(200)
-
- assert res["chunk"]
- assert res["start"]
- assert res["end"]
- end
- end
-end