1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ObjectTest do
13 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 test "returns an object by it's AP id" do
18 object = insert(:note)
19 found_object = Object.get_by_ap_id(object.data["id"])
21 assert object == found_object
24 describe "generic changeset" do
25 test "it ensures uniqueness of the id" do
26 object = insert(:note)
27 cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
30 {:error, _result} = Repo.insert(cs)
34 describe "deletion function" do
35 test "deletes an object" do
36 object = insert(:note)
37 found_object = Object.get_by_ap_id(object.data["id"])
39 assert object == found_object
41 Object.delete(found_object)
43 found_object = Object.get_by_ap_id(object.data["id"])
45 refute object == found_object
47 assert found_object.data["type"] == "Tombstone"
50 test "ensures cache is cleared for the object" do
51 object = insert(:note)
52 cached_object = Object.get_cached_by_ap_id(object.data["id"])
54 assert object == cached_object
56 Object.delete(cached_object)
58 {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
60 cached_object = Object.get_cached_by_ap_id(object.data["id"])
62 refute object == cached_object
64 assert cached_object.data["type"] == "Tombstone"
68 describe "normalizer" do
69 test "fetches unknown objects by default" do
71 object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
73 assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
76 test "fetches unknown objects when fetch_remote is explicitly true" do
78 object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
80 assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
83 test "does not fetch unknown objects when fetch_remote is false" do
85 Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)