Merge branch 'develop' into gun
[akkoma] / test / bookmark_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.BookmarkTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.Bookmark
9 alias Pleroma.Web.CommonAPI
10
11 describe "create/2" do
12 test "with valid params" do
13 user = insert(:user)
14 {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
15 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
16 assert bookmark.user_id == user.id
17 assert bookmark.activity_id == activity.id
18 end
19
20 test "with invalid params" do
21 {:error, changeset} = Bookmark.create(nil, "")
22 refute changeset.valid?
23
24 assert changeset.errors == [
25 user_id: {"can't be blank", [validation: :required]},
26 activity_id: {"can't be blank", [validation: :required]}
27 ]
28 end
29 end
30
31 describe "destroy/2" do
32 test "with valid params" do
33 user = insert(:user)
34
35 {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
36 {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
37
38 {:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
39 end
40 end
41
42 describe "get/2" do
43 test "gets a bookmark" do
44 user = insert(:user)
45
46 {:ok, activity} =
47 CommonAPI.post(user, %{
48 "status" =>
49 "Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
50 })
51
52 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
53 assert bookmark == Bookmark.get(user.id, activity.id)
54 end
55 end
56 end