Skip to content

Commit

Permalink
add Test::Endpoint to allow a "global" invocation method for the
Browse files Browse the repository at this point in the history
entire test suite.
  • Loading branch information
apotonick committed Dec 19, 2024
1 parent bd6c5a3 commit a13b468
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
42 changes: 42 additions & 0 deletions lib/trailblazer/test/endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Trailblazer
module Test
# DISCUSS: this is not really endpoint related, it's more like setting a "global" invocation mechanism.
module Endpoint
# DISCUSS: not sure this is the final "technique" to use the global endpoint invoker.
def self.module(receiver, invoke_method:, invoke_method_wtf:)
receiver.class_eval do
@@INVOKE_METHOD = invoke_method
@@INVOKE_METHOD_WTF = invoke_method_wtf

def trailblazer_test_invoke_method
@@INVOKE_METHOD
end

def trailblazer_test_invoke_method_wtf
@@INVOKE_METHOD_WTF
end
end

Assertion
end

module Assertion
def assert_pass(*args, invoke: trailblazer_test_invoke_method, **options, &block)
super(*args, **options, invoke: invoke, &block)
end

def assert_fail(*args, invoke: trailblazer_test_invoke_method, **options, &block)
super(*args, **options, invoke: invoke, &block)
end

def assert_pass?(*args, **options, &block)
assert_pass(*args, **options, invoke: trailblazer_test_invoke_method_wtf, &block)
end

def assert_fail?(*args, **options, &block)
assert_fail(*args, **options, invoke: trailblazer_test_invoke_method_wtf, &block)
end
end
end
end
end
42 changes: 13 additions & 29 deletions test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class AssertionActivitySuiteTest < Minitest::Spec
end

require "trailblazer/endpoint"
require "trailblazer/test/endpoint"
class EndpointWithActivityTest < Minitest::Spec
Record = AssertionsTest::Record
Create = AssertionActivityTest::Create
Expand All @@ -461,35 +462,6 @@ class EndpointWithActivityTest < Minitest::Spec
include Trailblazer::Test::Assertion::Activity::Assert
include Trailblazer::Test::Assertion::AssertExposes

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

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


def self._flow_options
{
context_options: {
aliases: {"model": :object},
container_class: Trailblazer::Context::Container::WithAliases,
}
}
end

def self.__(activity, options, **kws, &block) # TODO: move this to endpoint.
signal, (ctx, flow_options) = Trailblazer::Endpoint::Runtime.(
activity, options,
Expand All @@ -504,6 +476,18 @@ def self.__(activity, options, **kws, &block) # TODO: move this to endpoint.
def self.__?(*args, &block)
__(*args, invoke_method: Trailblazer::Developer::Wtf.method(:invoke), &block)
end
include Trailblazer::Test::Endpoint.module(self, invoke_method: method(:__), invoke_method_wtf: method(:__?))


def self._flow_options
{
context_options: {
aliases: {"model": :object},
container_class: Trailblazer::Context::Container::WithAliases,
}
}
end


it "{#assert_pass} {Activity} invoked via endpoint" do
ctx = assert_pass Create, {params: {title: "Roxanne"}},
Expand Down

0 comments on commit a13b468

Please sign in to comment.