Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
48 failures (after rebase more than 50)
  • Loading branch information
electronicbites committed Dec 22, 2024
1 parent 8458a29 commit 4eef1ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 0 additions & 2 deletions lib/radiator/podcast/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Radiator.Podcast.Show do
import Ecto.Changeset

alias Radiator.Accounts.User
alias Radiator.Outline.Node
alias Radiator.Outline.NodeContainer
alias Radiator.Podcast.{Episode, Network}

Expand All @@ -22,7 +21,6 @@ defmodule Radiator.Podcast.Show do
belongs_to :outline_node_container, NodeContainer

has_many(:episodes, Episode)
has_many(:outline_nodes, Node)
many_to_many(:hosts, User, join_through: "show_hosts")

timestamps(type: :utc_datetime)
Expand Down
2 changes: 1 addition & 1 deletion lib/radiator/resources/url.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Radiator.Resources.Url do
def changeset(url, attrs) do
url
|> cast(attrs, [:url, :start_bytes, :size_bytes, :node_id, :episode_id])
|> validate_required([:url, :start_bytes, :size_bytes, :node_id])
|> validate_required([:url, :start_bytes, :size_bytes, :node_id, :episode_id])
|> cast_embed(:meta_data, with: &MetaData.changeset/2)
end
end
34 changes: 17 additions & 17 deletions test/radiator/outline/node_repository_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ defmodule Radiator.Outline.NodeRepositoryTest do
end
end

describe "list_nodes_by_episode/1" do
describe "list_nodes_by_node_container/1" do
test "list_nodes/1 returns only nodes of this episode" do
node1 = node_fixture()
node2 = node_fixture()

assert NodeRepository.list_nodes_by_episode(node1.episode_id) == [node1]
assert NodeRepository.list_nodes_by_episode(node2.episode_id) == [node2]
assert NodeRepository.list_nodes_by_node_container(node1.outline_node_container_id) == [node1]
assert NodeRepository.list_nodes_by_node_container(node2.outline_node_container_id) == [node2]
end
end

Expand Down Expand Up @@ -159,10 +159,10 @@ defmodule Radiator.Outline.NodeRepositoryTest do
setup :complex_node_fixture

test "returns all nodes from a episode", %{parent_node: parent_node} do
episode_id = parent_node.episode_id
assert {:ok, tree} = NodeRepository.get_node_tree(episode_id)
outline_node_container_id = parent_node.outline_node_container_id
assert {:ok, tree} = NodeRepository.get_node_tree(outline_node_container_id)

all_nodes = NodeRepository.list_nodes_by_episode(episode_id)
all_nodes = NodeRepository.list_nodes_by_node_container(outline_node_container_id)

assert Enum.count(tree) == Enum.count(all_nodes)

Expand All @@ -172,19 +172,19 @@ defmodule Radiator.Outline.NodeRepositoryTest do
end)
end

test "does not return a node from another episode", %{
test "does not return a node from another container", %{
parent_node: parent_node
} do
episode_id = parent_node.episode_id
outline_node_container_id = parent_node.outline_node_container_id
other_node = node_fixture(parent_id: nil, prev_id: nil, content: "other content")
assert other_node.episode_id != episode_id
{:ok, tree} = NodeRepository.get_node_tree(episode_id)
assert other_node.outline_node_container_id != outline_node_container_id
{:ok, tree} = NodeRepository.get_node_tree(outline_node_container_id)
assert Enum.filter(tree, fn n -> n.uuid == other_node.uuid end) == []
end

test "returns nodes sorted by level", %{parent_node: parent_node} do
episode_id = parent_node.episode_id
{:ok, tree} = NodeRepository.get_node_tree(episode_id)
outline_node_container_id = parent_node.outline_node_container_id
{:ok, tree} = NodeRepository.get_node_tree(outline_node_container_id)

Enum.reduce(tree, 0, fn node, current_level ->
if node.parent_id != nil do
Expand All @@ -208,7 +208,7 @@ defmodule Radiator.Outline.NodeRepositoryTest do
nested_node_2: nested_node_2,
parent_node: parent_node
} do
{:ok, tree} = NodeRepository.get_node_tree(parent_node.episode_id)
{:ok, tree} = NodeRepository.get_node_tree(parent_node.outline_node_container_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)
Expand All @@ -223,25 +223,25 @@ defmodule Radiator.Outline.NodeRepositoryTest do
test "tree can have more than one parent node", %{
parent_node: parent_node
} do
episode_id = parent_node.episode_id
outline_node_container_id = parent_node.outline_node_container_id

other_parent_node =
node_fixture(
parent_id: nil,
prev_id: parent_node.uuid,
episode_id: episode_id,
outline_node_container_id: outline_node_container_id,
content: "also a parent"
)

third_parent_node =
node_fixture(
parent_id: nil,
prev_id: other_parent_node.uuid,
episode_id: episode_id,
outline_node_container_id: outline_node_container_id,
content: "even another root element"
)

{:ok, tree} = NodeRepository.get_node_tree(parent_node.episode_id)
{:ok, tree} = NodeRepository.get_node_tree(parent_node.outline_node_container_id)
assert_level_for_node(tree, parent_node, 0)
assert_level_for_node(tree, other_parent_node, 0)
assert_level_for_node(tree, third_parent_node, 0)
Expand Down

0 comments on commit 4eef1ff

Please sign in to comment.