2019-02-27 16:28:09 +01:00
|
|
|
defmodule MobilizonWeb.FeedControllerTest do
|
|
|
|
use MobilizonWeb.ConnCase
|
|
|
|
import Mobilizon.Factory
|
2019-03-01 12:57:22 +01:00
|
|
|
alias MobilizonWeb.Router.Helpers, as: Routes
|
|
|
|
alias MobilizonWeb.Endpoint
|
2019-02-27 16:28:09 +01:00
|
|
|
|
|
|
|
describe "/@:preferred_username.atom" do
|
|
|
|
test "it returns an RSS representation of the actor's public events", %{conn: conn} do
|
|
|
|
actor = insert(:actor)
|
2019-03-01 12:57:22 +01:00
|
|
|
tag1 = insert(:tag, title: "RSS", slug: "rss")
|
|
|
|
tag2 = insert(:tag, title: "ATOM", slug: "atom")
|
|
|
|
event1 = insert(:event, organizer_actor: actor, tags: [tag1])
|
|
|
|
event2 = insert(:event, organizer_actor: actor, tags: [tag1, tag2])
|
2019-02-27 16:28:09 +01:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
2019-03-01 12:57:22 +01:00
|
|
|
|> get(
|
|
|
|
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom")
|
|
|
|
|> URI.decode()
|
|
|
|
)
|
2019-02-27 16:28:09 +01:00
|
|
|
|
|
|
|
assert response(conn, 200) =~ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
|
|
|
assert response_content_type(conn, :xml) =~ "charset=utf-8"
|
|
|
|
|
2019-03-01 12:57:22 +01:00
|
|
|
{:ok, feed} = ElixirFeedParser.parse(conn.resp_body)
|
2019-02-27 16:28:09 +01:00
|
|
|
|
|
|
|
assert feed.title == actor.preferred_username <> "'s public events feed"
|
|
|
|
|
2019-03-01 12:57:22 +01:00
|
|
|
[entry1, entry2] = entries = feed.entries
|
|
|
|
|
|
|
|
Enum.each(entries, fn entry ->
|
2019-02-27 16:28:09 +01:00
|
|
|
assert entry.title in [event1.title, event2.title]
|
|
|
|
end)
|
2019-03-01 12:57:22 +01:00
|
|
|
|
|
|
|
assert entry1.categories == [tag2.slug, tag1.slug]
|
|
|
|
assert entry2.categories == [tag1.slug]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns an RSS representation of the actor's public events with the proper accept header",
|
|
|
|
%{conn: conn} do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "application/atom+xml")
|
|
|
|
|> get(
|
|
|
|
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom")
|
|
|
|
|> URI.decode()
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response(conn, 200) =~ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
|
|
|
assert response_content_type(conn, :xml) =~ "charset=utf-8"
|
2019-02-27 16:28:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it doesn't return anything for an not existing actor", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "application/atom+xml")
|
2019-03-01 12:57:22 +01:00
|
|
|
|> get("/@notexistent/feed/atom")
|
2019-02-27 16:28:09 +01:00
|
|
|
|
2019-03-01 12:57:22 +01:00
|
|
|
assert response(conn, 404)
|
2019-02-27 16:28:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|