1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
|