Merge branch 'develop' into issue/1276
[akkoma] / test / web / pleroma_api / controllers / pleroma_api_controller_test.exs
index 7eaeda4a025a48d5b1e1d8ce1c4f2af27709bd8e..0c83edb56173785cf70a8f640af146083fb1d9f2 100644 (file)
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
   alias Pleroma.Conversation.Participation
   alias Pleroma.Notification
   alias Pleroma.Repo
+  alias Pleroma.User
   alias Pleroma.Web.CommonAPI
 
   import Pleroma.Factory
@@ -73,6 +74,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
 
     participation = Repo.preload(participation, :recipients)
 
+    user = User.get_cached_by_id(user.id)
     assert [user] == participation.recipients
     assert other_user not in participation.recipients
 
@@ -93,6 +95,33 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
     assert other_user in participation.recipients
   end
 
+  test "POST /api/v1/pleroma/conversations/read", %{conn: conn} do
+    user = insert(:user)
+    other_user = insert(:user)
+
+    {:ok, _activity} =
+      CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
+
+    {:ok, _activity} =
+      CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
+
+    [participation2, participation1] = Participation.for_user(other_user)
+    assert Participation.get(participation2.id).read == false
+    assert Participation.get(participation1.id).read == false
+    assert User.get_cached_by_id(other_user.id).unread_conversation_count == 2
+
+    [%{"unread" => false}, %{"unread" => false}] =
+      conn
+      |> assign(:user, other_user)
+      |> post("/api/v1/pleroma/conversations/read", %{})
+      |> json_response(200)
+
+    [participation2, participation1] = Participation.for_user(other_user)
+    assert Participation.get(participation2.id).read == true
+    assert Participation.get(participation1.id).read == true
+    assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
+  end
+
   describe "POST /api/v1/pleroma/notifications/read" do
     test "it marks a single notification as read", %{conn: conn} do
       user1 = insert(:user)