Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow...
[akkoma] / test / web / ostatus / activity_representer_test.exs
1 defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.Web.OStatus.ActivityRepresenter
5 alias Pleroma.{User, Activity}
6
7 import Pleroma.Factory
8
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
15
16 user = User.get_cached_by_ap_id(note_activity.data["actor"])
17
18 expected = """
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 """
27
28 tuple = ActivityRepresenter.to_simple_form(note_activity, user)
29
30 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
31
32 assert clean(res) == clean(expected)
33 end
34
35 test "an unknown activity" do
36 tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
37 assert is_nil(tuple)
38 end
39
40 defp clean(string) do
41 String.replace(string, ~r/\s/, "")
42 end
43 end