Skip to content

Commit

Permalink
WIP: make episode a required attribute for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Dec 26, 2023
1 parent 01b56dd commit d205eaf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/radiator/outline/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ defmodule Radiator.Outline.Node do
end

@required_fields [
:content
:content,
:episode_id
]

@optional_fields [
:creator_id,
:parent_id,
:prev_id,
:episode_id # FIXME: should be required
:prev_id
]

@all_fields @optional_fields ++ @required_fields
Expand Down
2 changes: 1 addition & 1 deletion lib/radiator/podcast/episode.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Radiator.Podcast.Episode do
@moduledoc """
Represents the Episode model.
TODO: Episodes should be numbered and ordered inside a show.
Episodes are numbered inside a show.
"""
use Ecto.Schema
import Ecto.Changeset
Expand Down
3 changes: 0 additions & 3 deletions lib/radiator_web/controllers/api/outline_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ defmodule RadiatorWeb.Api.OutlineController do
token
|> decode_token()
|> get_user_by_token()
# show will be send in request from frontend (show_id)
# fetch wanted/current episode for show

|> create_node(content)
|> get_response()

Expand Down
10 changes: 7 additions & 3 deletions test/radiator/outline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Radiator.OutlineTest do
alias Radiator.Outline.Node

import Radiator.OutlineFixtures
alias Radiator.PodcastFixtures

@invalid_attrs %{content: nil}

Expand All @@ -21,22 +22,25 @@ defmodule Radiator.OutlineTest do
end

test "create_node/1 with valid data creates a node" do
valid_attrs = %{content: "some content"}
episode = PodcastFixtures.episode_fixture()
valid_attrs = %{content: "some content", episode_id: episode.id}

assert {:ok, %Node{} = node} = Outline.create_node(valid_attrs)
assert node.content == "some content"
end

test "create_node/1 trims whitespace from content" do
valid_attrs = %{content: " some content "}
episode = PodcastFixtures.episode_fixture()
valid_attrs = %{content: " some content ", episode_id: episode.id}

assert {:ok, %Node{} = node} = Outline.create_node(valid_attrs)
assert node.content == "some content"
end

test "create_node/1 can have a creator" do
episode = PodcastFixtures.episode_fixture()
user = %{id: 2}
valid_attrs = %{content: "some content"}
valid_attrs = %{content: "some content", episode_id: episode.id}

assert {:ok, %Node{} = node} = Outline.create_node(valid_attrs, user)
assert node.content == "some content"
Expand Down
2 changes: 2 additions & 0 deletions test/support/fixtures/outline_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Radiator.OutlineFixtures do
entities via the `Radiator.Outline` context.
"""
alias Radiator.PodcastFixtures

@doc """
Generate a node.
"""
Expand All @@ -17,6 +18,7 @@ defmodule Radiator.OutlineFixtures do
episode_id: episode.id
})
|> Radiator.Outline.create_node()

node
end
end

0 comments on commit d205eaf

Please sign in to comment.