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 Cachex.put(:web_resp_cache, URI.parse(object.data["id"]).path, "cofe")
58 Object.delete(cached_object)
60 {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
61 {:ok, nil} = Cachex.get(:web_resp_cache, URI.parse(object.data["id"]).path)
63 cached_object = Object.get_cached_by_ap_id(object.data["id"])
65 refute object == cached_object
67 assert cached_object.data["type"] == "Tombstone"
71 describe "normalizer" do
72 test "fetches unknown objects by default" do
74 object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
76 assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
79 test "fetches unknown objects when fetch_remote is explicitly true" do
81 object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
83 assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
86 test "does not fetch unknown objects when fetch_remote is false" do
88 Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)