Skip to content

Commit

Permalink
enable tree validation in dev and test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Aug 25, 2024
1 parent 763f0c6 commit 208a954
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/radiator/outline/dispatch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Radiator.Outline.Dispatch do
@moduledoc false

alias Radiator.Outline.Command
alias Radiator.Outline.Event
alias Radiator.Outline.EventProducer

def insert_node(attributes, user_id, event_id) do
Expand Down Expand Up @@ -33,6 +34,11 @@ defmodule Radiator.Outline.Dispatch do
end

def broadcast(event) do
if Mix.env == :dev || Mix.env == :test do
:ok = event
|> Event.episode_id()
|> Radiator.Outline.Validations.validate_tree_for_episode()

Check warning on line 40 in lib/radiator/outline/dispatch.ex

View workflow job for this annotation

GitHub Actions / Build & Test

Nested modules could be aliased at the top of the invoking module.
end
Phoenix.PubSub.broadcast(Radiator.PubSub, "events", event)
end

Expand Down
16 changes: 16 additions & 0 deletions lib/radiator/outline/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@ defmodule Radiator.Outline.Event do
def event_type(%NodeDeletedEvent{} = _event), do: "NodeDeletedEvent"

def event_type(%NodeMovedEvent{} = _event), do: "NodeMovedEvent"

def episode_id(%NodeInsertedEvent{} = event) do
event.node.episode_id
end

def episode_id(%NodeContentChangedEvent{} = event) do
Radiator.Outline.NodeRepository.get_node(event.node_id).episode_id

Check warning on line 55 in lib/radiator/outline/event.ex

View workflow job for this annotation

GitHub Actions / Build & Test

Nested modules could be aliased at the top of the invoking module.
end

def episode_id(%NodeDeletedEvent{} = event) do
Radiator.Outline.NodeRepository.get_node(event.next_id).episode_id

Check warning on line 59 in lib/radiator/outline/event.ex

View workflow job for this annotation

GitHub Actions / Build & Test

Nested modules could be aliased at the top of the invoking module.
end

def episode_id(%NodeMovedEvent{} = event) do
Radiator.Outline.NodeRepository.get_node(event.node_id).episode_id

Check warning on line 63 in lib/radiator/outline/event.ex

View workflow job for this annotation

GitHub Actions / Build & Test

Nested modules could be aliased at the top of the invoking module.
end
end

0 comments on commit 208a954

Please sign in to comment.