2019-07-10 05:13:23 +00:00
|
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-07-10 05:13:23 +00:00
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
2019-04-14 12:45:56 +00:00
|
|
|
|
defmodule Pleroma.BookmarkTest do
|
2020-12-21 11:21:40 +00:00
|
|
|
|
use Pleroma.DataCase, async: true
|
2019-04-14 12:45:56 +00:00
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
alias Pleroma.Bookmark
|
2024-02-26 22:45:02 +00:00
|
|
|
|
alias Pleroma.BookmarkFolder
|
2019-04-14 12:45:56 +00:00
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
2024-02-26 22:45:02 +00:00
|
|
|
|
describe "create/3" do
|
2019-04-14 12:45:56 +00:00
|
|
|
|
test "with valid params" do
|
|
|
|
|
user = insert(:user)
|
2020-05-12 19:59:26 +00:00
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
|
2019-04-14 12:45:56 +00:00
|
|
|
|
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
|
|
|
|
assert bookmark.user_id == user.id
|
|
|
|
|
assert bookmark.activity_id == activity.id
|
2024-02-26 22:45:02 +00:00
|
|
|
|
assert bookmark.folder_id == nil
|
2019-04-14 12:45:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "with invalid params" do
|
|
|
|
|
{:error, changeset} = Bookmark.create(nil, "")
|
|
|
|
|
refute changeset.valid?
|
|
|
|
|
|
|
|
|
|
assert changeset.errors == [
|
|
|
|
|
user_id: {"can't be blank", [validation: :required]},
|
|
|
|
|
activity_id: {"can't be blank", [validation: :required]}
|
|
|
|
|
]
|
|
|
|
|
end
|
2024-02-26 22:45:02 +00:00
|
|
|
|
|
|
|
|
|
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
|
2019-04-14 12:45:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "destroy/2" do
|
|
|
|
|
test "with valid params" do
|
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
|
2019-04-14 12:45:56 +00:00
|
|
|
|
{:ok, _bookmark} = Bookmark.create(user.id, activity.id)
|
|
|
|
|
|
|
|
|
|
{:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-27 20:06:46 +00:00
|
|
|
|
|
|
|
|
|
describe "get/2" do
|
|
|
|
|
test "gets a bookmark" do
|
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
|
CommonAPI.post(user, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
|
status:
|
2019-04-27 20:06:46 +00:00
|
|
|
|
"Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
|
|
|
|
assert bookmark == Bookmark.get(user.id, activity.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-14 12:45:56 +00:00
|
|
|
|
end
|