Skip to content

Commit

Permalink
WIP: remove_node should also return a NodeRepoResult with all del…
Browse files Browse the repository at this point in the history
…eted children
  • Loading branch information
electronicbites committed Aug 1, 2024
1 parent cfa32b5 commit b2b96e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ defmodule Radiator.Outline do
end)

# finally delete the node itself from the database
NodeRepository.delete_node(node)
deleted_node = NodeRepository.delete_node(node)
%NodeRepoResult{node: deleted_node, children: []}
end

@doc """
Expand Down
12 changes: 6 additions & 6 deletions test/radiator/outline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ defmodule Radiator.OutlineTest do

test "deletes the node" do
node = node_fixture()
assert {:ok, %Node{}} = Outline.remove_node(node)
assert %NodeRepoResult{} = Outline.remove_node(node)
assert_raise Ecto.NoResultsError, fn -> NodeRepository.get_node!(node.uuid) end
end

Expand All @@ -542,7 +542,7 @@ defmodule Radiator.OutlineTest do
} do
assert node_4.prev_id == node_3.uuid

assert {:ok, %Node{}} = Outline.remove_node(node_3)
assert %NodeRepoResult{} = Outline.remove_node(node_3)
# reload nodes
node_4 = NodeRepository.get_node!(node_4.uuid)
node_2 = NodeRepository.get_node!(node_2.uuid)
Expand All @@ -555,7 +555,7 @@ defmodule Radiator.OutlineTest do
} do
episode_id = node_6.episode_id
count_nodes = NodeRepository.count_nodes_by_episode(episode_id)
assert {:ok, %Node{}} = Outline.remove_node(node_6)
assert %NodeRepoResult{} = Outline.remove_node(node_6)
new_count_nodes = NodeRepository.count_nodes_by_episode(episode_id)
assert new_count_nodes == count_nodes - 1
end
Expand All @@ -567,7 +567,7 @@ defmodule Radiator.OutlineTest do
episode_id = node_1.episode_id

count_nodes = NodeRepository.count_nodes_by_episode(episode_id)
assert {:ok, %Node{}} = Outline.remove_node(node_1)
assert %NodeRepoResult{} = Outline.remove_node(node_1)
new_count_nodes = NodeRepository.count_nodes_by_episode(episode_id)
assert new_count_nodes == count_nodes - 1

Expand All @@ -580,7 +580,7 @@ defmodule Radiator.OutlineTest do
nested_node_1: nested_node_1,
nested_node_2: nested_node_2
} do
assert {:ok, %Node{}} = Outline.remove_node(node_3)
assert %NodeRepoResult{} = Outline.remove_node(node_3)

assert_raise Ecto.NoResultsError, fn -> NodeRepository.get_node!(nested_node_1.uuid) end
assert_raise Ecto.NoResultsError, fn -> NodeRepository.get_node!(nested_node_2.uuid) end
Expand All @@ -593,7 +593,7 @@ defmodule Radiator.OutlineTest do
nested_node_2: nested_node_2,
parent_node: parent_node
} do
assert {:ok, %Node{}} = Outline.remove_node(parent_node)
assert %NodeRepoResult{} = Outline.remove_node(parent_node)

# test some of elements in the tree
assert_raise Ecto.NoResultsError, fn -> NodeRepository.get_node!(node_1.uuid) end
Expand Down

0 comments on commit b2b96e3

Please sign in to comment.