fix tests
This commit is contained in:
parent
bc83fedfb3
commit
b9f8d3763d
@ -35,7 +35,7 @@ defmodule Pleroma.Web.AdminAPI.TagController do
|
|||||||
json(conn, tags)
|
json(conn, tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag(%{assigns: %{user: admin}} = conn, %{nicknames: nicknames, tags: tags}) do
|
def tag(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames, tags: tags}} = conn, _) do
|
||||||
with {:ok, _} <- User.tag(nicknames, tags) do
|
with {:ok, _} <- User.tag(nicknames, tags) do
|
||||||
ModerationLog.insert_log(%{
|
ModerationLog.insert_log(%{
|
||||||
actor: admin,
|
actor: admin,
|
||||||
@ -48,7 +48,10 @@ defmodule Pleroma.Web.AdminAPI.TagController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def untag(%{assigns: %{user: admin}} = conn, %{nicknames: nicknames, tags: tags}) do
|
def untag(
|
||||||
|
%{assigns: %{user: admin}, body_params: %{nicknames: nicknames, tags: tags}} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
with {:ok, _} <- User.untag(nicknames, tags) do
|
with {:ok, _} <- User.untag(nicknames, tags) do
|
||||||
ModerationLog.insert_log(%{
|
ModerationLog.insert_log(%{
|
||||||
actor: admin,
|
actor: admin,
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
defmodule Pleroma.Web.ApiSpec.Admin.TagOperation do
|
defmodule Pleroma.Web.ApiSpec.Admin.TagOperation do
|
||||||
alias OpenApiSpex.Operation
|
alias OpenApiSpex.Operation
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||||
|
|
||||||
import Pleroma.Web.ApiSpec.Helpers
|
import Pleroma.Web.ApiSpec.Helpers
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.TagOperation do
|
|||||||
tags: ["Admin", "Tags"],
|
tags: ["Admin", "Tags"],
|
||||||
summary: "List available tags.",
|
summary: "List available tags.",
|
||||||
operationId: "AdminAPI.TagController.list",
|
operationId: "AdminAPI.TagController.list",
|
||||||
|
parameters: admin_api_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response("Array of tags", "application/json", %Schema{
|
Operation.response("Array of tags", "application/json", %Schema{
|
||||||
@ -34,22 +36,22 @@ defmodule Pleroma.Web.ApiSpec.Admin.TagOperation do
|
|||||||
tags: ["Admin", "Tags"],
|
tags: ["Admin", "Tags"],
|
||||||
summary: "Adds tags to users.",
|
summary: "Adds tags to users.",
|
||||||
operationId: "AdminAPI.TagController.tag",
|
operationId: "AdminAPI.TagController.tag",
|
||||||
parameters: [
|
parameters: admin_api_params(),
|
||||||
Operation.parameter(
|
requestBody:
|
||||||
:nicknames,
|
request_body(
|
||||||
:query,
|
"Parameters",
|
||||||
%Schema{type: :array, items: %Schema{type: :string}},
|
%Schema{
|
||||||
"User's nicknames"
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
nicknames: %Schema{type: :array, items: %Schema{type: :string}},
|
||||||
|
tags: %Schema{type: :array, items: %Schema{type: :string}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: true
|
||||||
),
|
),
|
||||||
Operation.parameter(
|
|
||||||
:tags,
|
|
||||||
:query,
|
|
||||||
%Schema{type: :array, items: %Schema{type: :string}},
|
|
||||||
"tags"
|
|
||||||
)
|
|
||||||
],
|
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => empty_object_response()
|
204 => no_content_response(),
|
||||||
|
400 => Operation.response("Bad request", "application/json", ApiError)
|
||||||
},
|
},
|
||||||
security: [%{"oAuth" => ["write:accounts"]}]
|
security: [%{"oAuth" => ["write:accounts"]}]
|
||||||
}
|
}
|
||||||
@ -60,22 +62,22 @@ defmodule Pleroma.Web.ApiSpec.Admin.TagOperation do
|
|||||||
tags: ["Admin", "Tags"],
|
tags: ["Admin", "Tags"],
|
||||||
summary: "Remove tags from users.",
|
summary: "Remove tags from users.",
|
||||||
operationId: "AdminAPI.TagController.untag",
|
operationId: "AdminAPI.TagController.untag",
|
||||||
parameters: [
|
parameters: admin_api_params(),
|
||||||
Operation.parameter(
|
requestBody:
|
||||||
:nicknames,
|
request_body(
|
||||||
:query,
|
"Parameters",
|
||||||
%Schema{type: :array, items: %Schema{type: :string}},
|
%Schema{
|
||||||
"User's nicknames"
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
nicknames: %Schema{type: :array, items: %Schema{type: :string}},
|
||||||
|
tags: %Schema{type: :array, items: %Schema{type: :string}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: true
|
||||||
),
|
),
|
||||||
Operation.parameter(
|
|
||||||
:tags,
|
|
||||||
:query,
|
|
||||||
%Schema{type: :array, items: %Schema{type: :string}},
|
|
||||||
"tags"
|
|
||||||
)
|
|
||||||
],
|
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => empty_object_response()
|
204 => no_content_response(),
|
||||||
|
400 => Operation.response("Bad request", "application/json", ApiError)
|
||||||
},
|
},
|
||||||
security: [%{"oAuth" => ["write:accounts"]}]
|
security: [%{"oAuth" => ["write:accounts"]}]
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.AdminAPI.TagControllerTest do
|
|||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("accept", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|> get("/api/pleroma/admin/users/tag")
|
|> get("/api/pleroma/admin/users/tag")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
@ -62,24 +62,22 @@ defmodule Pleroma.Web.AdminAPI.TagControllerTest do
|
|||||||
user2 = insert(:user, %{tags: [build(:tag, name: "y")]})
|
user2 = insert(:user, %{tags: [build(:tag, name: "y")]})
|
||||||
user3 = insert(:user, %{tags: [build(:tag, name: "unchanged")]})
|
user3 = insert(:user, %{tags: [build(:tag, name: "unchanged")]})
|
||||||
|
|
||||||
conn =
|
assert conn
|
||||||
conn
|
|> put_req_header("content-type", "application/json")
|
||||||
|> put_req_header("accept", "application/json")
|
|> put("/api/pleroma/admin/users/tag", %{
|
||||||
|> put(
|
nicknames: [user1.nickname, user2.nickname],
|
||||||
"/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
|
tags: ["foo", "bar"]
|
||||||
"#{user2.nickname}&tags[]=foo&tags[]=bar"
|
})
|
||||||
)
|
|> json_response_and_validate_schema(204)
|
||||||
|
|
||||||
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
%{user1: user1, user2: user2, user3: user3}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it appends specified tags to users with specified nicknames", %{
|
test "it appends specified tags to users with specified nicknames", %{
|
||||||
conn: conn,
|
|
||||||
admin: admin,
|
admin: admin,
|
||||||
user1: user1,
|
user1: user1,
|
||||||
user2: user2
|
user2: user2
|
||||||
} do
|
} do
|
||||||
assert empty_json_response(conn)
|
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user1.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user1.id), :tags)
|
||||||
assert Enum.map(tags, & &1.name) == ["x", "foo", "bar"]
|
assert Enum.map(tags, & &1.name) == ["x", "foo", "bar"]
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user2.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user2.id), :tags)
|
||||||
@ -98,8 +96,7 @@ defmodule Pleroma.Web.AdminAPI.TagControllerTest do
|
|||||||
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
|
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
test "it does not modify tags of not specified users", %{user3: user3} do
|
||||||
assert empty_json_response(conn)
|
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user3.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user3.id), :tags)
|
||||||
assert Enum.map(tags, & &1.name) == ["unchanged"]
|
assert Enum.map(tags, & &1.name) == ["unchanged"]
|
||||||
end
|
end
|
||||||
@ -111,24 +108,22 @@ defmodule Pleroma.Web.AdminAPI.TagControllerTest do
|
|||||||
user2 = insert(:user, %{tags: [build(:tag, name: "y"), build(:tag, name: "z")]})
|
user2 = insert(:user, %{tags: [build(:tag, name: "y"), build(:tag, name: "z")]})
|
||||||
user3 = insert(:user, %{tags: [build(:tag, name: "unchanged")]})
|
user3 = insert(:user, %{tags: [build(:tag, name: "unchanged")]})
|
||||||
|
|
||||||
conn =
|
assert conn
|
||||||
conn
|
|> put_req_header("content-type", "application/json")
|
||||||
|> put_req_header("accept", "application/json")
|
|> delete(
|
||||||
|> delete(
|
"/api/pleroma/admin/users/tag",
|
||||||
"/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
|
%{nicknames: [user1.nickname, user2.nickname], tags: ["x", "z"]}
|
||||||
"#{user2.nickname}&tags[]=x&tags[]=z"
|
)
|
||||||
)
|
|> json_response_and_validate_schema(204)
|
||||||
|
|
||||||
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
%{user1: user1, user2: user2, user3: user3}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it removes specified tags from users with specified nicknames", %{
|
test "it removes specified tags from users with specified nicknames", %{
|
||||||
conn: conn,
|
|
||||||
admin: admin,
|
admin: admin,
|
||||||
user1: user1,
|
user1: user1,
|
||||||
user2: user2
|
user2: user2
|
||||||
} do
|
} do
|
||||||
assert empty_json_response(conn)
|
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user1.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user1.id), :tags)
|
||||||
assert tags == []
|
assert tags == []
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user2.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user2.id), :tags)
|
||||||
@ -147,8 +142,7 @@ defmodule Pleroma.Web.AdminAPI.TagControllerTest do
|
|||||||
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
|
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
test "it does not modify tags of not specified users", %{user3: user3} do
|
||||||
assert empty_json_response(conn)
|
|
||||||
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user3.id), :tags)
|
{:ok, tags} = Repo.get_assoc(User.get_cached_by_id(user3.id), :tags)
|
||||||
assert Enum.map(tags, & &1.name) == ["unchanged"]
|
assert Enum.map(tags, & &1.name) == ["unchanged"]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user