end
end
+ def update_avatar(%{assigns: %{user: user}} = conn, params) do
+ {:ok, object} = ActivityPub.upload(params)
+ change = Ecto.Changeset.change(user, %{avatar: object.data})
+ {:ok, user} = Repo.update(change)
+
+ response = UserRepresenter.to_map(user, %{for: user})
+ |> Poison.encode!
+
+ conn
+ |> json_reply(200, response)
+ end
+
+ defp bad_request_reply(conn, error_message) do
+ json = Poison.encode!(%{"error" => error_message})
+ json_reply(conn, 400, json)
+ end
+
defp json_reply(conn, status, json) do
conn
|> put_resp_content_type("application/json")
assert length(statuses) == 2
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user})
- assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]})
+ assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
end
+ test "get a user by params" do
+ user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
+ {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
+
+ assert {:error, "You need to specify screen_name or user_id"} == TwitterAPI.get_user(nil, nil)
+ assert user1_result == TwitterAPI.get_user(nil, %{"user_id" => user1.id})
+ assert user1_result == TwitterAPI.get_user(nil, %{"screen_name" => user1.nickname})
+ assert user1_result == TwitterAPI.get_user(user1, nil)
+ assert user1_result == TwitterAPI.get_user(user2, %{"user_id" => user1.id})
+ assert user1_result == TwitterAPI.get_user(user2, %{"screen_name" => user1.nickname})
+ assert {:error, "No user with such screen_name"} == TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
+ assert {:error, "No user with such user_id"} == TwitterAPI.get_user(nil, %{"user_id" => 666})
+ end
+
+ test "fetch user's statuses" do
+ {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
+ {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
+
+ {:ok, status1} = ActivityBuilder.insert(%{"id" => 1}, %{user: user1})
+ {:ok, status2} = ActivityBuilder.insert(%{"id" => 2}, %{user: user2})
+
+ user1_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user1.ap_id})
+
+ assert length(user1_statuses) == 1
+ assert Enum.at(user1_statuses, 0) == ActivityRepresenter.to_map(status1, %{user: user1})
+
+ user2_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user2.ap_id})
+
+ assert length(user2_statuses) == 1
+ assert Enum.at(user2_statuses, 0) == ActivityRepresenter.to_map(status2, %{user: user2})
+ end
+
test "fetch a single status" do
{:ok, activity} = ActivityBuilder.insert()
{:ok, user} = UserBuilder.insert()