X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fweb%2Ftwitter_api%2Futil_controller_test.exs;h=60f2fb052292e6f8ca9a8636e0a6aa666efa0cf4;hb=9c672ecbb5d4477cd16d2139a2cb66d3923ac5c8;hp=ad919d341ad67a6e24d4271df9dec775e588a344;hpb=a2a8c8e9e09b3aa5bc488a958a0afe5909a6e89c;p=akkoma
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index ad919d341..60f2fb052 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -21,177 +21,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
setup do: clear_config([:instance])
setup do: clear_config([:frontend_configurations, :pleroma_fe])
- describe "POST /api/pleroma/follow_import" do
- setup do: oauth_access(["follow"])
-
- test "it returns HTTP 200", %{conn: conn} do
- user2 = insert(:user)
-
- response =
- conn
- |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
- |> json_response(:ok)
-
- assert response == "job started"
- end
-
- test "it imports follow lists from file", %{user: user1, conn: conn} do
- user2 = insert(:user)
-
- with_mocks([
- {File, [],
- read!: fn "follow_list.txt" ->
- "Account address,Show boosts\n#{user2.ap_id},true"
- end}
- ]) do
- response =
- conn
- |> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
- |> json_response(:ok)
-
- assert response == "job started"
-
- assert ObanHelpers.member?(
- %{
- "op" => "follow_import",
- "follower_id" => user1.id,
- "followed_identifiers" => [user2.ap_id]
- },
- all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
- )
- end
- end
-
- test "it imports new-style mastodon follow lists", %{conn: conn} do
- user2 = insert(:user)
-
- response =
- conn
- |> post("/api/pleroma/follow_import", %{
- "list" => "Account address,Show boosts\n#{user2.ap_id},true"
- })
- |> json_response(:ok)
-
- assert response == "job started"
- end
-
- test "requires 'follow' or 'write:follows' permissions" do
- token1 = insert(:oauth_token, scopes: ["read", "write"])
- token2 = insert(:oauth_token, scopes: ["follow"])
- token3 = insert(:oauth_token, scopes: ["something"])
- another_user = insert(:user)
-
- for token <- [token1, token2, token3] do
- conn =
- build_conn()
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
-
- if token == token3 do
- assert %{"error" => "Insufficient permissions: follow | write:follows."} ==
- json_response(conn, 403)
- else
- assert json_response(conn, 200)
- end
- end
- end
-
- test "it imports follows with different nickname variations", %{conn: conn} do
- [user2, user3, user4, user5, user6] = insert_list(5, :user)
-
- identifiers =
- [
- user2.ap_id,
- user3.nickname,
- " ",
- "@" <> user4.nickname,
- user5.nickname <> "@localhost",
- "@" <> user6.nickname <> "@localhost"
- ]
- |> Enum.join("\n")
-
- response =
- conn
- |> post("/api/pleroma/follow_import", %{"list" => identifiers})
- |> json_response(:ok)
-
- assert response == "job started"
- assert [{:ok, job_result}] = ObanHelpers.perform_all()
- assert job_result == [user2, user3, user4, user5, user6]
- end
- end
-
- describe "POST /api/pleroma/blocks_import" do
- # Note: "follow" or "write:blocks" permission is required
- setup do: oauth_access(["write:blocks"])
-
- test "it returns HTTP 200", %{conn: conn} do
- user2 = insert(:user)
-
- response =
- conn
- |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
- |> json_response(:ok)
-
- assert response == "job started"
- end
-
- test "it imports blocks users from file", %{user: user1, conn: conn} do
- user2 = insert(:user)
- user3 = insert(:user)
-
- with_mocks([
- {File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
- ]) do
- response =
- conn
- |> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
- |> json_response(:ok)
-
- assert response == "job started"
-
- assert ObanHelpers.member?(
- %{
- "op" => "blocks_import",
- "blocker_id" => user1.id,
- "blocked_identifiers" => [user2.ap_id, user3.ap_id]
- },
- all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
- )
- end
- end
-
- test "it imports blocks with different nickname variations", %{conn: conn} do
- [user2, user3, user4, user5, user6] = insert_list(5, :user)
-
- identifiers =
- [
- user2.ap_id,
- user3.nickname,
- "@" <> user4.nickname,
- user5.nickname <> "@localhost",
- "@" <> user6.nickname <> "@localhost"
- ]
- |> Enum.join(" ")
-
- response =
- conn
- |> post("/api/pleroma/blocks_import", %{"list" => identifiers})
- |> json_response(:ok)
-
- assert response == "job started"
- assert [{:ok, job_result}] = ObanHelpers.perform_all()
- assert job_result == [user2, user3, user4, user5, user6]
- end
- end
-
describe "PUT /api/pleroma/notification_settings" do
setup do: oauth_access(["write:accounts"])
test "it updates notification settings", %{user: user, conn: conn} do
conn
|> put("/api/pleroma/notification_settings", %{
- "followers" => false,
+ "block_from_strangers" => true,
"bar" => 1
})
|> json_response(:ok)
@@ -199,130 +35,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
- followers: false,
- follows: true,
- non_follows: true,
- non_followers: true,
- privacy_option: false
+ block_from_strangers: true,
+ hide_notification_contents: false
} == user.notification_settings
end
- test "it updates notification privacy option", %{user: user, conn: conn} do
+ test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
conn
- |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
+ |> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"})
|> json_response(:ok)
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
- followers: true,
- follows: true,
- non_follows: true,
- non_followers: true,
- privacy_option: true
+ block_from_strangers: false,
+ hide_notification_contents: true
} == user.notification_settings
end
end
- describe "GET /api/statusnet/config" do
- test "it returns config in xml format", %{conn: conn} do
- instance = Config.get(:instance)
-
- response =
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/api/statusnet/config")
- |> response(:ok)
-
- assert response ==
- "\n\n#{Keyword.get(instance, :name)}\n#{
- Pleroma.Web.base_url()
- }\n#{Keyword.get(instance, :limit)}\n#{
- !Keyword.get(instance, :registrations_open)
- }\n\n\n"
- end
-
- test "it returns config in json format", %{conn: conn} do
- instance = Config.get(:instance)
- Config.put([:instance, :managed_config], true)
- Config.put([:instance, :registrations_open], false)
- Config.put([:instance, :invites_enabled], true)
- Config.put([:instance, :public], false)
- Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
-
- response =
- conn
- |> put_req_header("accept", "application/json")
- |> get("/api/statusnet/config")
- |> json_response(:ok)
-
- expected_data = %{
- "site" => %{
- "accountActivationRequired" => "0",
- "closed" => "1",
- "description" => Keyword.get(instance, :description),
- "invitesEnabled" => "1",
- "name" => Keyword.get(instance, :name),
- "pleromafe" => %{"theme" => "asuka-hospital"},
- "private" => "1",
- "safeDMMentionsEnabled" => "0",
- "server" => Pleroma.Web.base_url(),
- "textlimit" => to_string(Keyword.get(instance, :limit)),
- "uploadlimit" => %{
- "avatarlimit" => to_string(Keyword.get(instance, :avatar_upload_limit)),
- "backgroundlimit" => to_string(Keyword.get(instance, :background_upload_limit)),
- "bannerlimit" => to_string(Keyword.get(instance, :banner_upload_limit)),
- "uploadlimit" => to_string(Keyword.get(instance, :upload_limit))
- },
- "vapidPublicKey" => Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
- }
- }
-
- assert response == expected_data
- end
-
- test "returns the state of safe_dm_mentions flag", %{conn: conn} do
- Config.put([:instance, :safe_dm_mentions], true)
-
- response =
- conn
- |> get("/api/statusnet/config.json")
- |> json_response(:ok)
-
- assert response["site"]["safeDMMentionsEnabled"] == "1"
-
- Config.put([:instance, :safe_dm_mentions], false)
-
- response =
- conn
- |> get("/api/statusnet/config.json")
- |> json_response(:ok)
-
- assert response["site"]["safeDMMentionsEnabled"] == "0"
- end
-
- test "it returns the managed config", %{conn: conn} do
- Config.put([:instance, :managed_config], false)
- Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
-
- response =
- conn
- |> get("/api/statusnet/config.json")
- |> json_response(:ok)
-
- refute response["site"]["pleromafe"]
-
- Config.put([:instance, :managed_config], true)
-
- response =
- conn
- |> get("/api/statusnet/config.json")
- |> json_response(:ok)
-
- assert response["site"]["pleromafe"] == %{"theme" => "asuka-hospital"}
- end
- end
-
describe "GET /api/pleroma/frontend_configurations" do
test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
config = [
@@ -451,28 +182,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- describe "GET /api/statusnet/version" do
- test "it returns version in xml format", %{conn: conn} do
- response =
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/api/statusnet/version")
- |> response(:ok)
-
- assert response == "#{Pleroma.Application.named_version()}"
- end
-
- test "it returns version in json format", %{conn: conn} do
- response =
- conn
- |> put_req_header("accept", "application/json")
- |> get("/api/statusnet/version")
- |> json_response(:ok)
-
- assert response == "#{Pleroma.Application.named_version()}"
- end
- end
-
describe "POST /main/ostatus - remote_subscribe/2" do
setup do: clear_config([:instance, :federating], true)
@@ -713,10 +422,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- test "with proper permissions and valid password", %{conn: conn} do
+ test "with proper permissions and valid password", %{conn: conn, user: user} do
conn = post(conn, "/api/pleroma/delete_account", %{"password" => "test"})
-
+ ObanHelpers.perform_all()
assert json_response(conn, 200) == %{"status" => "success"}
+
+ user = User.get_by_id(user.id)
+ assert user.deactivated == true
+ assert user.name == nil
+ assert user.bio == ""
+ assert user.password_hash == nil
end
end
end