1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.BookmarkTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.BookmarkFolder
10 alias Pleroma.Web.CommonAPI
12 describe "create/3" do
13 test "with valid params" do
15 {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
16 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
17 assert bookmark.user_id == user.id
18 assert bookmark.activity_id == activity.id
19 assert bookmark.folder_id == nil
22 test "with invalid params" do
23 {:error, changeset} = Bookmark.create(nil, "")
24 refute changeset.valid?
26 assert changeset.errors == [
27 user_id: {"can't be blank", [validation: :required]},
28 activity_id: {"can't be blank", [validation: :required]}
32 test "update existing bookmark folder" do
34 {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
36 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
37 assert bookmark.folder_id == nil
39 {:ok, bookmark_folder} = BookmarkFolder.create(user.id, "Read later")
41 {:ok, bookmark} = Bookmark.create(user.id, activity.id, bookmark_folder.id)
42 assert bookmark.folder_id == bookmark_folder.id
46 describe "destroy/2" do
47 test "with valid params" do
50 {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
51 {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
53 {:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
58 test "gets a bookmark" do
62 CommonAPI.post(user, %{
64 "Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
67 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
68 assert bookmark == Bookmark.get(user.id, activity.id)