Skip to content

Commit

Permalink
WIP: tree node function
Browse files Browse the repository at this point in the history
fixup 2
  • Loading branch information
electronicbites committed Feb 14, 2024
1 parent 7838821 commit 928e679
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ defmodule Radiator.Outline do
node_tree_initial_query =
Node
|> where([n], is_nil(n.parent_id))
|> where([n], n.episode_id == ^episode_id)

node_tree_recursion_query =
Node
Expand Down
32 changes: 23 additions & 9 deletions test/radiator/outline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ defmodule Radiator.OutlineTest do
setup :complex_node_fixture

test "returns all nodes from a episode", %{
node_1: node_1,
node_2: node_2,
node_3: node_3,
node_4: node_4,
node_5: node_5,
node_6: node_6,
nested_node_1: nested_node_1,
nested_node_2: nested_node_2,
# node_1: node_1,
# node_2: node_2,
# node_3: node_3,
# node_4: node_4,
# node_5: node_5,
# node_6: node_6,
# nested_node_1: nested_node_1,
# nested_node_2: nested_node_2,
parent: parent
} do
episode_id = parent.episode_id
Expand All @@ -139,12 +139,26 @@ defmodule Radiator.OutlineTest do
|> where([n], n.episode_id == ^episode_id)
|> Repo.all()
assert Enum.count(tree) == Enum.count(all_nodes)
Enum.each(tree, fn node ->
assert node == List.first(Enum.filter(all_nodes, fn n -> n.uuid == node.uuid end))
end)
end

test "does not return a node not in this episode", %{
parent: parent
} do
episode_id = parent.episode_id
other_node = node_fixture(parent_id: nil, prev_id: nil, content: "other content")
assert other_node.episode_id != episode_id
{:ok, tree} = Outline.get_node_tree(episode_id)
assert Enum.filter(tree, fn n -> n.uuid == other_node.uuid end) == nil
end

end

defp complex_node_fixture(_) do
episode = PodcastFixtures.episode_fixture()
parent = node_fixture(episode_id: episode.id)
parent = node_fixture(episode_id: episode.id, parent_id: nil, prev_id: nil)
node_1 = node_fixture(episode_id: episode.id, parent_id: parent.uuid, prev_id: nil)
node_2 = node_fixture(episode_id: episode.id, parent_id: parent.uuid, prev_id: node_1.uuid)
node_3 = node_fixture(episode_id: episode.id, parent_id: parent.uuid, prev_id: node_2.uuid)
Expand Down

0 comments on commit 928e679

Please sign in to comment.