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.

62 lines
1.6KB

  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
  8. alias Pleroma.Object
  9. test "returns an object by it's AP id" do
  10. object = insert(:note)
  11. found_object = Object.get_by_ap_id(object.data["id"])
  12. assert object == found_object
  13. end
  14. describe "generic changeset" do
  15. test "it ensures uniqueness of the id" do
  16. object = insert(:note)
  17. cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
  18. assert cs.valid?
  19. {:error, _result} = Repo.insert(cs)
  20. end
  21. end
  22. describe "deletion function" do
  23. test "deletes an object" do
  24. object = insert(:note)
  25. found_object = Object.get_by_ap_id(object.data["id"])
  26. assert object == found_object
  27. Object.delete(found_object)
  28. found_object = Object.get_by_ap_id(object.data["id"])
  29. refute object == found_object
  30. assert found_object.data["type"] == "Tombstone"
  31. end
  32. test "ensures cache is cleared for the object" do
  33. object = insert(:note)
  34. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  35. assert object == cached_object
  36. Object.delete(cached_object)
  37. {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
  38. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  39. refute object == cached_object
  40. assert cached_object.data["type"] == "Tombstone"
  41. end
  42. end
  43. end