Add tests.
get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
get "/users/show", TwitterAPI.Controller, :show_user
+ get "/statuses/followers", TwitterAPI.Controller, :followers
+ get "/statuses/friends", TwitterAPI.Controller, :friends
get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
- get "/statuses/followers", TwitterAPI.Controller, :followers
- get "/statuses/friends", TwitterAPI.Controller, :friends
get "/friends/ids", TwitterAPI.Controller, :friends_ids
get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
end
end
- def followers(%{assigns: %{user: user}} = conn, _params) do
- with {:ok, followers} <- User.get_followers(user) do
+ def followers(conn, params) do
+ with {:ok, user} <- TwitterAPI.get_user(conn.assigns.user, params),
+ {:ok, followers} <- User.get_followers(user) do
render(conn, UserView, "index.json", %{users: followers, for: user})
else
_e -> bad_request_reply(conn, "Can't get followers")
end
end
- def friends(%{assigns: %{user: user}} = conn, _params) do
- with {:ok, friends} <- User.get_friends(user) do
+ def friends(conn, params) do
+ with {:ok, user} <- TwitterAPI.get_user(conn.assigns.user, params),
+ {:ok, friends} <- User.get_friends(user) do
render(conn, UserView, "index.json", %{users: friends, for: user})
else
_e -> bad_request_reply(conn, "Can't get friends")
end
describe "GET /api/statuses/friends" do
- test "it returns a user's friends", %{conn: conn} do
+ test "it returns the logged in user's friends", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
end
+
+ test "it returns a given user's friends with user_id", %{conn: conn} do
+ user = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+
+ conn = conn
+ |> get("/api/statuses/friends", %{"user_id" => user.id})
+
+ assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
+ end
+
+ test "it returns a given user's friends with screen_name", %{conn: conn} do
+ user = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+
+ conn = conn
+ |> get("/api/statuses/friends", %{"screen_name" => user.nickname})
+
+ assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
+ end
end
describe "GET /friends/ids" do