forked from AkkomaGang/akkoma
Fix follower/following lists.
Add tests.
This commit is contained in:
parent
9223038319
commit
1969773fb4
3 changed files with 39 additions and 7 deletions
|
@ -142,6 +142,8 @@ def user_fetcher(username) do
|
|||
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
|
||||
|
||||
|
@ -188,8 +190,6 @@ def user_fetcher(username) do
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -263,16 +263,18 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
|
|||
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")
|
||||
|
|
|
@ -518,7 +518,7 @@ test "it returns a user's followers", %{conn: conn} do
|
|||
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)
|
||||
|
@ -533,6 +533,36 @@ test "it returns a user's friends", %{conn: conn} do
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue