Merge branch 'develop' into issue/1280
This commit is contained in:
commit
d770cffce0
575 changed files with 5892 additions and 2203 deletions
|
|
@ -867,6 +867,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
test "adds an emoji reaction activity to the db" do
|
||||
user = insert(:user)
|
||||
reactor = insert(:user)
|
||||
third_user = insert(:user)
|
||||
fourth_user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"})
|
||||
assert object = Object.normalize(activity)
|
||||
|
||||
|
|
@ -881,7 +883,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert reaction_activity.data["to"] == [User.ap_followers(reactor), activity.data["actor"]]
|
||||
assert reaction_activity.data["context"] == object.data["context"]
|
||||
assert object.data["reaction_count"] == 1
|
||||
assert object.data["reactions"]["🔥"] == [reactor.ap_id]
|
||||
assert object.data["reactions"] == [["🔥", [reactor.ap_id]]]
|
||||
|
||||
{:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(third_user, object, "☕")
|
||||
|
||||
assert object.data["reaction_count"] == 2
|
||||
assert object.data["reactions"] == [["🔥", [reactor.ap_id]], ["☕", [third_user.ap_id]]]
|
||||
|
||||
{:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(fourth_user, object, "🔥")
|
||||
|
||||
assert object.data["reaction_count"] == 3
|
||||
|
||||
assert object.data["reactions"] == [
|
||||
["🔥", [fourth_user.ap_id, reactor.ap_id]],
|
||||
["☕", [third_user.ap_id]]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -919,7 +935,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
object = Object.get_by_ap_id(object.data["id"])
|
||||
assert object.data["reaction_count"] == 0
|
||||
assert object.data["reactions"] == %{}
|
||||
assert object.data["reactions"] == []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
)
|
||||
|> Repo.all()
|
||||
|
||||
assert length(accepts) == 0
|
||||
assert Enum.empty?(accepts)
|
||||
end
|
||||
|
||||
test "it works for follow requests when you are already followed, creating a new accept activity" do
|
||||
|
|
|
|||
|
|
@ -636,4 +636,17 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert updated_object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_cached_emoji_reactions/1" do
|
||||
test "returns the data or an emtpy list" do
|
||||
object = insert(:note)
|
||||
assert Utils.get_cached_emoji_reactions(object) == []
|
||||
|
||||
object = insert(:note, data: %{"reactions" => [["x", ["lain"]]]})
|
||||
assert Utils.get_cached_emoji_reactions(object) == [["x", ["lain"]]]
|
||||
|
||||
object = insert(:note, data: %{"reactions" => %{}})
|
||||
assert Utils.get_cached_emoji_reactions(object) == []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,497 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.ConfigTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.AdminAPI.Config
|
||||
|
||||
test "get_by_key/1" do
|
||||
config = insert(:config)
|
||||
insert(:config)
|
||||
|
||||
assert config == Config.get_by_params(%{group: config.group, key: config.key})
|
||||
end
|
||||
|
||||
test "create/1" do
|
||||
{:ok, config} = Config.create(%{group: "pleroma", key: "some_key", value: "some_value"})
|
||||
assert config == Config.get_by_params(%{group: "pleroma", key: "some_key"})
|
||||
end
|
||||
|
||||
test "update/1" do
|
||||
config = insert(:config)
|
||||
{:ok, updated} = Config.update(config, %{value: "some_value"})
|
||||
loaded = Config.get_by_params(%{group: config.group, key: config.key})
|
||||
assert loaded == updated
|
||||
end
|
||||
|
||||
test "update_or_create/1" do
|
||||
config = insert(:config)
|
||||
key2 = "another_key"
|
||||
|
||||
params = [
|
||||
%{group: "pleroma", key: key2, value: "another_value"},
|
||||
%{group: config.group, key: config.key, value: "new_value"}
|
||||
]
|
||||
|
||||
assert Repo.all(Config) |> length() == 1
|
||||
|
||||
Enum.each(params, &Config.update_or_create(&1))
|
||||
|
||||
assert Repo.all(Config) |> length() == 2
|
||||
|
||||
config1 = Config.get_by_params(%{group: config.group, key: config.key})
|
||||
config2 = Config.get_by_params(%{group: "pleroma", key: key2})
|
||||
|
||||
assert config1.value == Config.transform("new_value")
|
||||
assert config2.value == Config.transform("another_value")
|
||||
end
|
||||
|
||||
test "delete/1" do
|
||||
config = insert(:config)
|
||||
{:ok, _} = Config.delete(%{key: config.key, group: config.group})
|
||||
refute Config.get_by_params(%{key: config.key, group: config.group})
|
||||
end
|
||||
|
||||
describe "transform/1" do
|
||||
test "string" do
|
||||
binary = Config.transform("value as string")
|
||||
assert binary == :erlang.term_to_binary("value as string")
|
||||
assert Config.from_binary(binary) == "value as string"
|
||||
end
|
||||
|
||||
test "boolean" do
|
||||
binary = Config.transform(false)
|
||||
assert binary == :erlang.term_to_binary(false)
|
||||
assert Config.from_binary(binary) == false
|
||||
end
|
||||
|
||||
test "nil" do
|
||||
binary = Config.transform(nil)
|
||||
assert binary == :erlang.term_to_binary(nil)
|
||||
assert Config.from_binary(binary) == nil
|
||||
end
|
||||
|
||||
test "integer" do
|
||||
binary = Config.transform(150)
|
||||
assert binary == :erlang.term_to_binary(150)
|
||||
assert Config.from_binary(binary) == 150
|
||||
end
|
||||
|
||||
test "atom" do
|
||||
binary = Config.transform(":atom")
|
||||
assert binary == :erlang.term_to_binary(:atom)
|
||||
assert Config.from_binary(binary) == :atom
|
||||
end
|
||||
|
||||
test "pleroma module" do
|
||||
binary = Config.transform("Pleroma.Bookmark")
|
||||
assert binary == :erlang.term_to_binary(Pleroma.Bookmark)
|
||||
assert Config.from_binary(binary) == Pleroma.Bookmark
|
||||
end
|
||||
|
||||
test "phoenix module" do
|
||||
binary = Config.transform("Phoenix.Socket.V1.JSONSerializer")
|
||||
assert binary == :erlang.term_to_binary(Phoenix.Socket.V1.JSONSerializer)
|
||||
assert Config.from_binary(binary) == Phoenix.Socket.V1.JSONSerializer
|
||||
end
|
||||
|
||||
test "sigil" do
|
||||
binary = Config.transform("~r/comp[lL][aA][iI][nN]er/")
|
||||
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
|
||||
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
|
||||
end
|
||||
|
||||
test "link sigil" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/
|
||||
end
|
||||
|
||||
test "link sigil with u modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/u")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/u)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/u
|
||||
end
|
||||
|
||||
test "link sigil with i modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/i")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/i
|
||||
end
|
||||
|
||||
test "link sigil with s modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/s")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/s
|
||||
end
|
||||
|
||||
test "2 child tuple" do
|
||||
binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
|
||||
assert binary == :erlang.term_to_binary({"v1", :v2})
|
||||
assert Config.from_binary(binary) == {"v1", :v2}
|
||||
end
|
||||
|
||||
test "tuple with n childs" do
|
||||
binary =
|
||||
Config.transform(%{
|
||||
"tuple" => [
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Bookmark",
|
||||
150,
|
||||
false,
|
||||
"Phoenix.Socket.V1.JSONSerializer"
|
||||
]
|
||||
})
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) ==
|
||||
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
|
||||
end
|
||||
|
||||
test "tuple with dispatch key" do
|
||||
binary = Config.transform(%{"tuple" => [":dispatch", ["{:_,
|
||||
[
|
||||
{\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{\"/websocket\", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: \"/websocket\"]}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]}"]]})
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
{:dispatch,
|
||||
[
|
||||
{:_,
|
||||
[
|
||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: "/websocket"]}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]}
|
||||
]}
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) ==
|
||||
{:dispatch,
|
||||
[
|
||||
{:_,
|
||||
[
|
||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: "/websocket"]}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]}
|
||||
]}
|
||||
end
|
||||
|
||||
test "map with string key" do
|
||||
binary = Config.transform(%{"key" => "value"})
|
||||
assert binary == :erlang.term_to_binary(%{"key" => "value"})
|
||||
assert Config.from_binary(binary) == %{"key" => "value"}
|
||||
end
|
||||
|
||||
test "map with atom key" do
|
||||
binary = Config.transform(%{":key" => "value"})
|
||||
assert binary == :erlang.term_to_binary(%{key: "value"})
|
||||
assert Config.from_binary(binary) == %{key: "value"}
|
||||
end
|
||||
|
||||
test "list of strings" do
|
||||
binary = Config.transform(["v1", "v2", "v3"])
|
||||
assert binary == :erlang.term_to_binary(["v1", "v2", "v3"])
|
||||
assert Config.from_binary(binary) == ["v1", "v2", "v3"]
|
||||
end
|
||||
|
||||
test "list of modules" do
|
||||
binary = Config.transform(["Pleroma.Repo", "Pleroma.Activity"])
|
||||
assert binary == :erlang.term_to_binary([Pleroma.Repo, Pleroma.Activity])
|
||||
assert Config.from_binary(binary) == [Pleroma.Repo, Pleroma.Activity]
|
||||
end
|
||||
|
||||
test "list of atoms" do
|
||||
binary = Config.transform([":v1", ":v2", ":v3"])
|
||||
assert binary == :erlang.term_to_binary([:v1, :v2, :v3])
|
||||
assert Config.from_binary(binary) == [:v1, :v2, :v3]
|
||||
end
|
||||
|
||||
test "list of mixed values" do
|
||||
binary =
|
||||
Config.transform([
|
||||
"v1",
|
||||
":v2",
|
||||
"Pleroma.Repo",
|
||||
"Phoenix.Socket.V1.JSONSerializer",
|
||||
15,
|
||||
false
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary([
|
||||
"v1",
|
||||
:v2,
|
||||
Pleroma.Repo,
|
||||
Phoenix.Socket.V1.JSONSerializer,
|
||||
15,
|
||||
false
|
||||
])
|
||||
|
||||
assert Config.from_binary(binary) == [
|
||||
"v1",
|
||||
:v2,
|
||||
Pleroma.Repo,
|
||||
Phoenix.Socket.V1.JSONSerializer,
|
||||
15,
|
||||
false
|
||||
]
|
||||
end
|
||||
|
||||
test "simple keyword" do
|
||||
binary = Config.transform([%{"tuple" => [":key", "value"]}])
|
||||
assert binary == :erlang.term_to_binary([{:key, "value"}])
|
||||
assert Config.from_binary(binary) == [{:key, "value"}]
|
||||
assert Config.from_binary(binary) == [key: "value"]
|
||||
end
|
||||
|
||||
test "keyword with partial_chain key" do
|
||||
binary =
|
||||
Config.transform([%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}])
|
||||
|
||||
assert binary == :erlang.term_to_binary(partial_chain: &:hackney_connect.partial_chain/1)
|
||||
assert Config.from_binary(binary) == [partial_chain: &:hackney_connect.partial_chain/1]
|
||||
end
|
||||
|
||||
test "keyword" do
|
||||
binary =
|
||||
Config.transform([
|
||||
%{"tuple" => [":types", "Pleroma.PostgresTypes"]},
|
||||
%{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]},
|
||||
%{"tuple" => [":migration_lock", nil]},
|
||||
%{"tuple" => [":key1", 150]},
|
||||
%{"tuple" => [":key2", "string"]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
types: Pleroma.PostgresTypes,
|
||||
telemetry_event: [Pleroma.Repo.Instrumenter],
|
||||
migration_lock: nil,
|
||||
key1: 150,
|
||||
key2: "string"
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) == [
|
||||
types: Pleroma.PostgresTypes,
|
||||
telemetry_event: [Pleroma.Repo.Instrumenter],
|
||||
migration_lock: nil,
|
||||
key1: 150,
|
||||
key2: "string"
|
||||
]
|
||||
end
|
||||
|
||||
test "complex keyword with nested mixed childs" do
|
||||
binary =
|
||||
Config.transform([
|
||||
%{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]},
|
||||
%{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]},
|
||||
%{"tuple" => [":link_name", true]},
|
||||
%{"tuple" => [":proxy_remote", false]},
|
||||
%{"tuple" => [":common_map", %{":key" => "value"}]},
|
||||
%{
|
||||
"tuple" => [
|
||||
":proxy_opts",
|
||||
[
|
||||
%{"tuple" => [":redirect_on_failure", false]},
|
||||
%{"tuple" => [":max_body_length", 1_048_576]},
|
||||
%{
|
||||
"tuple" => [
|
||||
":http",
|
||||
[%{"tuple" => [":follow_redirect", true]}, %{"tuple" => [":pool", ":upload"]}]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
uploader: Pleroma.Uploaders.Local,
|
||||
filters: [Pleroma.Upload.Filter.Dedupe],
|
||||
link_name: true,
|
||||
proxy_remote: false,
|
||||
common_map: %{key: "value"},
|
||||
proxy_opts: [
|
||||
redirect_on_failure: false,
|
||||
max_body_length: 1_048_576,
|
||||
http: [
|
||||
follow_redirect: true,
|
||||
pool: :upload
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) ==
|
||||
[
|
||||
uploader: Pleroma.Uploaders.Local,
|
||||
filters: [Pleroma.Upload.Filter.Dedupe],
|
||||
link_name: true,
|
||||
proxy_remote: false,
|
||||
common_map: %{key: "value"},
|
||||
proxy_opts: [
|
||||
redirect_on_failure: false,
|
||||
max_body_length: 1_048_576,
|
||||
http: [
|
||||
follow_redirect: true,
|
||||
pool: :upload
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
test "common keyword" do
|
||||
binary =
|
||||
Config.transform([
|
||||
%{"tuple" => [":level", ":warn"]},
|
||||
%{"tuple" => [":meta", [":all"]]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":val", nil]},
|
||||
%{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
level: :warn,
|
||||
meta: [:all],
|
||||
path: "",
|
||||
val: nil,
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) == [
|
||||
level: :warn,
|
||||
meta: [:all],
|
||||
path: "",
|
||||
val: nil,
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||
]
|
||||
end
|
||||
|
||||
test "complex keyword with sigil" do
|
||||
binary =
|
||||
Config.transform([
|
||||
%{"tuple" => [":federated_timeline_removal", []]},
|
||||
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
|
||||
%{"tuple" => [":replace", []]}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
federated_timeline_removal: [],
|
||||
reject: [~r/comp[lL][aA][iI][nN]er/],
|
||||
replace: []
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) ==
|
||||
[federated_timeline_removal: [], reject: [~r/comp[lL][aA][iI][nN]er/], replace: []]
|
||||
end
|
||||
|
||||
test "complex keyword with tuples with more than 2 values" do
|
||||
binary =
|
||||
Config.transform([
|
||||
%{
|
||||
"tuple" => [
|
||||
":http",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
":key1",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
[
|
||||
%{
|
||||
"tuple" => [
|
||||
"/api/v1/streaming",
|
||||
"Pleroma.Web.MastodonAPI.WebsocketHandler",
|
||||
[]
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
"/websocket",
|
||||
"Phoenix.Endpoint.CowboyWebSocket",
|
||||
%{
|
||||
"tuple" => [
|
||||
"Phoenix.Transports.WebSocket",
|
||||
%{
|
||||
"tuple" => [
|
||||
"Pleroma.Web.Endpoint",
|
||||
"Pleroma.Web.UserSocket",
|
||||
[]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
"Phoenix.Endpoint.Cowboy2Handler",
|
||||
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
assert binary ==
|
||||
:erlang.term_to_binary(
|
||||
http: [
|
||||
key1: [
|
||||
_: [
|
||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, []}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
assert Config.from_binary(binary) == [
|
||||
http: [
|
||||
key1: [
|
||||
{:_,
|
||||
[
|
||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||
{Phoenix.Transports.WebSocket,
|
||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, []}}},
|
||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||
]}
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -284,22 +284,22 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, %Activity{}, _} = CommonAPI.favorite(activity.id, user)
|
||||
end
|
||||
|
||||
test "retweeting a status twice returns an error" do
|
||||
test "retweeting a status twice returns the status" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, %Activity{}, _object} = CommonAPI.repeat(activity.id, user)
|
||||
{:error, _} = CommonAPI.repeat(activity.id, user)
|
||||
{:ok, %Activity{} = activity, object} = CommonAPI.repeat(activity.id, user)
|
||||
{:ok, ^activity, ^object} = CommonAPI.repeat(activity.id, user)
|
||||
end
|
||||
|
||||
test "favoriting a status twice returns an error" do
|
||||
test "favoriting a status twice returns the status" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, %Activity{}, _object} = CommonAPI.favorite(activity.id, user)
|
||||
{:error, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, %Activity{} = activity, object} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, ^activity, ^object} = CommonAPI.favorite(activity.id, user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil)
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 0
|
||||
assert Enum.empty?(cc)
|
||||
|
||||
assert mentioned_user.ap_id in to
|
||||
assert user.follower_address in to
|
||||
|
|
@ -323,7 +323,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
|
||||
|
||||
assert length(to) == 3
|
||||
assert length(cc) == 0
|
||||
assert Enum.empty?(cc)
|
||||
|
||||
assert mentioned_user.ap_id in to
|
||||
assert third_user.ap_id in to
|
||||
|
|
@ -338,7 +338,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct", nil)
|
||||
|
||||
assert length(to) == 1
|
||||
assert length(cc) == 0
|
||||
assert Enum.empty?(cc)
|
||||
|
||||
assert mentioned_user.ap_id in to
|
||||
end
|
||||
|
|
@ -353,7 +353,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
|
||||
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 0
|
||||
assert Enum.empty?(cc)
|
||||
|
||||
assert mentioned_user.ap_id in to
|
||||
assert third_user.ap_id in to
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
||||
|
||||
results =
|
||||
get(conn, "/api/v2/search", %{"q" => "2hu #private"})
|
||||
conn
|
||||
|> get("/api/v2/search", %{"q" => "2hu #private"})
|
||||
|> json_response(200)
|
||||
|
||||
[account | _] = results["accounts"]
|
||||
|
|
@ -73,6 +74,30 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
[status] = results["statuses"]
|
||||
assert status["id"] == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "excludes a blocked users from search results", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_smith = insert(:user, %{nickname: "Agent", name: "I love 2hu"})
|
||||
user_neo = insert(:user, %{nickname: "Agent Neo", name: "Agent"})
|
||||
|
||||
{:ok, act1} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"})
|
||||
{:ok, act2} = CommonAPI.post(user_smith, %{"status" => "Agent Smith"})
|
||||
{:ok, act3} = CommonAPI.post(user_neo, %{"status" => "Agent Smith"})
|
||||
Pleroma.User.block(user, user_smith)
|
||||
|
||||
results =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
|
||||
|> get("/api/v2/search", %{"q" => "Agent"})
|
||||
|> json_response(200)
|
||||
|
||||
status_ids = Enum.map(results["statuses"], fn g -> g["id"] end)
|
||||
|
||||
assert act3.id in status_ids
|
||||
refute act2.id in status_ids
|
||||
refute act1.id in status_ids
|
||||
end
|
||||
end
|
||||
|
||||
describe ".account_search" do
|
||||
|
|
@ -146,11 +171,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
||||
|
||||
conn =
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu"})
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
|> json_response(200)
|
||||
|
||||
[account | _] = results["accounts"]
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
|
|
@ -168,11 +192,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
"status" => "check out https://shitposter.club/notice/2827873"
|
||||
})
|
||||
|
||||
conn =
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
|> json_response(200)
|
||||
|
||||
[status, %{"id" => ^activity_id}] = results["statuses"]
|
||||
|
||||
|
|
@ -189,11 +212,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
})
|
||||
|
||||
capture_log(fn ->
|
||||
conn =
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]})
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
|> json_response(200)
|
||||
|
||||
[] = results["statuses"]
|
||||
end)
|
||||
|
|
@ -202,23 +224,23 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
test "search fetches remote accounts", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
results =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "true"})
|
||||
|> json_response(200)
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
[account] = results["accounts"]
|
||||
assert account["acct"] == "mike@osada.macgirvin.com"
|
||||
end
|
||||
|
||||
test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
|
||||
conn =
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "false"})
|
||||
|> json_response(200)
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
assert [] == results["accounts"]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -638,6 +638,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "favoriting twice will just return 200", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
post(conn, "/api/v1/statuses/#{activity.id}/favourite")
|
||||
assert post(conn, "/api/v1/statuses/#{activity.id}/favourite") |> json_response(200)
|
||||
end
|
||||
|
||||
test "returns 400 error for a wrong id", %{conn: conn} do
|
||||
conn = post(conn, "/api/v1/statuses/1/favourite")
|
||||
|
||||
|
|
|
|||
|
|
@ -134,4 +134,31 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
assert [expected] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: follower})
|
||||
end
|
||||
|
||||
test "EmojiReaction notification" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
|
||||
{:ok, _activity, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
|
||||
[notification] = Notification.for_user(user)
|
||||
|
||||
assert notification
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false},
|
||||
type: "pleroma:emoji_reaction",
|
||||
emoji: "☕",
|
||||
account: AccountView.render("show.json", %{user: other_user, for: user}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
NotificationView.render("show.json", %{notification: notification, for: user})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,6 +24,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "has an emoji reaction list" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "dae cofe??"})
|
||||
|
||||
{:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "☕")
|
||||
{:ok, _, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵")
|
||||
{:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
status = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert status[:pleroma][:emoji_reactions] == [
|
||||
%{emoji: "☕", count: 2},
|
||||
%{emoji: "🍵", count: 1}
|
||||
]
|
||||
end
|
||||
|
||||
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -172,7 +190,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
|
||||
expires_at: nil,
|
||||
direct_conversation_id: nil,
|
||||
thread_muted: false
|
||||
thread_muted: false,
|
||||
emoji_reactions: []
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,17 +57,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read:statuses"]))
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
|
||||
|> json_response(200)
|
||||
|
||||
assert result == %{}
|
||||
assert result == []
|
||||
|
||||
{:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
|
||||
|
||||
|
|
@ -76,7 +71,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
|> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
|
||||
|> json_response(200)
|
||||
|
||||
[represented_user] = result["🎅"]
|
||||
[%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result
|
||||
assert represented_user["id"] == other_user.id
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
|
||||
user = refresh_record(user)
|
||||
assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
|
||||
assert length(Token.get_user_tokens(user)) == 0
|
||||
assert Enum.empty?(Token.get_user_tokens(user))
|
||||
end
|
||||
|
||||
test "it sets password_reset_pending to false", %{conn: conn} do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue