feed_parser/test/parser/atom_test.exs

44 lines
1.7 KiB
Elixir
Raw Normal View History

2019-09-01 19:49:30 +00:00
defmodule FeedParser.Parser.AtomTest do
use ExUnit.Case
alias FeedParser.Parser.Atom
doctest Atom
test "matches atom feed" do
data = File.read!("test/fixtures/atom/feed.xml")
assert {true, _} = Atom.accepts(data, "application/atom+xml")
assert {true, _} = Atom.accepts(data, "application/xml")
end
test "parses atom feed" do
data = File.read!("test/fixtures/atom/feed.xml")
{true, parsed_data} = Atom.accepts(data, "application/atom+xml")
assert {:ok, %FeedParser.Feed{} = feed} = Atom.parse_feed(parsed_data)
assert feed.site_url == "http://example.org/"
assert feed.title == "Example Feed"
2019-09-01 20:11:13 +00:00
assert feed.last_updated == ~U[2003-12-13 18:30:02Z]
2019-09-01 19:49:30 +00:00
assert [%FeedParser.Item{} = item] = feed.items
assert item.guid == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
assert item.title == "Atom-Powered Robots Run Amok"
assert item.url == "http://example.org/2003/12/13/atom03"
assert item.date == ~U[2003-12-13 18:30:02Z]
assert item.content == "Some text."
end
2019-09-01 20:32:36 +00:00
test "parses atom entry with multiple links" do
data = File.read!("test/fixtures/atom/multi_url.xml")
{true, parsed_data} = Atom.accepts(data, "application/atom+xml")
{:ok, %FeedParser.Feed{} = feed} = Atom.parse_feed(parsed_data)
[item] = feed.items
assert item.url ==
"https://techcrunch.com/2019/08/30/someone-hacked-jack-dorseys-own-twitter-account/"
assert item.links == [
{"https://techcrunch.com/2019/08/30/someone-hacked-jack-dorseys-own-twitter-account/",
"alternate"},
{"http://df4.us/rrx", "shorturl"},
{"https://daringfireball.net/linked/2019/08/30/dorsey-twitter-account", "related"}
]
end
2019-09-01 19:49:30 +00:00
end