Skip to content

Commit

Permalink
with endpoint, allow wtf? debugging in assert_pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 19, 2024
1 parent ca3fe01 commit 3cd4e93
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,20 @@ class EndpointWithActivityTest < Minitest::Spec
include Trailblazer::Test::Assertion::AssertExposes

module Endpoint
def assert_pass(*args, **options, &block)
super(*args, **options, invoke: EndpointWithActivityTest.method(:__), &block)
def assert_pass(*args, invoke: EndpointWithActivityTest.method(:__), **options, &block)
super(*args, **options, invoke: invoke, &block)
end

def assert_fail(*args, **options, &block)
super(*args, **options, invoke: EndpointWithActivityTest.method(:__), &block)
def assert_fail(*args, invoke: EndpointWithActivityTest.method(:__), **options, &block)
super(*args, **options, invoke: invoke, &block)
end

def assert_pass?(*args, **options, &block)
assert_pass(*args, **options, invoke: EndpointWithActivityTest.method(:__?), &block)
end

def assert_fail?(*args, **options, &block)
assert_fail(*args, **options, invoke: EndpointWithActivityTest.method(:__?), &block)
end
end
include Endpoint
Expand All @@ -482,16 +490,21 @@ def self._flow_options
}
end

def self.__(activity, options, &block) # TODO: move this to endpoint.
def self.__(activity, options, **kws, &block) # TODO: move this to endpoint.
signal, (ctx, flow_options) = Trailblazer::Endpoint::Runtime.(
activity, options,
flow_options: _flow_options(),
**kws,
&block
)

return signal, ctx # DISCUSS: should we provide a Result object here?
end

def self.__?(*args, &block)
__(*args, invoke_method: Trailblazer::Developer::Wtf.method(:invoke), &block)
end

it "{#assert_pass} {Activity} invoked via endpoint" do
ctx = assert_pass Create, {params: {title: "Roxanne"}},
title: "Roxanne"
Expand All @@ -504,5 +517,21 @@ def self.__(activity, options, &block) # TODO: move this to endpoint.

assert_equal ctx.class, Trailblazer::Context::Container::WithAliases
end

it "{#assert_pass?}" do
out, _ = capture_io do
ctx = assert_pass? Create, {params: {title: "Roxanne"}},
title: "Roxanne"

assert_equal ctx[:object].title, "Roxanne" # aliasing only works through endpoint.
end

assert_equal out, %(AssertionActivityTest::Create
|-- \e[32mStart.default\e[0m
|-- \e[32mvalidate\e[0m
|-- \e[32mmodel\e[0m
`-- End.success
)
end
end

0 comments on commit 3cd4e93

Please sign in to comment.