logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

bookmark_test.exs (1679B)


  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. defmodule Pleroma.BookmarkTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Bookmark
  8. alias Pleroma.Web.CommonAPI
  9. describe "create/2" do
  10. test "with valid params" do
  11. user = insert(:user)
  12. {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
  13. {:ok, bookmark} = Bookmark.create(user.id, activity.id)
  14. assert bookmark.user_id == user.id
  15. assert bookmark.activity_id == activity.id
  16. end
  17. test "with invalid params" do
  18. {:error, changeset} = Bookmark.create(nil, "")
  19. refute changeset.valid?
  20. assert changeset.errors == [
  21. user_id: {"can't be blank", [validation: :required]},
  22. activity_id: {"can't be blank", [validation: :required]}
  23. ]
  24. end
  25. end
  26. describe "destroy/2" do
  27. test "with valid params" do
  28. user = insert(:user)
  29. {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
  30. {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
  31. {:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
  32. end
  33. end
  34. describe "get/2" do
  35. test "gets a bookmark" do
  36. user = insert(:user)
  37. {:ok, activity} =
  38. CommonAPI.post(user, %{
  39. status:
  40. "Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
  41. })
  42. {:ok, bookmark} = Bookmark.create(user.id, activity.id)
  43. assert bookmark == Bookmark.get(user.id, activity.id)
  44. end
  45. end
  46. end