Skip to content

Commit

Permalink
move docs test to path_layout_test.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 15, 2023
1 parent 98a2cb5 commit 9840df7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 72 deletions.
71 changes: 71 additions & 0 deletions test/docs/path_layout_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
it do
module A
Memo = DocsStrategyTest::Memo

#:step
module Memo::Activity
class Create < Trailblazer::Activity::Path
step :validate
step :create
#~mod
def validate(ctx, params:, **)
ctx[:input] = Form.validate(params)
end

def create(ctx, input:, **)
Memo.create(input)
end
#~mod end
end
end
#:step end
end

ctx = {params: {text: "Hydrate!"}}

signal, (ctx, flow_options) = A::Memo::Activity::Create.([ctx, {}])

_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:success>}
_(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}}
end

it do
module B
#:validate
class Create < Trailblazer::Activity::Path
#~flow
step :validate, Output(Trailblazer::Activity::Left, :failure) => End(:invalid)
step :create
#~flow end
#~mod
def validate(ctx, params:, **)
ctx[:input] = Form.validate(params) # true/false
end

def create(ctx, input:, **)
Memo.create(input)
end
#~mod end
end
#:validate end
end

ctx = {params: {text: "Hydrate!"}}
signal, (ctx, _flow_options) = B::Create.([ctx, {}])

_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:success>}
_(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}}

ctx = {params: nil}
signal, (ctx, _flow_options) = B::Create.([ctx, {}])
_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:invalid>}
_(ctx.inspect).must_equal %{{:params=>nil, :input=>nil}}
=begin
#:validate-call
ctx = {params: nil}
signal, (ctx, flow_options) = Memo::Create.([ctx, {}])
puts signal #=> #<Trailblazer::Activity::End semantic=:invalid>
#:validate-call end
=end
end
72 changes: 0 additions & 72 deletions test/docs/strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,6 @@ def self.create(options)
end
end

it do
module A
Memo = DocsStrategyTest::Memo

#:step
module Memo::Activity
class Create < Trailblazer::Activity::Path
step :validate
step :create
#~mod
def validate(ctx, params:, **)
ctx[:input] = Form.validate(params)
end

def create(ctx, input:, **)
Memo.create(input)
end
#~mod end
end
end
#:step end
end

ctx = {params: {text: "Hydrate!"}}

signal, (ctx, flow_options) = A::Memo::Activity::Create.([ctx, {}])

_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:success>}
_(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}}
end

it do
module B
#:validate
class Create < Trailblazer::Activity::Path
#~flow
step :validate, Output(Trailblazer::Activity::Left, :failure) => End(:invalid)
step :create
#~flow end
#~mod
def validate(ctx, params:, **)
ctx[:input] = Form.validate(params) # true/false
end

def create(ctx, input:, **)
Memo.create(input)
end
#~mod end
end
#:validate end
end

ctx = {params: {text: "Hydrate!"}}
signal, (ctx, _flow_options) = B::Create.([ctx, {}])

_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:success>}
_(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}}

ctx = {params: nil}
signal, (ctx, _flow_options) = B::Create.([ctx, {}])
_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:invalid>}
_(ctx.inspect).must_equal %{{:params=>nil, :input=>nil}}
=begin
#:validate-call
ctx = {params: nil}
signal, (ctx, flow_options) = Memo::Create.([ctx, {}])
puts signal #=> #<Trailblazer::Activity::End semantic=:invalid>
#:validate-call end
=end
end

it do
module C
#:double-end
Expand Down

0 comments on commit 9840df7

Please sign in to comment.