aboutsummaryrefslogtreecommitdiff
path: root/test/pleroma/bookmark_folder_test.exs
blob: c45129b0e7fd1fd50193bc6a168d4887fb30948f (plain) (blame)
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
# 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