Treat any present value in "no_attachment_links" as true
[akkoma] / test / object_test.exs
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
5 defmodule Pleroma.ObjectTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.{Repo, Object}
9
10 test "returns an object by it's AP id" do
11 object = insert(:note)
12 found_object = Object.get_by_ap_id(object.data["id"])
13
14 assert object == found_object
15 end
16
17 describe "generic changeset" do
18 test "it ensures uniqueness of the id" do
19 object = insert(:note)
20 cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
21 assert cs.valid?
22
23 {:error, _result} = Repo.insert(cs)
24 end
25 end
26
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
32 assert object == found_object
33
34 Object.delete(found_object)
35
36 found_object = Object.get_by_ap_id(object.data["id"])
37
38 refute object == found_object
39 end
40
41 test "ensures cache is cleared for the object" do
42 object = insert(:note)
43 cached_object = Object.get_cached_by_ap_id(object.data["id"])
44
45 assert object == cached_object
46
47 Object.delete(cached_object)
48
49 {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
50
51 cached_object = Object.get_cached_by_ap_id(object.data["id"])
52
53 refute object == cached_object
54 end
55 end
56 end