1 defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
4 alias Pleroma.Web.OStatus.ActivityRepresenter
5 alias Pleroma.{User, Activity}
9 test "a note activity" do
10 note_activity = insert(:note_activity)
11 updated_at = note_activity.updated_at
12 |> NaiveDateTime.to_iso8601
13 inserted_at = note_activity.inserted_at
14 |> NaiveDateTime.to_iso8601
16 user = User.get_cached_by_ap_id(note_activity.data["actor"])
19 <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
20 <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
21 <id>#{note_activity.data["object"]["id"]}</id>
22 <title>New note by #{user.nickname}</title>
23 <content type="html">#{note_activity.data["object"]["content"]}</content>
24 <published>#{inserted_at}</published>
25 <updated>#{updated_at}</updated>
26 <ostatus:conversation>#{note_activity.data["context"]}</ostatus:conversation>
27 <link href="#{note_activity.data["context"]}" rel="ostatus:conversation" />
28 <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
31 tuple = ActivityRepresenter.to_simple_form(note_activity, user)
33 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
35 assert clean(res) == clean(expected)
38 test "a reply note" do
39 note = insert(:note_activity)
40 answer = insert(:note_activity)
41 object = answer.data["object"]
42 object = Map.put(object, "inReplyTo", note.data["object"]["id"])
44 data = %{answer.data | "object" => object}
45 answer = %{answer | data: data}
47 updated_at = answer.updated_at
48 |> NaiveDateTime.to_iso8601
49 inserted_at = answer.inserted_at
50 |> NaiveDateTime.to_iso8601
52 user = User.get_cached_by_ap_id(answer.data["actor"])
55 <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
56 <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
57 <id>#{answer.data["object"]["id"]}</id>
58 <title>New note by #{user.nickname}</title>
59 <content type="html">#{answer.data["object"]["content"]}</content>
60 <published>#{inserted_at}</published>
61 <updated>#{updated_at}</updated>
62 <ostatus:conversation>#{answer.data["context"]}</ostatus:conversation>
63 <link href="#{answer.data["context"]}" rel="ostatus:conversation" />
64 <thr:in-reply-to ref="#{note.data["object"]["id"]}" />
65 <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
68 tuple = ActivityRepresenter.to_simple_form(answer, user)
70 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
72 assert clean(res) == clean(expected)
75 test "an unknown activity" do
76 tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
81 String.replace(string, ~r/\s/, "")