feed_parser/test/parser/jsonfeed_test.exs

27 lines
1004 B
Elixir
Raw Normal View History

2019-09-01 19:49:30 +00:00
defmodule FeedParser.Parser.JSONFeedTest do
use ExUnit.Case
alias FeedParser.Parser.JSONFeed
doctest JSONFeed
test "matches json feed" do
data = File.read!("test/fixtures/jsonfeed/feed.json")
assert {true, _} = JSONFeed.accepts(data, "application/json")
end
test "parses json feed" do
data = File.read!("test/fixtures/jsonfeed/feed.json")
{true, parsed_data} = JSONFeed.accepts(data, "application/json")
assert {:ok, %FeedParser.Feed{} = feed} = JSONFeed.parse_feed(parsed_data)
assert feed.title == "My Example Feed"
assert feed.site_url == "https://example.org/"
IO.inspect(feed.items)
assert [%FeedParser.Item{} = item2, %FeedParser.Item{} = item1] = feed.items
assert item2.guid == "2"
assert item2.content == "This is a second item."
assert item2.url == "https://example.org/second-item"
assert item1.guid == "1"
assert item1.content == "<p>Hello, world!</p>"
assert item1.url == "https://example.org/initial-post"
end
end