Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow...
[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) |> to_string
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/" xmlns:poco="http://portablecontacts.net/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 <link rel="self" href="#{OStatus.feed_path(user)}" />
31 <author>
32 #{user_xml}
33 </author>
34 <entry>
35 #{entry_xml}
36 </entry>
37 </feed>
38 """
39 assert clean(res) == clean(expected)
40 end
41
42 defp clean(string) do
43 String.replace(string, ~r/\s/, "")
44 end
45 end