Add OPML tests
This commit is contained in:
parent
dffd653738
commit
5f3be52132
|
@ -23,7 +23,7 @@ defmodule Frenzy.OPML.Importer do
|
|||
outline_elements
|
||||
|> Enum.flat_map(&get_feeds/1)
|
||||
|> Enum.reduce(%{}, fn {group, feed_url}, acc ->
|
||||
Map.update(acc, group, [], fn feeds -> [feed_url | feeds] end)
|
||||
Map.update(acc, group, [feed_url], fn feeds -> [feed_url | feeds] end)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
defmodule Frenzy.OPML.ExporterTest do
|
||||
use ExUnit.Case
|
||||
alias Frenzy.OPML.Exporter
|
||||
alias Frenzy.{Feed, Group}
|
||||
doctest Exporter
|
||||
|
||||
test "export groups" do
|
||||
res =
|
||||
Exporter.export([
|
||||
%Group{
|
||||
title: "Group 1",
|
||||
feeds: [
|
||||
%Feed{
|
||||
feed_url: "https://shadowfacts.net/feed.xml",
|
||||
site_url: "https://shadowfacts.net/",
|
||||
title: "Shadowfacts"
|
||||
}
|
||||
]
|
||||
},
|
||||
%Group{
|
||||
title: "Group 2",
|
||||
feeds: [
|
||||
%Feed{
|
||||
feed_url: "some other url",
|
||||
site_url: "my site",
|
||||
title: "the title"
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
assert res ==
|
||||
"""
|
||||
<opml version="1.0">
|
||||
<head>
|
||||
<title>Frenzy export</title>
|
||||
</head>
|
||||
<body>
|
||||
<outline text="Group 1" title="Group 1">
|
||||
<outline htmlUrl="https://shadowfacts.net/" text="Shadowfacts" title="Shadowfacts" type="rss" xmlUrl="https://shadowfacts.net/feed.xml"/>
|
||||
</outline>
|
||||
<outline text="Group 2" title="Group 2">
|
||||
<outline htmlUrl="my site" text="the title" title="the title" type="rss" xmlUrl="some other url"/>
|
||||
</outline>
|
||||
</body>
|
||||
</opml>
|
||||
"""
|
||||
|> String.trim()
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
defmodule Frenzy.OPML.ImporterTests do
|
||||
use ExUnit.Case
|
||||
alias Frenzy.OPML.Importer
|
||||
doctest Importer
|
||||
|
||||
@opml """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- OPML generated by NetNewsWire -->
|
||||
<opml version="1.1">
|
||||
<head>
|
||||
<title>Subscriptions-OnMyMac.opml</title>
|
||||
</head>
|
||||
<body>
|
||||
<outline text="Julia Evans" title="Julia Evans" description="" type="rss" version="RSS" htmlUrl="" xmlUrl="https://jvns.ca/atom.xml"/>
|
||||
<outline text="my folder" title="my folder">
|
||||
<outline text="The Shape of Everything" title="The Shape of Everything" description="" type="rss" version="RSS" htmlUrl="https://shapeof.com/" xmlUrl="https://shapeof.com/feed.json"/>
|
||||
</outline>
|
||||
</body>
|
||||
</opml>
|
||||
"""
|
||||
|
||||
test "parse simple OPML" do
|
||||
res = Importer.parse_opml(@opml)
|
||||
|
||||
assert res == %{
|
||||
:default => ["https://jvns.ca/atom.xml"],
|
||||
"my folder" => ["https://shapeof.com/feed.json"]
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue