[#878] Tests improvements per code review.
[akkoma] / test / web / activity_pub / views / object_view_test.exs
1 defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
2 use Pleroma.DataCase
3 import Pleroma.Factory
4
5 alias Pleroma.Object
6 alias Pleroma.Web.ActivityPub.ObjectView
7 alias Pleroma.Web.CommonAPI
8
9 test "renders a note object" do
10 note = insert(:note)
11
12 result = ObjectView.render("object.json", %{object: note})
13
14 assert result["id"] == note.data["id"]
15 assert result["to"] == note.data["to"]
16 assert result["content"] == note.data["content"]
17 assert result["type"] == "Note"
18 assert result["@context"]
19 end
20
21 test "renders a note activity" do
22 note = insert(:note_activity)
23 object = Object.normalize(note)
24
25 result = ObjectView.render("object.json", %{object: note})
26
27 assert result["id"] == note.data["id"]
28 assert result["to"] == note.data["to"]
29 assert result["object"]["type"] == "Note"
30 assert result["object"]["content"] == object.data["content"]
31 assert result["type"] == "Create"
32 assert result["@context"]
33 end
34
35 test "renders a like activity" do
36 note = insert(:note_activity)
37 object = Object.normalize(note)
38 user = insert(:user)
39
40 {:ok, like_activity, _} = CommonAPI.favorite(note.id, user)
41
42 result = ObjectView.render("object.json", %{object: like_activity})
43
44 assert result["id"] == like_activity.data["id"]
45 assert result["object"] == object.data["id"]
46 assert result["type"] == "Like"
47 end
48
49 test "renders an announce activity" do
50 note = insert(:note_activity)
51 object = Object.normalize(note)
52 user = insert(:user)
53
54 {:ok, announce_activity, _} = CommonAPI.repeat(note.id, user)
55
56 result = ObjectView.render("object.json", %{object: announce_activity})
57
58 assert result["id"] == announce_activity.data["id"]
59 assert result["object"] == object.data["id"]
60 assert result["type"] == "Announce"
61 end
62 end