Skip to content

Commit

Permalink
add another test asserting the levels
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Apr 1, 2024
1 parent 298c996 commit 029165c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ defmodule Radiator.Outline do
content: content,
parent_id: binaray_uuid_to_ecto_uuid(parent_id),
prev_id: binaray_uuid_to_ecto_uuid(prev_id),
level: level
level: level,
episode_id: episode_id
}
end)

Expand Down
28 changes: 28 additions & 0 deletions test/radiator/outline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,34 @@ defmodule Radiator.OutlineTest do
node.level
end)
end

test "associated the correct level", %{
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_node: parent_node
} do
{:ok, tree} = Outline.get_node_tree(parent_node.episode_id)
assert_level_for_node(tree, parent_node, 0)
assert_level_for_node(tree, node_1, 1)
assert_level_for_node(tree, node_2, 1)
assert_level_for_node(tree, node_3, 1)
assert_level_for_node(tree, node_4, 1)
assert_level_for_node(tree, node_5, 1)
assert_level_for_node(tree, node_6, 1)
assert_level_for_node(tree, nested_node_1, 2)
assert_level_for_node(tree, nested_node_2, 2)
end
end

defp assert_level_for_node(tree, node, level) do
node = Enum.filter(tree, fn n -> n.uuid == node.uuid end) |> List.first()
assert node.level == level
end

defp complex_node_fixture(_) do
Expand Down

0 comments on commit 029165c

Please sign in to comment.