Add Tests
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 14 May 2019 13:12:47 +0000 (20:12 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 14 May 2019 13:12:47 +0000 (20:12 +0700)
test/list_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/common_api/common_api_test.exs

index 1909c0cd9e664771e7e425eab8542c5e7d8e8a2a..0e72b66604c212e87957f873fd23b4f04a08dfa8 100644 (file)
@@ -113,4 +113,33 @@ defmodule Pleroma.ListTest do
     assert owned_list in lists_2
     refute not_owned_list in lists_2
   end
+
+  test "get ap_id by user nickname and list id" do
+    nickname = "foo"
+    list_id = 42
+
+    expected = Pleroma.Web.Endpoint.url() <> "/users/#{nickname}/lists/#{list_id}"
+
+    assert Pleroma.List.ap_id(%Pleroma.User{nickname: nickname}, list_id) == expected
+    assert Pleroma.List.ap_id({nickname, list_id}) == expected
+  end
+
+  test "get by ap_id" do
+    user = insert(:user)
+    {:ok, list} = Pleroma.List.create("foo", user)
+    ap_id = Pleroma.List.ap_id(user, list.id)
+
+    assert Pleroma.List.get_by_ap_id(ap_id) == list
+  end
+
+  test "memberships" do
+    user = insert(:user)
+    member = insert(:user)
+    {:ok, list} = Pleroma.List.create("foo", user)
+    {:ok, list} = Pleroma.List.follow(list, member)
+
+    list_ap_id = Pleroma.List.ap_id(user, list.id)
+
+    assert Pleroma.List.memberships(member) == [list_ap_id]
+  end
 end
index 0f90aa1acb072585fed756c1f745536669d8de29..e38de388b73b4f1e8fbe9bcd4c3d8a6421abfcde 100644 (file)
@@ -1156,6 +1156,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     end
   end
 
+  test "fetch_activities/2 returns activities addressed to a list " do
+    user = insert(:user)
+    member = insert(:user)
+    {:ok, list} = Pleroma.List.create("foo", user)
+    {:ok, list} = Pleroma.List.follow(list, member)
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+    activity = Repo.preload(activity, :bookmark)
+
+    assert ActivityPub.fetch_activities([], %{"user" => user}) == [activity]
+  end
+
   def data_uri do
     File.read!("test/fixtures/avatar_data_uri")
   end
index c24b50f8c833a4f1513edb8841b51cb7153fdc25..e93189df65ac5a81ce5a85ab8558b55e216ebfcd 100644 (file)
@@ -1028,6 +1028,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
 
       assert modified["directMessage"] == true
     end
+
+    test "it strips BCC field" do
+      user = insert(:user)
+      {:ok, list} = Pleroma.List.create("foo", user)
+
+      {:ok, activity} =
+        CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+      assert is_nil(modified["bcc"])
+    end
   end
 
   describe "user upgrade" do
index a5b07c4469f89d8fc2938bf7829bc2428a3b19f2..11f3c8357caf9405affe3e89f8ebfc39e29d4556 100644 (file)
@@ -87,6 +87,19 @@ defmodule Pleroma.Web.CommonAPITest do
 
       assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
     end
+
+    test "it allows to address a list" do
+      user = insert(:user)
+      {:ok, list} = Pleroma.List.create("foo", user)
+
+      list_ap_id = Pleroma.List.ap_id(user, list.id)
+
+      {:ok, activity} =
+        CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+      assert activity.data["bcc"] == [list_ap_id]
+      assert activity.recipients == [list_ap_id, user.ap_id]
+    end
   end
 
   describe "reactions" do