feed_representer_test.exs 1.71 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
  use Pleroma.DataCase
  import Pleroma.Factory
  alias Pleroma.User
lain's avatar
lain committed
5
  alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
lain's avatar
lain committed
6
7
8
9
10
11
12
13
14
15
16
  alias Pleroma.Web.OStatus

  test "returns a feed of the last 20 items of the user" do
    note_activity = insert(:note_activity)
    user = User.get_cached_by_ap_id(note_activity.data["actor"])

    tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])

    most_recent_update = note_activity.updated_at
    |> NaiveDateTime.to_iso8601

lain's avatar
lain committed
17
    res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
lain's avatar
lain committed
18
19
20
    user_xml = UserRepresenter.to_simple_form(user)
    |> :xmerl.export_simple_content(:xmerl_xml)

lain's avatar
lain committed
21
22
23
    entry_xml = ActivityRepresenter.to_simple_form(note_activity, user)
    |> :xmerl.export_simple_content(:xmerl_xml)

lain's avatar
lain committed
24
    expected = """
25
    <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">
lain's avatar
lain committed
26
27
28
      <id>#{OStatus.feed_path(user)}</id>
      <title>#{user.nickname}'s timeline</title>
      <updated>#{most_recent_update}</updated>
lain's avatar
lain committed
29
      <logo>#{User.avatar_url(user)}</logo>
lain's avatar
lain committed
30
      <link rel="hub" href="#{OStatus.pubsub_path(user)}" />
31
      <link rel="salmon" href="#{OStatus.salmon_path(user)}" />
lain's avatar
lain committed
32
      <link rel="self" href="#{OStatus.feed_path(user)}" type="application/atom+xml" />
lain's avatar
lain committed
33
34
35
      <author>
        #{user_xml}
      </author>
lain's avatar
lain committed
36
37
38
      <entry>
        #{entry_xml}
      </entry>
lain's avatar
lain committed
39
40
41
42
43
44
45
46
47
    </feed>
    """
    assert clean(res) == clean(expected)
  end

  defp clean(string) do
    String.replace(string, ~r/\s/, "")
  end
end