alias Ecto.Changeset
alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Object
:ok
end
+ clear_config([:instance, :public])
+ clear_config([:rich_media, :enabled])
+
test "the home timeline", %{conn: conn} do
user = insert(:user)
following = insert(:user)
end
test "the public timeline when public is set to false", %{conn: conn} do
- public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
- on_exit(fn ->
- Config.put([:instance, :public], public)
- end)
-
assert conn
|> get("/api/v1/timelines/public", %{"local" => "False"})
|> json_response(403) == %{"error" => "This resource requires authentication."}
assert %{"id" => third_id} = json_response(conn_three, 200)
refute id == third_id
+
+ # An activity that will expire:
+ # 2 hours
+ expires_in = 120 * 60
+
+ conn_four =
+ conn
+ |> post("api/v1/statuses", %{
+ "status" => "oolong",
+ "expires_in" => expires_in
+ })
+
+ assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200)
+ assert activity = Activity.get_by_id(fourth_id)
+ assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
+
+ estimated_expires_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(expires_in)
+ |> NaiveDateTime.truncate(:second)
+
+ # This assert will fail if the test takes longer than a minute. I sure hope it never does:
+ assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60
+
+ assert fourth_response["pleroma"]["expires_at"] ==
+ NaiveDateTime.to_iso8601(expiration.scheduled_at)
end
test "replying to a status", %{conn: conn} do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Activity.get_by_id(id)
- Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
assert %{"visibility" => "direct"} = status
assert status["url"] != direct.data["id"]
- # User should be able to see his own direct message
+ # User should be able to see their own direct message
res_conn =
build_conn()
|> assign(:user, user_one)
end
end
- describe "lists" do
- test "creating a list", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/lists", %{"title" => "cuties"})
-
- assert %{"title" => title} = json_response(conn, 200)
- assert title == "cuties"
- end
-
- test "adding users to a list", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
-
- assert %{} == json_response(conn, 200)
- %Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
- assert following == [other_user.follower_address]
- end
-
- test "removing users from a list", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- third_user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
- {:ok, list} = Pleroma.List.follow(list, other_user)
- {:ok, list} = Pleroma.List.follow(list, third_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
-
- assert %{} == json_response(conn, 200)
- %Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
- assert following == [third_user.follower_address]
- end
-
- test "listing users in a list", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
- {:ok, list} = Pleroma.List.follow(list, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(other_user.id)
- end
-
- test "retrieving a list", %{conn: conn} do
- user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/lists/#{list.id}")
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == to_string(list.id)
- end
-
- test "renaming a list", %{conn: conn} do
- user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
-
- conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/lists/#{list.id}", %{"title" => "newname"})
-
- assert %{"title" => name} = json_response(conn, 200)
- assert name == "newname"
- end
-
- test "deleting a list", %{conn: conn} do
- user = insert(:user)
- {:ok, list} = Pleroma.List.create("name", user)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/lists/#{list.id}")
-
- assert %{} = json_response(conn, 200)
- assert is_nil(Repo.get(Pleroma.List, list.id))
- end
-
+ describe "list timelines" do
test "list timeline", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
describe "media upload" do
setup do
- upload_config = Config.get([Pleroma.Upload])
- proxy_config = Config.get([:media_proxy])
-
- on_exit(fn ->
- Config.put([Pleroma.Upload], upload_config)
- Config.put([:media_proxy], proxy_config)
- end)
-
user = insert(:user)
conn =
[conn: conn, image: image]
end
+ clear_config([:media_proxy])
+ clear_config([Pleroma.Upload])
+
test "returns uploaded image", %{conn: conn, image: image} do
desc = "Description of the image"
describe "pinned statuses" do
setup do
- Config.put([:instance, :max_pinned_statuses], 1)
-
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
[user: user, activity: activity]
end
+ clear_config([:instance, :max_pinned_statuses]) do
+ Config.put([:instance, :max_pinned_statuses], 1)
+ end
+
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
setup do
Config.put([:rich_media, :enabled], true)
- on_exit(fn ->
- Config.put([:rich_media, :enabled], false)
- end)
-
user = insert(:user)
%{user: user}
end
conn: conn,
path: path
} do
- is_public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
conn = get(conn, path)
assert conn.status == 302
assert redirected_to(conn) == "/web/login"
-
- Config.put([:instance, :public], is_public)
end
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
setup do
- setting = Config.get([:instance, :account_activation_required])
-
- unless setting do
- Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Config.put([:instance, :account_activation_required], setting) end)
- end
-
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
[user: user]
end
+ clear_config([:instance, :account_activation_required]) do
+ Config.put([:instance, :account_activation_required], true)
+ end
+
test "resend account confirmation email", %{conn: conn, user: user} do
conn
|> assign(:user, user)
setup do
user = insert(:user)
other_user = insert(:user)
- config = Config.get(:suggestions)
- on_exit(fn -> Config.put(:suggestions, config) end)
-
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
url500 = "http://test500?#{host}&#{user.nickname}"
url200 = "http://test200?#{host}&#{user.nickname}"
[user: user, other_user: other_user]
end
+ clear_config(:suggestions)
+
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
Config.put([:suggestions, :enabled], false)