3d8eaac6e40dbed2a1f93b6173d2c012cd23405f
[akkoma] / test / web / ostatus / feed_representer_test.exs
1 defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
2 use Pleroma.DataCase
3 import Pleroma.Factory
4 alias Pleroma.User
5 alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
6 alias Pleroma.Web.OStatus
7
8 test "returns a feed of the last 20 items of the user" do
9 note_activity = insert(:note_activity)
10 user = User.get_cached_by_ap_id(note_activity.data["actor"])
11
12 tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
13
14 most_recent_update = note_activity.updated_at
15 |> NaiveDateTime.to_iso8601
16
17 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
18 user_xml = UserRepresenter.to_simple_form(user)
19 |> :xmerl.export_simple_content(:xmerl_xml)
20
21 entry_xml = ActivityRepresenter.to_simple_form(note_activity, user)
22 |> :xmerl.export_simple_content(:xmerl_xml)
23
24 expected = """
25 <feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
26 <id>#{OStatus.feed_path(user)}</id>
27 <title>#{user.nickname}'s timeline</title>
28 <updated>#{most_recent_update}</updated>
29 <link rel="hub" href="#{OStatus.pubsub_path(user)}" />
30 <author>
31 #{user_xml}
32 </author>
33 <entry>
34 #{entry_xml}
35 </entry>
36 </feed>
37 """
38 assert clean(res) == clean(expected)
39 end
40
41 defp clean(string) do
42 String.replace(string, ~r/\s/, "")
43 end
44 end