e252eca9f7cd63ed8791d44667f6b3f76d017b50
[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}
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 expected = """
22 <feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
23 <id>#{OStatus.feed_path(user)}</id>
24 <title>#{user.nickname}'s timeline</title>
25 <updated>#{most_recent_update}</updated>
26 <entries />
27 <link rel="hub" href="#{OStatus.pubsub_path}" />
28 <author>
29 #{user_xml}
30 </author>
31 </feed>
32 """
33 assert clean(res) == clean(expected)
34 end
35
36 defp clean(string) do
37 String.replace(string, ~r/\s/, "")
38 end
39 end