diff --git a/test/radiator/outline_test.exs b/test/radiator/outline_test.exs index b29cf9e1..308a9bc9 100644 --- a/test/radiator/outline_test.exs +++ b/test/radiator/outline_test.exs @@ -11,8 +11,33 @@ defmodule Radiator.OutlineTest do alias Radiator.Outline.NodeRepository alias Radiator.Podcast - describe "node_tree" do - test "generate from template" do + describe "generate nodes from template" do + test "single node" do + %{id: episode_id} = episode_fixture() + + assert %Node{} = node = "node-1" |> node_tree_fixture(%{episode_id: episode_id}) + assert [%Node{}] = list = ["node-1"] |> node_tree_fixture(%{episode_id: episode_id}) + + assert %{content: "node-1", parent_id: nil, prev_id: nil, episode_id: ^episode_id} = node + assert [%{content: "node-1", parent_id: nil, prev_id: nil, episode_id: ^episode_id}] = list + end + + test "list of nodes" do + %{id: episode_id} = episode_fixture() + + nodes = ["node-1", "node-2", "node-3"] |> node_tree_fixture(%{episode_id: episode_id}) + + assert length(nodes) == 3 + assert Enum.all?(nodes, &match?(%Node{episode_id: ^episode_id}, &1)) + + assert [ + %{uuid: uuid_1, content: "node-1", parent_id: nil, prev_id: nil}, + %{uuid: uuid_2, content: "node-2", parent_id: nil, prev_id: uuid_1}, + %{uuid: _uuid_3, content: "node-3", parent_id: nil, prev_id: uuid_2} + ] = nodes + end + + test "tree of nodes" do %{id: episode_id, show_id: show_id} = episode_fixture() nodes = diff --git a/test/support/data_case.ex b/test/support/data_case.ex index bde91534..65c144c7 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -81,6 +81,25 @@ defmodule Radiator.DataCase do def simple_node_fixture_hierachical(_) do episode = PodcastFixtures.episode_fixture() + attrs = %{ + episode_id: episode.id, + show_id: episode.show_id, + outline_node_container_id: episode.outline_node_container_id + } + + nodes = + [ + "node-1", + {"node-2", ["node-2_1"]} + ] + |> node_tree_fixture(attrs) + + assert [ + %{uuid: uuid_1, content: "node-1", parent_id: nil, prev_id: nil}, + %{uuid: uuid_2, content: "node-2", parent_id: nil, prev_id: uuid_1}, + %{uuid: _uuid_2_1, content: "node-2_1", parent_id: uuid_2, prev_id: nil} + ] = nodes + node_1 = node_fixture( episode_id: episode.id, diff --git a/test/support/fixtures/outline_fixtures.ex b/test/support/fixtures/outline_fixtures.ex index 9d8509eb..689c9266 100644 --- a/test/support/fixtures/outline_fixtures.ex +++ b/test/support/fixtures/outline_fixtures.ex @@ -48,19 +48,6 @@ defmodule Radiator.OutlineFixtures do """ def node_tree_fixture(content, attrs \\ %{}) - def node_tree_fixture(content, attrs) when is_bitstring(content) do - attrs - |> Map.merge(%{content: content}) - |> node_fixture() - end - - def node_tree_fixture({content, list}, attrs) do - node = node_tree_fixture(content, attrs) - child_attrs = Map.merge(attrs, %{parent_id: node.uuid, prev_id: nil}) - - [node, [node_tree_fixture(list, child_attrs)]] - end - def node_tree_fixture([content], attrs) do [node_tree_fixture(content, attrs)] end @@ -74,6 +61,19 @@ defmodule Radiator.OutlineFixtures do List.flatten([nodes | node_tree_fixture(tail, child_attrs)]) end + def node_tree_fixture({content, list}, attrs) do + node = node_tree_fixture(content, attrs) + child_attrs = Map.merge(attrs, %{parent_id: node.uuid, prev_id: nil}) + + [node, [node_tree_fixture(list, child_attrs)]] + end + + def node_tree_fixture(content, attrs) when is_bitstring(content) do + attrs + |> Map.merge(%{content: content}) + |> node_fixture() + end + @doc """ Generate a node_container. """