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.

61 lines
1.5KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ObjectTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.{Repo, Object}
  8. test "returns an object by it's AP id" do
  9. object = insert(:note)
  10. found_object = Object.get_by_ap_id(object.data["id"])
  11. assert object == found_object
  12. end
  13. describe "generic changeset" do
  14. test "it ensures uniqueness of the id" do
  15. object = insert(:note)
  16. cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
  17. assert cs.valid?
  18. {:error, _result} = Repo.insert(cs)
  19. end
  20. end
  21. describe "deletion function" do
  22. test "deletes an object" do
  23. object = insert(:note)
  24. found_object = Object.get_by_ap_id(object.data["id"])
  25. assert object == found_object
  26. Object.delete(found_object)
  27. found_object = Object.get_by_ap_id(object.data["id"])
  28. refute object == found_object
  29. assert found_object.data["type"] == "Tombstone"
  30. end
  31. test "ensures cache is cleared for the object" do
  32. object = insert(:note)
  33. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  34. assert object == cached_object
  35. Object.delete(cached_object)
  36. {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
  37. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  38. refute object == cached_object
  39. assert cached_object.data["type"] == "Tombstone"
  40. end
  41. end
  42. end