Skip to content

Commit

Permalink
in invoke, make activity a positional argument to stay consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 12, 2024
1 parent f35e2c0 commit e7f2b3c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/trailblazer/test/assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Assertion

# @private
# Invoker for Operation
def self.invoke_activity(ctx, operation:, **)
def self.invoke_activity(operation, ctx)
result = operation.call(ctx)

return result.terminus, result # translate the holy {Operation::Result} object back to a normal "circuit interface" return value.
Expand All @@ -16,7 +16,7 @@ def self.invoke_activity(ctx, operation:, **)
module Wtf
# @private
# Invoker with debugging for Operation
def self.invoke_activity(ctx, operation:, **)
def self.invoke_activity(operation, ctx)
result = operation.wtf?(ctx)

return result.terminus, result
Expand Down Expand Up @@ -56,14 +56,14 @@ def self.actual(asserted, reader, name)

# Assertions for Activity, not for Operation.
module Activity
def self.invoke_activity(ctx, operation:, **)
signal, (ctx, _) = operation.call([ctx, {}]) # call with circuit interface. https://trailblazer.to/2.1/docs/operation/#operation-internals-circuit-interface
def self.invoke_activity(activity, ctx)
signal, (ctx, _) = activity.call([ctx, {}]) # call with circuit interface. https://trailblazer.to/2.1/docs/operation/#operation-internals-circuit-interface

return signal, ctx
end

def self.invoke_activity_with_tracing(ctx, operation:, **)
signal, (ctx, _) = Developer::Wtf.invoke(operation, [ctx, {}])
def self.invoke_activity_with_tracing(activity, ctx)
signal, (ctx, _) = Developer::Wtf.invoke(activity, [ctx, {}])

return signal, ctx
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trailblazer/test/assertion/assert_fail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module AssertFail

# {expected_errors} can be nil when using the {#assert_fail} block syntax.
def call(activity, ctx, expected_errors=nil, test:, invoke:, **kws)
signal, ctx, _ = invoke.(ctx, operation: activity) # FIXME: remove kws?
signal, ctx, _ = invoke.(activity, ctx)

assert_fail_with_model(signal, ctx, expected_errors: expected_errors, test: test, operation: activity, **kws)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trailblazer/test/assertion/assert_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module AssertPass
module_function

def call(activity, ctx, invoke:, model_at: :model, test:, user_block:, expected_model_attributes:)
signal, ctx, _ = invoke.(ctx, operation: activity)
signal, ctx, _ = invoke.(activity, ctx)

assert_pass_with_model(signal, ctx, expected_model_attributes: expected_model_attributes, test: test, user_block: user_block, model_at: model_at, operation: activity)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/trailblazer/test/operation/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Helper
def mock_step(activity, path:, &block)
raise ArgumentError, "Missing block: `#mock_step` requires a block." unless block_given?

# raise path.last.inspect
mocked_step_id, path = path.last, path[0..-2]

mock_step = ->(ctx, **) { yield(ctx) }
Expand All @@ -15,5 +14,4 @@ def mock_step(activity, path:, &block)
end
end


# [:delete_assets] => -> { step Destroy.method(:tidy_storage), before: :rm_uploads }
# [:delete_assets] => -> { step Destroy.method(:tidy_storage), before: :rm_uploads }
43 changes: 43 additions & 0 deletions test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,46 @@ class AssertionActivitySuiteTest < Minitest::Spec
)
end
end

class EndpointTest < Minitest::Spec
Record = AssertionsTest::Record
Create = AssertionActivityTest::Create

include Trailblazer::Test::Assertion
include Trailblazer::Test::Assertion::Activity::Assert
include Trailblazer::Test::Assertion::AssertExposes

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


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

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

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

require "trailblazer/endpoint"
it "Activity invoked via endpoint" do
assert_pass Create, {params: {title: "Roxanne"}},
title: "Roxanne"
end
end

0 comments on commit e7f2b3c

Please sign in to comment.