Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

90 lignes
2.4KB

  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. import Tesla.Mock
  8. alias Pleroma.Object
  9. alias Pleroma.Repo
  10. setup do
  11. mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
  12. :ok
  13. end
  14. test "returns an object by it's AP id" do
  15. object = insert(:note)
  16. found_object = Object.get_by_ap_id(object.data["id"])
  17. assert object == found_object
  18. end
  19. describe "generic changeset" do
  20. test "it ensures uniqueness of the id" do
  21. object = insert(:note)
  22. cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
  23. assert cs.valid?
  24. {:error, _result} = Repo.insert(cs)
  25. end
  26. end
  27. describe "deletion function" do
  28. test "deletes an object" do
  29. object = insert(:note)
  30. found_object = Object.get_by_ap_id(object.data["id"])
  31. assert object == found_object
  32. Object.delete(found_object)
  33. found_object = Object.get_by_ap_id(object.data["id"])
  34. refute object == found_object
  35. assert found_object.data["type"] == "Tombstone"
  36. end
  37. test "ensures cache is cleared for the object" do
  38. object = insert(:note)
  39. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  40. assert object == cached_object
  41. Object.delete(cached_object)
  42. {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
  43. cached_object = Object.get_cached_by_ap_id(object.data["id"])
  44. refute object == cached_object
  45. assert cached_object.data["type"] == "Tombstone"
  46. end
  47. end
  48. describe "normalizer" do
  49. test "fetches unknown objects by default" do
  50. %Object{} =
  51. object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
  52. assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
  53. end
  54. test "fetches unknown objects when fetch_remote is explicitly true" do
  55. %Object{} =
  56. object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
  57. assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
  58. end
  59. test "does not fetch unknown objects when fetch_remote is false" do
  60. assert is_nil(
  61. Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)
  62. )
  63. end
  64. end
  65. end