def friends(%{assigns: %{user: for_user}} = conn, params) do
{:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1)
+ {:ok, export} = Ecto.Type.cast(:boolean, params["all"] || false)
+
+ page = if export, do: nil, else: page
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
{:ok, friends} <- User.get_friends(user, page) do
assert Enum.sort(expected) == Enum.sort(result)
end
- test "it returns 20 friends per page", %{conn: conn} do
+ test "it returns 20 friends per page, except if 'export' is set to true", %{conn: conn} do
user = insert(:user)
followeds = insert_list(21, :user)
result = json_response(res_conn, 200)
assert length(result) == 1
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{all: true})
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 21
end
test "it returns a given user's friends with user_id", %{conn: conn} do