Add user timeline spec test
authordtluna <dtluna@openmailbox.org>
Mon, 17 Apr 2017 13:31:19 +0000 (16:31 +0300)
committerdtluna <dtluna@openmailbox.org>
Mon, 17 Apr 2017 13:31:19 +0000 (16:31 +0300)
test/web/twitter_api/twitter_api_controller_test.exs

index f9723dd9fa94e93269456d2b38e357babaee366c..6f1788a5884de5fad060f0545db913ecca97fecc 100644 (file)
@@ -114,6 +114,72 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     end
   end
 
+  describe "GET /statuses/user_timeline.json" do
+    setup [:valid_user]
+    test "without any params", %{conn: conn} do
+      conn = get(conn, "/api/statuses/user_timeline.json")
+      assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id"}
+    end
+
+    test "with user_id", %{conn: conn} do
+      user = insert(:user)
+      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
+
+      conn = get(conn, "/api/statuses/user_timeline.json", %{"user_id" => user.id})
+      response = json_response(conn, 200)
+      assert length(response) == 1
+      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+    end
+
+    test "with screen_name", %{conn: conn} do
+      user = insert(:user)
+      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
+
+      conn = get(conn, "/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
+      response = json_response(conn, 200)
+      assert length(response) == 1
+      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+    end
+
+    test "with credentials", %{conn: conn, user: current_user} do
+      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: current_user})
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> get("/api/statuses/user_timeline.json")
+
+      response = json_response(conn, 200)
+
+      assert length(response) == 1
+      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: current_user})
+    end
+
+    test "with credentials with user_id", %{conn: conn, user: current_user} do
+      user = insert(:user)
+      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
+
+      response = json_response(conn, 200)
+
+      assert length(response) == 1
+      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+    end
+
+    test "with credentials screen_name", %{conn: conn, user: current_user} do
+      user = insert(:user)
+      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
+
+      response = json_response(conn, 200)
+
+      assert length(response) == 1
+      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+    end
+  end
+
   describe "POST /friendships/create.json" do
     setup [:valid_user]
     test "without valid credentials", %{conn: conn} do