Fix queue name
[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.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
10 alias Pleroma.Web.OStatus
11
12 test "returns a feed of the last 20 items of the user" do
13 note_activity = insert(:note_activity)
14 user = User.get_cached_by_ap_id(note_activity.data["actor"])
15
16 tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
17
18 most_recent_update =
19 note_activity.updated_at
20 |> NaiveDateTime.to_iso8601()
21
22 res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
23
24 user_xml =
25 UserRepresenter.to_simple_form(user)
26 |> :xmerl.export_simple_content(:xmerl_xml)
27
28 entry_xml =
29 ActivityRepresenter.to_simple_form(note_activity, user)
30 |> :xmerl.export_simple_content(:xmerl_xml)
31
32 expected = """
33 <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">
34 <id>#{OStatus.feed_path(user)}</id>
35 <title>#{user.nickname}'s timeline</title>
36 <updated>#{most_recent_update}</updated>
37 <logo>#{User.avatar_url(user)}</logo>
38 <link rel="hub" href="#{OStatus.pubsub_path(user)}" />
39 <link rel="salmon" href="#{OStatus.salmon_path(user)}" />
40 <link rel="self" href="#{OStatus.feed_path(user)}" type="application/atom+xml" />
41 <author>
42 #{user_xml}
43 </author>
44 <link rel="next" href="#{OStatus.feed_path(user)}?max_id=#{note_activity.id}" type="application/atom+xml" />
45 <entry>
46 #{entry_xml}
47 </entry>
48 </feed>
49 """
50
51 assert clean(res) == clean(expected)
52 end
53
54 defp clean(string) do
55 String.replace(string, ~r/\s/, "")
56 end
57 end