Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3KB

  1. defmodule Pleroma.ObjectTest do
  2. use Pleroma.DataCase
  3. import Pleroma.Factory
  4. alias Pleroma.{Repo, Object}
  5. test "returns an object by it's AP id" do
  6. object = insert(:note)
  7. found_object = Object.get_by_ap_id(object.data["id"])
  8. assert object == found_object
  9. end
  10. describe "generic changeset" do
  11. test "it ensures uniqueness of the id" do
  12. object = insert(:note)
  13. cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
  14. assert cs.valid?
  15. {:error, _result} = Repo.insert(cs)
  16. end
  17. end
  18. describe "deletion function" do
  19. test "deletes an object" do
  20. object = insert(:note)
  21. found_object = Object.get_by_ap_id(object.data["id"])
  22. assert object == found_object
  23. Object.delete(found_object)
  24. found_object = Object.get_by_ap_id(object.data["id"])
  25. refute object == found_object
  26. end
  27. test "ensures cache is cleared for the object" do
  28. object = insert(:note)
  29. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  30. assert object == cached_object
  31. Object.delete(cached_object)
  32. {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
  33. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  34. refute object == cached_object
  35. end
  36. end
  37. end