Merge remote-tracking branch 'origin/develop' into translate-posts
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
commit
3893311bd2
81 changed files with 1362 additions and 170 deletions
1
test/fixtures/minds-invalid-mention-post.json
vendored
Normal file
1
test/fixtures/minds-invalid-mention-post.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":"https://www.w3.org/ns/activitystreams","type":"Note","id":"https://www.minds.com/api/activitypub/users/1198929502760083472/entities/urn:comment:1600926863310458883:0:0:0:1600932467852709903","attributedTo":"https://www.minds.com/api/activitypub/users/1198929502760083472","content":"\u003Ca class=\u0022u-url mention\u0022 href=\u0022https://www.minds.com/lain\u0022 target=\u0022_blank\u0022\u003E@lain\u003C/a\u003E corn syrup.","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://www.minds.com/api/activitypub/users/1198929502760083472/followers","https://lain.com/users/lain"],"tag":[{"type":"Mention","href":"https://www.minds.com/api/activitypub/users/464237775479123984","name":"@lain"}],"url":"https://www.minds.com/newsfeed/1600926863310458883?focusedCommentUrn=urn:comment:1600926863310458883:0:0:0:1600932467852709903","published":"2024-02-04T17:34:03+00:00","inReplyTo":"https://lain.com/objects/36254095-c839-4167-bcc2-b361d5de9198","source":{"content":"@lain corn syrup.","mediaType":"text/plain"}}
|
||||
1
test/fixtures/minds-pleroma-mentioned-post.json
vendored
Normal file
1
test/fixtures/minds-pleroma-mentioned-post.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://lain.com/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://lain.com/users/lain","attachment":[],"attributedTo":"https://lain.com/users/lain","cc":["https://lain.com/users/lain/followers"],"content":"which diet is the best for cognitive dissonance","context":"https://lain.com/contexts/98c8a130-e813-4797-8973-600e80114317","conversation":"https://lain.com/contexts/98c8a130-e813-4797-8973-600e80114317","id":"https://lain.com/objects/36254095-c839-4167-bcc2-b361d5de9198","published":"2024-02-04T17:11:23.931890Z","repliesCount":11,"sensitive":null,"source":{"content":"which diet is the best for cognitive dissonance","mediaType":"text/plain"},"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Note"}
|
||||
1
test/fixtures/tesla_mock/smithereen_non_anonymous_poll.json
vendored
Normal file
1
test/fixtures/tesla_mock/smithereen_non_anonymous_poll.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"type":"Question","id":"https://friends.grishka.me/posts/54642","attributedTo":"https://friends.grishka.me/users/1","content":"<p>здесь тоже можно что-то написать отдельно от опроса</p>","published":"2021-09-04T00:22:16Z","url":"https://friends.grishka.me/posts/54642","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://friends.grishka.me/users/1/followers"],"replies":{"type":"Collection","id":"https://friends.grishka.me/posts/54642/replies","first":{"type":"CollectionPage","items":[],"partOf":"https://friends.grishka.me/posts/54642/replies","next":"https://friends.grishka.me/posts/54642/replies?page=1"}},"sensitive":false,"likes":"https://friends.grishka.me/posts/54642/likes","name":"тестовый опрос","oneOf":[{"type":"Note","id":"https://friends.grishka.me/posts/54642#options/76","name":"тестовый ответ 1","replies":{"type":"Collection","id":"https://friends.grishka.me/activitypub/objects/polls/24/options/76/votes","totalItems":4,"items":[]}},{"type":"Note","id":"https://friends.grishka.me/posts/54642#options/77","name":"тестовый ответ 2","replies":{"type":"Collection","id":"https://friends.grishka.me/activitypub/objects/polls/24/options/77/votes","totalItems":4,"items":[]}},{"type":"Note","id":"https://friends.grishka.me/posts/54642#options/78","name":"тестовый ответ 3","replies":{"type":"Collection","id":"https://friends.grishka.me/activitypub/objects/polls/24/options/78/votes","totalItems":6,"items":[]}}],"votersCount":14,"nonAnonymous":true,"@context":["https://www.w3.org/ns/activitystreams",{"sensitive":"as:sensitive","toot":"http://joinmastodon.org/ns#","sm":"http://smithereen.software/ns#","votersCount":"toot:votersCount","nonAnonymous":"sm:nonAnonymous"}]}
|
||||
1
test/fixtures/tesla_mock/smithereen_user.json
vendored
Normal file
1
test/fixtures/tesla_mock/smithereen_user.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"type":"Person","id":"https://friends.grishka.me/users/1","name":"Григорий Клюшников","icon":{"type":"Image","image":{"type":"Image","url":"https://friends.grishka.me/i/6QLsOws97AWp5N_osd74C1IC1ijnFopyCBD9MSEeXNQ/q:93/bG9jYWw6Ly8vcy91cGxvYWRzL2F2YXRhcnMvNTYzODRhODEwODk5ZTRjMzI4YmY4YmQwM2Q2MWM3NmMud2VicA.jpg","mediaType":"image/jpeg","width":1280,"height":960},"width":573,"height":572,"cropRegion":[0.26422762870788574,0.3766937553882599,0.7113820910453796,0.9728997349739075],"url":"https://friends.grishka.me/i/ql_49PQcETAWgY_nC-Qj63H_Oa6FyOAEoWFkUSSkUvQ/c:573:572:nowe:338:362/q:93/bG9jYWw6Ly8vcy91cGxvYWRzL2F2YXRhcnMvNTYzODRhODEwODk5ZTRjMzI4YmY4YmQwM2Q2MWM3NmMud2VicA.jpg","mediaType":"image/jpeg"},"summary":"<p>Делаю эту хрень, пытаюсь вырвать социальные сети из жадных лап корпораций</p>\n<p></p>\n<p></p>\n<p></p>\n<p></p>\n<p></p>\n<p></p>\n<p></p>\n<p>This server does NOT support direct messages. Please write me <a href=\"https://t.me/grishka\">on Telegram</a> or <a href=\"https://matrix.to/#/@grishk:matrix.org\">Matrix</a>.</p>","url":"https://friends.grishka.me/grishka","preferredUsername":"grishka","inbox":"https://friends.grishka.me/users/1/inbox","outbox":"https://friends.grishka.me/users/1/outbox","followers":"https://friends.grishka.me/users/1/followers","following":"https://friends.grishka.me/users/1/following","endpoints":{"sharedInbox":"https://friends.grishka.me/activitypub/sharedInbox","collectionSimpleQuery":"https://friends.grishka.me/users/1/collectionQuery"},"publicKey":{"id":"https://friends.grishka.me/users/1#main-key","owner":"https://friends.grishka.me/users/1","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjlakm+i/d9ER/hIeR7KfiFW+SdLZj2SkKIeM8cmR+YFJuh9ghFqXrkFEjcaqUnAFqe5gYDNSQACnDLA8y4DnzjfGNIohKAnRoa9x6GORmfKQvcnjaTZ53S1NvUiPPyc0Pv/vfCtY/Ab0CEXe5BLqL38oZn817Jf7pBrPRTYH7m012kvwAUTT6k0Y8lPITBEG7nzYbbuGcrN9Y/RDdwE08jmBXlZ45bahRH3VNXVpQE17dCzJB+7k+iJ1R7YCoI+DuMlBYGXGE2KVk46NZTuLnOjFV9SyXfWX4/SrJM4oxev+SX2N75tQgmNZmVVHeqg2ZcbC0WCfNjJOi2HHS9MujwIDAQAB\n-----END PUBLIC KEY-----\n"},"wall":"https://friends.grishka.me/users/1/wall","firstName":"Григорий","lastName":"Клюшников","middleName":"Александрович","vcard:bday":"1993-01-22","gender":"http://schema.org#Male","supportsFriendRequests":true,"friends":"https://friends.grishka.me/users/1/friends","groups":"https://friends.grishka.me/users/1/groups","capabilities":{"supportsFriendRequests":true},"@context":["https://www.w3.org/ns/activitystreams",{"sm":"http://smithereen.software/ns#","cropRegion":{"@id":"sm:cropRegion","@container":"@list"},"wall":{"@id":"sm:wall","@type":"@id"},"collectionSimpleQuery":"sm:collectionSimpleQuery","sc":"http://schema.org#","firstName":"sc:givenName","lastName":"sc:familyName","middleName":"sc:additionalName","gender":{"@id":"sc:gender","@type":"sc:GenderType"},"maidenName":"sm:maidenName","friends":{"@id":"sm:friends","@type":"@id"},"groups":{"@id":"sm:groups","@type":"@id"},"vcard":"http://www.w3.org/2006/vcard/ns#","capabilities":"litepub:capabilities","supportsFriendRequests":"sm:supportsFriendRequests","litepub":"http://litepub.social/ns#"},"https://w3id.org/security/v1"]}
|
||||
60
test/pleroma/bookmark_folder_test.exs
Normal file
60
test/pleroma/bookmark_folder_test.exs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.BookmarkFolderTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.BookmarkFolder
|
||||
|
||||
describe "create/3" do
|
||||
test "with valid params" do
|
||||
user = insert(:user)
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Read later", "🕓")
|
||||
assert folder.user_id == user.id
|
||||
assert folder.name == "Read later"
|
||||
assert folder.emoji == "🕓"
|
||||
end
|
||||
|
||||
test "with invalid params" do
|
||||
{:error, changeset} = BookmarkFolder.create(nil, "", "not an emoji")
|
||||
refute changeset.valid?
|
||||
|
||||
assert changeset.errors == [
|
||||
emoji: {"Invalid emoji", []},
|
||||
user_id: {"can't be blank", [validation: :required]},
|
||||
name: {"can't be blank", [validation: :required]}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
test "update/3" do
|
||||
user = insert(:user)
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Read ltaer")
|
||||
{:ok, folder} = BookmarkFolder.update(folder.id, "Read later")
|
||||
assert folder.name == "Read later"
|
||||
end
|
||||
|
||||
test "for_user/1" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _} = BookmarkFolder.create(user.id, "Folder 1")
|
||||
{:ok, _} = BookmarkFolder.create(user.id, "Folder 2")
|
||||
{:ok, _} = BookmarkFolder.create(other_user.id, "Folder 3")
|
||||
|
||||
folders = BookmarkFolder.for_user(user.id)
|
||||
|
||||
assert length(folders) == 2
|
||||
end
|
||||
|
||||
test "belongs_to_user?/2" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Folder")
|
||||
|
||||
assert true == BookmarkFolder.belongs_to_user?(folder.id, user.id)
|
||||
assert false == BookmarkFolder.belongs_to_user?(folder.id, other_user.id)
|
||||
end
|
||||
end
|
||||
|
|
@ -6,15 +6,17 @@ defmodule Pleroma.BookmarkTest do
|
|||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.BookmarkFolder
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
describe "create/2" do
|
||||
describe "create/3" do
|
||||
test "with valid params" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
|
||||
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
||||
assert bookmark.user_id == user.id
|
||||
assert bookmark.activity_id == activity.id
|
||||
assert bookmark.folder_id == nil
|
||||
end
|
||||
|
||||
test "with invalid params" do
|
||||
|
|
@ -26,6 +28,19 @@ defmodule Pleroma.BookmarkTest do
|
|||
activity_id: {"can't be blank", [validation: :required]}
|
||||
]
|
||||
end
|
||||
|
||||
test "update existing bookmark folder" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
|
||||
|
||||
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
||||
assert bookmark.folder_id == nil
|
||||
|
||||
{:ok, bookmark_folder} = BookmarkFolder.create(user.id, "Read later")
|
||||
|
||||
{:ok, bookmark} = Bookmark.create(user.id, activity.id, bookmark_folder.id)
|
||||
assert bookmark.folder_id == bookmark_folder.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroy/2" do
|
||||
|
|
|
|||
|
|
@ -35,21 +35,6 @@ defmodule Pleroma.Search.DatabaseSearchTest do
|
|||
assert [] = Search.search(nil, "wednesday")
|
||||
end
|
||||
|
||||
test "using plainto_tsquery on postgres < 11" do
|
||||
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
|
||||
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
|
||||
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||
{:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
||||
|
||||
# plainto doesn't understand complex queries
|
||||
assert [result] = Search.search(nil, "wednesday -dudes")
|
||||
|
||||
assert result.id == post.id
|
||||
end
|
||||
|
||||
test "using websearch_to_tsquery" do
|
||||
user = insert(:user)
|
||||
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ defmodule Pleroma.User.BackupTest do
|
|||
|
||||
test "it creates a zip archive with user data" do
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
%{ap_id: other_ap_id} = other_user = insert(:user)
|
||||
|
||||
{:ok, %{object: %{data: %{"id" => id1}}} = status1} =
|
||||
CommonAPI.post(user, %{status: "status1"})
|
||||
|
|
@ -182,6 +183,8 @@ defmodule Pleroma.User.BackupTest do
|
|||
Bookmark.create(user.id, status2.id)
|
||||
Bookmark.create(user.id, status3.id)
|
||||
|
||||
CommonAPI.follow(user, other_user)
|
||||
|
||||
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||
assert {:ok, path} = Backup.export(backup, self())
|
||||
assert {:ok, zipfile} = :zip.zip_open(String.to_charlist(path), [:memory])
|
||||
|
|
@ -261,6 +264,16 @@ defmodule Pleroma.User.BackupTest do
|
|||
"type" => "OrderedCollection"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
assert {:ok, {'following.json', json}} = :zip.zip_get('following.json', zipfile)
|
||||
|
||||
assert %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "following.json",
|
||||
"orderedItems" => [^other_ap_id],
|
||||
"totalItems" => 1,
|
||||
"type" => "OrderedCollection"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
:zip.zip_close(zipfile)
|
||||
File.rm!(path)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2928,4 +2928,51 @@ defmodule Pleroma.UserTest do
|
|||
refute User.endorses?(user, pinned_user)
|
||||
end
|
||||
end
|
||||
|
||||
test "it checks fields links for a backlink" do
|
||||
user = insert(:user, ap_id: "https://social.example.org/users/lain")
|
||||
|
||||
fields = [
|
||||
%{"name" => "Link", "value" => "http://example.com/rel_me/null"},
|
||||
%{"name" => "Verified link", "value" => "http://example.com/rel_me/link"},
|
||||
%{"name" => "Not a link", "value" => "i'm not a link"}
|
||||
]
|
||||
|
||||
user
|
||||
|> User.update_and_set_cache(%{raw_fields: fields})
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert [
|
||||
%{"verified_at" => nil},
|
||||
%{"verified_at" => verified_at},
|
||||
%{"verified_at" => nil}
|
||||
] = user.fields
|
||||
|
||||
assert is_binary(verified_at)
|
||||
end
|
||||
|
||||
test "updating fields does not invalidate previously validated links" do
|
||||
user = insert(:user, ap_id: "https://social.example.org/users/lain")
|
||||
|
||||
user
|
||||
|> User.update_and_set_cache(%{
|
||||
raw_fields: [%{"name" => "verified link", "value" => "http://example.com/rel_me/link"}]
|
||||
})
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
%User{fields: [%{"verified_at" => verified_at}]} = user = User.get_cached_by_id(user.id)
|
||||
|
||||
user
|
||||
|> User.update_and_set_cache(%{
|
||||
raw_fields: [%{"name" => "Verified link", "value" => "http://example.com/rel_me/link"}]
|
||||
})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert [%{"verified_at" => ^verified_at}] = user.fields
|
||||
end
|
||||
end
|
||||
|
|
|
|||
73
test/pleroma/web/activity_pub/mrf/force_mention_test.exs
Normal file
73
test/pleroma/web/activity_pub/mrf/force_mention_test.exs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionTest do
|
||||
use Pleroma.DataCase
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.ForceMention
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "adds mention to a reply" do
|
||||
lain =
|
||||
insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false)
|
||||
|
||||
niobleoum =
|
||||
insert(:user,
|
||||
ap_id: "https://www.minds.com/api/activitypub/users/1198929502760083472",
|
||||
nickname: "niobleoum@minds.com",
|
||||
local: false
|
||||
)
|
||||
|
||||
status = File.read!("test/fixtures/minds-pleroma-mentioned-post.json") |> Jason.decode!()
|
||||
|
||||
status_activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => lain.ap_id,
|
||||
"object" => status
|
||||
}
|
||||
|
||||
Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity)
|
||||
|
||||
reply = File.read!("test/fixtures/minds-invalid-mention-post.json") |> Jason.decode!()
|
||||
|
||||
reply_activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => niobleoum.ap_id,
|
||||
"object" => reply
|
||||
}
|
||||
|
||||
{:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(reply_activity)
|
||||
|
||||
assert Enum.find(tag, fn %{"href" => href} -> href == lain.ap_id end)
|
||||
end
|
||||
|
||||
test "adds mention to a quote" do
|
||||
user1 = insert(:user, ap_id: "https://misskey.io/users/83ssedkv53")
|
||||
user2 = insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i")
|
||||
|
||||
status = File.read!("test/fixtures/tesla_mock/misskey.io_8vs6wxufd0.json") |> Jason.decode!()
|
||||
|
||||
status_activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => user1.ap_id,
|
||||
"object" => status
|
||||
}
|
||||
|
||||
Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity)
|
||||
|
||||
quote_post = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!()
|
||||
|
||||
quote_activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => user2.ap_id,
|
||||
"object" => quote_post
|
||||
}
|
||||
|
||||
{:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(quote_activity)
|
||||
|
||||
assert Enum.find(tag, fn %{"href" => href} -> href == user1.ap_id end)
|
||||
end
|
||||
end
|
||||
|
|
@ -25,6 +25,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
|
||||
describe "should_federate?/1" do
|
||||
test "it returns false when the inbox is nil" do
|
||||
refute Publisher.should_federate?(nil, false)
|
||||
refute Publisher.should_federate?(nil, true)
|
||||
end
|
||||
|
||||
test "it returns true when public is true" do
|
||||
assert Publisher.should_federate?(false, true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "gather_webfinger_links/1" do
|
||||
test "it returns links" do
|
||||
user = insert(:user)
|
||||
|
|
@ -205,6 +216,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
refute called(Instances.set_reachable(inbox))
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
|
||||
Instances,
|
||||
[:passthrough],
|
||||
|
|
|
|||
|
|
@ -91,6 +91,13 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
assert %{"alsoKnownAs" => ^akas} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "renders full nickname" do
|
||||
clear_config([Pleroma.Web.WebFinger, :domain], "plemora.dev")
|
||||
|
||||
user = insert(:user, nickname: "user")
|
||||
assert %{"webfinger" => "acct:user@plemora.dev"} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
describe "endpoints" do
|
||||
test "local users have a usable endpoints structure" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -107,6 +107,18 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "get instance contact information", %{conn: conn} do
|
||||
user = insert(:user, %{local: true})
|
||||
|
||||
clear_config([:instance, :contact_username], user.nickname)
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
|
||||
assert result = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert result["contact_account"]["id"] == user.id
|
||||
end
|
||||
|
||||
test "get instance information v2", %{conn: conn} do
|
||||
clear_config([:auth, :oauth_consumer_strategies], [])
|
||||
|
||||
|
|
|
|||
|
|
@ -322,26 +322,20 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
end
|
||||
|
||||
test "search fetches remote statuses and prefers them over other results", %{conn: conn} do
|
||||
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
|
||||
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
|
||||
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
|
||||
{:ok, %{id: activity_id}} =
|
||||
CommonAPI.post(insert(:user), %{
|
||||
status: "check out http://mastodon.example.org/@admin/99541947525187367"
|
||||
})
|
||||
|
||||
capture_log(fn ->
|
||||
{:ok, %{id: activity_id}} =
|
||||
CommonAPI.post(insert(:user), %{
|
||||
status: "check out http://mastodon.example.org/@admin/99541947525187367"
|
||||
})
|
||||
%{"url" => result_url, "id" => result_id} =
|
||||
conn
|
||||
|> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Map.get("statuses")
|
||||
|> List.first()
|
||||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [
|
||||
%{"url" => "http://mastodon.example.org/@admin/99541947525187367"},
|
||||
%{"id" => ^activity_id}
|
||||
] = results["statuses"]
|
||||
end)
|
||||
refute match?(^result_id, activity_id)
|
||||
assert match?(^result_url, "http://mastodon.example.org/@admin/99541947525187367")
|
||||
end
|
||||
|
||||
test "search doesn't show statuses that it shouldn't", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -1717,6 +1717,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
card_data = %{
|
||||
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
||||
"image_description" => "",
|
||||
"provider_name" => "example.com",
|
||||
"provider_url" => "https://example.com",
|
||||
"title" => "The Rock",
|
||||
|
|
@ -1770,6 +1771,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"title" => "Pleroma",
|
||||
"description" => "",
|
||||
"image" => nil,
|
||||
"image_description" => "",
|
||||
"provider_name" => "example.com",
|
||||
"provider_url" => "https://example.com",
|
||||
"url" => "https://example.com/ogp-missing-data",
|
||||
|
|
@ -1828,6 +1830,60 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
json_response_and_validate_schema(bookmarks, 200)
|
||||
end
|
||||
|
||||
test "bookmark folders" do
|
||||
%{conn: conn, user: user} = oauth_access(["write:bookmarks", "read:bookmarks"])
|
||||
|
||||
{:ok, folder} = Pleroma.BookmarkFolder.create(user.id, "folder")
|
||||
author = insert(:user)
|
||||
|
||||
folder_bookmarks_uri = "/api/v1/bookmarks?folder_id=#{folder.id}"
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(author, %{status: "heweoo?"})
|
||||
{:ok, activity2} = CommonAPI.post(author, %{status: "heweoo!"})
|
||||
|
||||
# Add bookmark with a folder
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity1.id}/bookmark", %{folder_id: folder.id})
|
||||
|
||||
assert json_response_and_validate_schema(response, 200)["bookmarked"] == true
|
||||
|
||||
assert json_response_and_validate_schema(response, 200)["pleroma"]["bookmark_folder"] ==
|
||||
folder.id
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity2.id}/bookmark")
|
||||
|
||||
assert json_response_and_validate_schema(response, 200)["bookmarked"] == true
|
||||
assert json_response_and_validate_schema(response, 200)["pleroma"]["bookmark_folder"] == nil
|
||||
|
||||
bookmarks =
|
||||
get(conn, folder_bookmarks_uri)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(bookmarks) == 1
|
||||
|
||||
# Update folder for existing bookmark
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity2.id}/bookmark", %{folder_id: folder.id})
|
||||
|
||||
assert json_response_and_validate_schema(response, 200)["bookmarked"] == true
|
||||
|
||||
assert json_response_and_validate_schema(response, 200)["pleroma"]["bookmark_folder"] ==
|
||||
folder.id
|
||||
|
||||
bookmarks =
|
||||
get(conn, folder_bookmarks_uri)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(bookmarks) == 2
|
||||
end
|
||||
|
||||
describe "conversation muting" do
|
||||
setup do: oauth_access(["write:mutes"])
|
||||
|
||||
|
|
|
|||
|
|
@ -511,10 +511,15 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account_data["fields"] == [
|
||||
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"},
|
||||
%{
|
||||
"name" => "<a href=\"http://google.com\">foo</a>",
|
||||
"value" => "bar",
|
||||
"verified_at" => nil
|
||||
},
|
||||
%{
|
||||
"name" => "link.io",
|
||||
"value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)
|
||||
"value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>),
|
||||
"verified_at" => nil
|
||||
}
|
||||
]
|
||||
|
||||
|
|
@ -573,8 +578,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account_data["fields"] == [
|
||||
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||
%{"name" => "they wins", "value" => ":blank:"}
|
||||
%{"name" => ":firefox:", "value" => "is best 2hu", "verified_at" => nil},
|
||||
%{"name" => "they wins", "value" => ":blank:", "verified_at" => nil}
|
||||
]
|
||||
|
||||
assert account_data["source"]["fields"] == [
|
||||
|
|
@ -602,10 +607,11 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "foo", "value" => "bar", "verified_at" => nil},
|
||||
%{
|
||||
"name" => "link",
|
||||
"value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>)
|
||||
"value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>),
|
||||
"verified_at" => nil
|
||||
}
|
||||
]
|
||||
|
||||
|
|
@ -627,7 +633,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => ""}
|
||||
%{"name" => "foo", "value" => "", "verified_at" => nil}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
%{title: "why are you even asking?", votes_count: 0}
|
||||
],
|
||||
votes_count: 0,
|
||||
voters_count: 0
|
||||
voters_count: 0,
|
||||
pleroma: %{non_anonymous: false}
|
||||
}
|
||||
|
||||
result = PollView.render("show.json", %{object: object})
|
||||
|
|
@ -165,4 +166,11 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
]
|
||||
} = PollView.render("show.json", %{object: object})
|
||||
end
|
||||
|
||||
test "that poll is non anonymous" do
|
||||
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
||||
result = PollView.render("show.json", %{object: object})
|
||||
|
||||
assert result[:pleroma][:non_anonymous] == true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -341,7 +341,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
emoji_reactions: [],
|
||||
parent_visible: false,
|
||||
pinned_at: nil,
|
||||
quotes_count: 0
|
||||
quotes_count: 0,
|
||||
bookmark_folder: nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -772,6 +773,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
page_url = "http://example.com"
|
||||
|
||||
card = %{
|
||||
"image:alt" => "Example image description",
|
||||
url: page_url,
|
||||
site_name: "Example site name",
|
||||
title: "Example website",
|
||||
|
|
@ -779,7 +781,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
description: "Example description"
|
||||
}
|
||||
|
||||
%{provider_name: "example.com"} =
|
||||
%{provider_name: "example.com", image_description: "Example image description"} =
|
||||
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
defmodule Pleroma.Web.PleromaAPI.BookmarkFolderControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.BookmarkFolder
|
||||
# alias Pleroma.Object
|
||||
# alias Pleroma.Tests.Helpers
|
||||
# alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
# alias Pleroma.User
|
||||
# alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
# alias Pleroma.Web.CommonAPI
|
||||
|
||||
# import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "GET /api/v1/pleroma/bookmark_folders" do
|
||||
setup do: oauth_access(["read:bookmarks"])
|
||||
|
||||
test "it lists bookmark folders", %{conn: conn, user: user} do
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Bookmark folder")
|
||||
|
||||
folder_id = folder.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/bookmark_folders")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^folder_id,
|
||||
"name" => "Bookmark folder",
|
||||
"emoji" => nil,
|
||||
"emoji_url" => nil
|
||||
}
|
||||
] = result
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/v1/pleroma/bookmark_folders" do
|
||||
setup do: oauth_access(["write:bookmarks"])
|
||||
|
||||
test "it creates a bookmark folder", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/bookmark_folders", %{
|
||||
name: "Bookmark folder",
|
||||
emoji: "📁"
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"name" => "Bookmark folder",
|
||||
"emoji" => "📁",
|
||||
"emoji_url" => nil
|
||||
} = result
|
||||
end
|
||||
|
||||
test "it creates a bookmark folder with custom emoji", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/bookmark_folders", %{
|
||||
name: "Bookmark folder",
|
||||
emoji: ":firefox:"
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"name" => "Bookmark folder",
|
||||
"emoji" => ":firefox:",
|
||||
"emoji_url" => "http://localhost:4001/emoji/Firefox.gif"
|
||||
} = result
|
||||
end
|
||||
|
||||
test "it returns error for invalid emoji", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/bookmark_folders", %{
|
||||
name: "Bookmark folder",
|
||||
emoji: "not an emoji"
|
||||
})
|
||||
|> json_response_and_validate_schema(422)
|
||||
|
||||
assert %{"error" => "Invalid emoji"} = result
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/v1/pleroma/bookmark_folders/:id" do
|
||||
setup do: oauth_access(["write:bookmarks"])
|
||||
|
||||
test "it updates a bookmark folder", %{conn: conn, user: user} do
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Bookmark folder")
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch("/api/v1/pleroma/bookmark_folders/#{folder.id}", %{
|
||||
name: "bookmark folder"
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"name" => "bookmark folder"
|
||||
} = result
|
||||
end
|
||||
|
||||
test "it returns error when updating others' folders", %{conn: conn} do
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, folder} = BookmarkFolder.create(other_user.id, "Bookmark folder")
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch("/api/v1/pleroma/bookmark_folders/#{folder.id}", %{
|
||||
name: "bookmark folder"
|
||||
})
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
assert %{
|
||||
"error" => "Access denied"
|
||||
} = result
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /api/v1/pleroma/bookmark_folders/:id" do
|
||||
setup do: oauth_access(["write:bookmarks"])
|
||||
|
||||
test "it deleting a bookmark folder", %{conn: conn, user: user} do
|
||||
{:ok, folder} = BookmarkFolder.create(user.id, "Bookmark folder")
|
||||
|
||||
assert conn
|
||||
|> delete("/api/v1/pleroma/bookmark_folders/#{folder.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
folders = BookmarkFolder.for_user(user.id)
|
||||
|
||||
assert length(folders) == 0
|
||||
end
|
||||
|
||||
test "it returns error when deleting others' folders", %{conn: conn} do
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, folder} = BookmarkFolder.create(other_user.id, "Bookmark folder")
|
||||
|
||||
result =
|
||||
conn
|
||||
|> patch("/api/v1/pleroma/bookmark_folders/#{folder.id}")
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
assert %{
|
||||
"error" => "Access denied"
|
||||
} = result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1503,6 +1503,24 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: "hello"}}
|
||||
end
|
||||
|
||||
def get("https://friends.grishka.me/posts/54642", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/smithereen_non_anonymous_poll.json"),
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://friends.grishka.me/users/1", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/smithereen_user.json"),
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
Code.put_compiler_option(:warnings_as_errors, true)
|
||||
|
||||
ExUnit.configure(max_cases: System.schedulers_online())
|
||||
|
||||
ExUnit.start(exclude: [:federated, :erratic])
|
||||
|
||||
if match?({:unix, :darwin}, :os.type()) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue