summaryrefslogtreecommitdiff
path: root/test/web/mastodon_api
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/mastodon_api')
-rw-r--r--test/web/mastodon_api/controllers/list_controller_test.exs166
-rw-r--r--test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs (renamed from test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs)0
-rw-r--r--test/web/mastodon_api/controllers/search_controller_test.exs (renamed from test/web/mastodon_api/search_controller_test.exs)0
-rw-r--r--test/web/mastodon_api/controllers/subscription_controller_test.exs (renamed from test/web/mastodon_api/subscription_controller_test.exs)0
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs130
-rw-r--r--test/web/mastodon_api/views/account_view_test.exs (renamed from test/web/mastodon_api/account_view_test.exs)0
-rw-r--r--test/web/mastodon_api/views/conversation_view_test.exs (renamed from test/web/mastodon_api/conversation_view_test.exs)0
-rw-r--r--test/web/mastodon_api/views/list_view_test.exs (renamed from test/web/mastodon_api/list_view_test.exs)14
-rw-r--r--test/web/mastodon_api/views/notification_view_test.exs (renamed from test/web/mastodon_api/notification_view_test.exs)0
-rw-r--r--test/web/mastodon_api/views/push_subscription_view_test.exs (renamed from test/web/mastodon_api/push_subscription_view_test.exs)0
-rw-r--r--test/web/mastodon_api/views/scheduled_activity_view_test.exs (renamed from test/web/mastodon_api/scheduled_activity_view_test.exs)0
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs (renamed from test/web/mastodon_api/status_view_test.exs)1
12 files changed, 208 insertions, 103 deletions
diff --git a/test/web/mastodon_api/controllers/list_controller_test.exs b/test/web/mastodon_api/controllers/list_controller_test.exs
new file mode 100644
index 000000000..093506309
--- /dev/null
+++ b/test/web/mastodon_api/controllers/list_controller_test.exs
@@ -0,0 +1,166 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Repo
+
+ import Pleroma.Factory
+
+ 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 "renders error for invalid params", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/lists", %{"title" => nil})
+
+ assert %{"error" => "can't be blank"} == json_response(conn, :unprocessable_entity)
+ end
+
+ test "listing a user's lists", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/lists", %{"title" => "cuties"})
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/lists", %{"title" => "cofe"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/lists")
+
+ assert [
+ %{"id" => _, "title" => "cofe"},
+ %{"id" => _, "title" => "cuties"}
+ ] = json_response(conn, :ok)
+ 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 "renders 404 if list is not found", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/lists/666")
+
+ assert %{"error" => "List not found"} = json_response(conn, :not_found)
+ 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 "validates title when 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" => " "})
+
+ assert %{"error" => "can't be blank"} == json_response(conn, :unprocessable_entity)
+ 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
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
index 87ee82050..87ee82050 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
diff --git a/test/web/mastodon_api/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs
index 49c79ff0a..49c79ff0a 100644
--- a/test/web/mastodon_api/search_controller_test.exs
+++ b/test/web/mastodon_api/controllers/search_controller_test.exs
diff --git a/test/web/mastodon_api/subscription_controller_test.exs b/test/web/mastodon_api/controllers/subscription_controller_test.exs
index 7dfb02f63..7dfb02f63 100644
--- a/test/web/mastodon_api/subscription_controller_test.exs
+++ b/test/web/mastodon_api/controllers/subscription_controller_test.exs
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0f40146fb..64b889d55 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Ecto.Changeset
alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Object
@@ -151,6 +152,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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
@@ -404,7 +431,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest 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)
@@ -901,106 +928,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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)
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 1d8b28339..1d8b28339 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/views/conversation_view_test.exs
index a2a880705..a2a880705 100644
--- a/test/web/mastodon_api/conversation_view_test.exs
+++ b/test/web/mastodon_api/views/conversation_view_test.exs
diff --git a/test/web/mastodon_api/list_view_test.exs b/test/web/mastodon_api/views/list_view_test.exs
index 73143467f..fb00310b9 100644
--- a/test/web/mastodon_api/list_view_test.exs
+++ b/test/web/mastodon_api/views/list_view_test.exs
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
import Pleroma.Factory
alias Pleroma.Web.MastodonAPI.ListView
- test "Represent a list" do
+ test "show" do
user = insert(:user)
title = "mortal enemies"
{:ok, list} = Pleroma.List.create(title, user)
@@ -17,6 +17,16 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
title: title
}
- assert expected == ListView.render("list.json", %{list: list})
+ assert expected == ListView.render("show.json", %{list: list})
+ end
+
+ test "index" do
+ user = insert(:user)
+
+ {:ok, list} = Pleroma.List.create("my list", user)
+ {:ok, list2} = Pleroma.List.create("cofe", user)
+
+ assert [%{id: _, title: "my list"}, %{id: _, title: "cofe"}] =
+ ListView.render("index.json", lists: [list, list2])
end
end
diff --git a/test/web/mastodon_api/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 977ea1e87..977ea1e87 100644
--- a/test/web/mastodon_api/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
diff --git a/test/web/mastodon_api/push_subscription_view_test.exs b/test/web/mastodon_api/views/push_subscription_view_test.exs
index dc935fc82..dc935fc82 100644
--- a/test/web/mastodon_api/push_subscription_view_test.exs
+++ b/test/web/mastodon_api/views/push_subscription_view_test.exs
diff --git a/test/web/mastodon_api/scheduled_activity_view_test.exs b/test/web/mastodon_api/views/scheduled_activity_view_test.exs
index ecbb855d4..ecbb855d4 100644
--- a/test/web/mastodon_api/scheduled_activity_view_test.exs
+++ b/test/web/mastodon_api/views/scheduled_activity_view_test.exs
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index c983b494f..1b6beb6d2 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -149,6 +149,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
in_reply_to_account_acct: nil,
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
+ expires_at: nil,
direct_conversation_id: nil
}
}