Add direct_note[_activity]_factory and a couple tests
[akkoma] / test / web / mastodon_api / mastodon_api_controller_test.exs
index 69a0299acf19bd37251a8b777ed88296f689e12e..94131dcb3f4346ff0a7a2b7fb3a86c2f9bb63eeb 100644 (file)
@@ -75,9 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
         "sensitive" => "false"
       })
 
-    {:ok, ttl} = Cachex.ttl(:user_cache, "idem:#{idempotency_key}")
-    # 5 Minutes
-    assert ttl > :timer.seconds(5 * 60 - 1)
+    {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
+    # Six hours
+    assert ttl > :timer.seconds(6 * 60 * 60 - 1)
 
     assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
              json_response(conn_one, 200)
@@ -97,6 +97,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert %{"id" => second_id} = json_response(conn_two, 200)
 
     assert id == second_id
+
+    conn_three =
+      conn
+      |> assign(:user, user)
+      |> post("/api/v1/statuses", %{
+        "status" => "cofe",
+        "spoiler_text" => "2hu",
+        "sensitive" => "false"
+      })
+
+    assert %{"id" => third_id} = json_response(conn_three, 200)
+
+    refute id == third_id
   end
 
   test "posting a sensitive status", %{conn: conn} do
@@ -111,6 +124,40 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert Repo.get(Activity, id)
   end
 
+  test "posting a direct status", %{conn: conn} do
+    user1 = insert(:user)
+    user2 = insert(:user)
+    content = "direct cofe @#{user2.nickname}"
+
+    conn =
+      conn
+      |> assign(:user, user1)
+      |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+
+    assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
+    assert activity = Repo.get(Activity, id)
+    assert user2.follower_address not in activity.data["to"]
+  end
+
+  test "direct timeline", %{conn: conn} do
+    dm = insert(:direct_note_activity)
+    reg_note = insert(:note_activity)
+
+    recipient = User.get_by_ap_id(hd(dm.recipients))
+
+    conn =
+      conn
+      |> assign(:user, recipient)
+      |> get("api/v1/timelines/direct")
+
+    resp = json_response(conn, 200)
+    first_status = hd(resp)
+
+    assert length(resp) == 1
+    assert %{"visibility" => "direct"} = first_status
+    assert first_status["url"] != reg_note.data["id"]
+  end
+
   test "replying to a status", %{conn: conn} do
     user = insert(:user)