From: dtluna Date: Mon, 17 Apr 2017 13:31:19 +0000 (+0300) Subject: Add user timeline spec test X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=470f5f7cd616852327706bae74bd1eddd653285f;p=akkoma Add user timeline spec test --- 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 @@ 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