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" assert feed.last_updated == ~U[2003-12-13 18:30:02Z] 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.creator == "John Doe" assert item.content == "Some text." end 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 test "parses atom entry with multiple authors" do data = File.read!("test/fixtures/atom/multi_author.xml") {true, parsed_data} = Atom.accepts(data, "application/atom+xml") assert {:ok, %FeedParser.Feed{items: items}} = Atom.parse_feed(parsed_data) assert [%FeedParser.Item{creator: "John Doe, Jane Doe"}] = items end test "parses ato item with multiple authors" do data = File.read!("test/fixtures/atom/multi_author_item.xml") {true, parsed_data} = Atom.accepts(data, "application/atom+xml") assert {:ok, %FeedParser.Feed{items: items}} = Atom.parse_feed(parsed_data) assert [%FeedParser.Item{creator: "John Doe, Jane Doe"}] = items end end