Merge remote-tracking branch 'origin/develop' into instance_rules
This commit is contained in:
commit
01a5f839c5
39 changed files with 871 additions and 96 deletions
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"})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1828,6 +1828,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"])
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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