From 5f3be5213254446c83672d1c6796d01c1d20ff6e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 19 Jul 2020 11:33:55 -0400 Subject: [PATCH] Add OPML tests --- lib/frenzy/opml/importer.ex | 2 +- test/frenzy/opml/exporter_test.exs | 50 ++++++++++++++++++++++++++++++ test/frenzy/opml/importer_test.exs | 30 ++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/frenzy/opml/exporter_test.exs create mode 100644 test/frenzy/opml/importer_test.exs diff --git a/lib/frenzy/opml/importer.ex b/lib/frenzy/opml/importer.ex index bb33194..9bab1b3 100644 --- a/lib/frenzy/opml/importer.ex +++ b/lib/frenzy/opml/importer.ex @@ -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 diff --git a/test/frenzy/opml/exporter_test.exs b/test/frenzy/opml/exporter_test.exs new file mode 100644 index 0000000..0aa25a5 --- /dev/null +++ b/test/frenzy/opml/exporter_test.exs @@ -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 == + """ + + + Frenzy export + + + + + + + + + + + """ + |> String.trim() + end +end diff --git a/test/frenzy/opml/importer_test.exs b/test/frenzy/opml/importer_test.exs new file mode 100644 index 0000000..d545d00 --- /dev/null +++ b/test/frenzy/opml/importer_test.exs @@ -0,0 +1,30 @@ +defmodule Frenzy.OPML.ImporterTests do + use ExUnit.Case + alias Frenzy.OPML.Importer + doctest Importer + + @opml """ + + + + + Subscriptions-OnMyMac.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