added api spec
This commit is contained in:
parent
5ae56aafb2
commit
917d325972
5 changed files with 164 additions and 52 deletions
|
|
@ -23,9 +23,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
test "it returns HTTP 200", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "it imports follow lists from file", %{conn: conn} do
|
||||
|
|
@ -37,9 +39,13 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
"Account address,Show boosts\n#{user2.ap_id},true"
|
||||
end}
|
||||
]) do
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{
|
||||
"list" => %Plug.Upload{path: "follow_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2]
|
||||
|
|
@ -49,11 +55,13 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
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)
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{
|
||||
"list" => "Account address,Show boosts\n#{user2.ap_id},true"
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response == "job started"
|
||||
end
|
||||
|
|
@ -68,6 +76,7 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("authorization", "Bearer #{token.token}")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
|
||||
|
||||
if token == token3 do
|
||||
|
|
@ -93,9 +102,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
]
|
||||
|> Enum.join("\n")
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/follow_import", %{"list" => identifiers})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/follow_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
|
|
@ -109,9 +120,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
test "it returns HTTP 200", %{conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "it imports blocks users from file", %{conn: conn} do
|
||||
|
|
@ -120,10 +133,13 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
with_mocks([
|
||||
{File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
|
||||
]) do
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{
|
||||
"list" => %Plug.Upload{path: "blocks_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
|
|
@ -143,9 +159,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
]
|
||||
|> Enum.join(" ")
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => identifiers})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
|
|
@ -159,25 +177,30 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
test "it returns HTTP 200", %{user: user, conn: conn} do
|
||||
user2 = insert(:user)
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => "#{user2.ap_id}"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2]
|
||||
assert Pleroma.User.mutes?(user, user2)
|
||||
end
|
||||
|
||||
|
||||
test "it imports mutes users from file", %{user: user, conn: conn} do
|
||||
users = [user2, user3] = insert_list(2, :user)
|
||||
|
||||
with_mocks([
|
||||
{File, [], read!: fn "mutes_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
|
||||
]) do
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => %Plug.Upload{path: "mutes_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{
|
||||
"list" => %Plug.Upload{path: "mutes_list.txt"}
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
|
|
@ -188,15 +211,22 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
test "it imports mutes with different nickname variations", %{user: user, conn: conn} do
|
||||
users = [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(" ")
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join(" ")
|
||||
|
||||
assert "job started" ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => identifiers})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert "job started" == conn
|
||||
|> post("/api/pleroma/mutes_import", %{"list" => identifiers})
|
||||
|> json_response(:ok)
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == users
|
||||
assert Enum.all?(users, &Pleroma.User.mutes?(user, &1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue