1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.BookmarkFolderTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.BookmarkFolder
10 describe "create/3" do
11 test "with valid params" do
13 {:ok, folder} = BookmarkFolder.create(user.id, "Read later", "🕓")
14 assert folder.user_id == user.id
15 assert folder.name == "Read later"
16 assert folder.emoji == "🕓"
19 test "with invalid params" do
20 {:error, changeset} = BookmarkFolder.create(nil, "", "not an emoji")
21 refute changeset.valid?
23 assert changeset.errors == [
24 emoji: {"Invalid emoji", []},
25 user_id: {"can't be blank", [validation: :required]},
26 name: {"can't be blank", [validation: :required]}
33 {:ok, folder} = BookmarkFolder.create(user.id, "Read ltaer")
34 {:ok, folder} = BookmarkFolder.update(folder.id, "Read later")
35 assert folder.name == "Read later"
40 other_user = insert(:user)
42 {:ok, _} = BookmarkFolder.create(user.id, "Folder 1")
43 {:ok, _} = BookmarkFolder.create(user.id, "Folder 2")
44 {:ok, _} = BookmarkFolder.create(other_user.id, "Folder 3")
46 folders = BookmarkFolder.for_user(user.id)
48 assert length(folders) == 2
51 test "belongs_to_user?/2" do
53 other_user = insert(:user)
55 {:ok, folder} = BookmarkFolder.create(user.id, "Folder")
57 assert true == BookmarkFolder.belongs_to_user?(folder.id, user.id)
58 assert false == BookmarkFolder.belongs_to_user?(folder.id, other_user.id)