Add context and inReplyTo.
[akkoma] / test / web / twitter_api / twitter_api_controller_test.exs
index 86c03c652a89abee13396b81860546ef2d443b70..851d5f4a7570ea617abc8f0c5a01f08a92ca9326 100644 (file)
@@ -62,7 +62,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     test "with credentials", %{conn: conn, user: current_user} do
       {:ok, user} = UserBuilder.insert
       activities = ActivityBuilder.insert_list(30, %{"to" => [User.ap_followers(user)]}, %{user: user})
-      ActivityBuilder.insert_list(10, %{"to" => [User.ap_followers(user)]}, %{user: user})
+      returned_activities = ActivityBuilder.insert_list(10, %{"to" => [User.ap_followers(user)]}, %{user: user})
       {:ok, other_user} = UserBuilder.insert(%{ap_id: "glimmung", nickname: "nockame"})
       ActivityBuilder.insert_list(10, %{}, %{user: other_user})
       since_id = List.last(activities).id
@@ -76,6 +76,50 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       response = json_response(conn, 200)
 
       assert length(response) == 10
+      assert response == Enum.map(returned_activities, fn (activity) -> ActivityRepresenter.to_map(activity, %{user: user, for: current_user}) end)
+    end
+  end
+
+  describe "POST /friendships/create.json" do
+    setup [:valid_user]
+    test "without valid credentials", %{conn: conn} do
+      conn = post conn, "/api/friendships/create.json"
+      assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+    end
+
+    test "with credentials", %{conn: conn, user: current_user} do
+      {:ok, followed } = UserBuilder.insert(%{name: "some guy"})
+
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> post("/api/friendships/create.json", %{user_id: followed.id})
+
+      current_user = Repo.get(User, current_user.id)
+      assert current_user.following == [User.ap_followers(followed)]
+      assert json_response(conn, 200) == UserRepresenter.to_map(followed)
+    end
+  end
+
+  describe "POST /friendships/destroy.json" do
+    setup [:valid_user]
+    test "without valid credentials", %{conn: conn} do
+      conn = post conn, "/api/friendships/destroy.json"
+      assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+    end
+
+    test "with credentials", %{conn: conn, user: current_user} do
+      {:ok, followed } = UserBuilder.insert(%{name: "some guy"})
+
+      {:ok, current_user} = User.follow(current_user, followed)
+      assert current_user.following == [User.ap_followers(followed)]
+
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> post("/api/friendships/destroy.json", %{user_id: followed.id})
+
+      current_user = Repo.get(User, current_user.id)
+      assert current_user.following == []
+      assert json_response(conn, 200) == UserRepresenter.to_map(followed)
     end
   end