Merge branch 'feature/jobs' into 'develop'
[akkoma] / test / web / ostatus / feed_representer_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.User
9 alias Pleroma.Web.OStatus.ActivityRepresenter
10 alias Pleroma.Web.OStatus.FeedRepresenter
11 alias Pleroma.Web.OStatus.UserRepresenter
12 alias Pleroma.Web.OStatus
13
14 test "returns a feed of the last 20 items of the user" do
15 note_activity = insert(:note_activity)
16 user = User.get_cached_by_ap_id(note_activity.data["actor"])
17
18 tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
19
20 most_recent_update =
21 note_activity.updated_at
22 |> NaiveDateTime.to_iso8601()
23
24 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
25
26 user_xml =
27 UserRepresenter.to_simple_form(user)
28 |> :xmerl.export_simple_content(:xmerl_xml)
29
30 entry_xml =
31 ActivityRepresenter.to_simple_form(note_activity, user)
32 |> :xmerl.export_simple_content(:xmerl_xml)
33
34 expected = """
35 <feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
36 <id>#{OStatus.feed_path(user)}</id>
37 <title>#{user.nickname}'s timeline</title>
38 <updated>#{most_recent_update}</updated>
39 <logo>#{User.avatar_url(user)}</logo>
40 <link rel="hub" href="#{OStatus.pubsub_path(user)}" />
41 <link rel="salmon" href="#{OStatus.salmon_path(user)}" />
42 <link rel="self" href="#{OStatus.feed_path(user)}" type="application/atom+xml" />
43 <author>
44 #{user_xml}
45 </author>
46 <link rel="next" href="#{OStatus.feed_path(user)}?max_id=#{note_activity.id}" type="application/atom+xml" />
47 <entry>
48 #{entry_xml}
49 </entry>
50 </feed>
51 """
52
53 assert clean(res) == clean(expected)
54 end
55
56 defp clean(string) do
57 String.replace(string, ~r/\s/, "")
58 end
59 end