From 470f5f7cd616852327706bae74bd1eddd653285f Mon Sep 17 00:00:00 2001 From: dtluna Date: Mon, 17 Apr 2017 16:31:19 +0300 Subject: [PATCH] Add user timeline spec test --- .../twitter_api_controller_test.exs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index f9723dd9f..6f1788a58 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -114,6 +114,72 @@ test "with credentials", %{conn: conn, user: current_user} 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