From 67573d41017e6fd0643507ec171525df74f79f9b Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 7 Dec 2023 17:37:44 +0100 Subject: [PATCH] add test to discuss https://github.com/trailblazer/trailblazer-operation/pull/65. --- test/call_test.rb | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/test/call_test.rb b/test/call_test.rb index 76e243e..2c6475c 100644 --- a/test/call_test.rb +++ b/test/call_test.rb @@ -41,18 +41,18 @@ class Update < Trailblazer::Operation result.event.must_equal Update.to_h[:outputs].find { |output| output.semantic == :failure }.signal end + def self.add_1(wrap_ctx, original_args) + ctx, = original_args[0] + ctx[:seq] << 1 + return wrap_ctx, original_args # yay to mutable state. not. + end + it "invokes with the taskWrap" do operation = Class.new(Trailblazer::Operation) do include Trailblazer::Activity::Testing.def_steps(:a) - def self.add_1(wrap_ctx, original_args) - ctx, = original_args[0] - ctx[:seq] << 1 - return wrap_ctx, original_args # yay to mutable state. not. - end - merge = [ - [Trailblazer::Activity::TaskWrap::Pipeline.method(:insert_before), "task_wrap.call_task", ["user.add_1", method(:add_1)]] + [Trailblazer::Activity::TaskWrap::Pipeline.method(:insert_before), "task_wrap.call_task", ["user.add_1", CallTest.method(:add_1)]] ] step :a, extensions: [Trailblazer::Activity::TaskWrap::Extension(merge: merge)] @@ -70,4 +70,27 @@ def self.add_1(wrap_ctx, original_args) result.wtf? end + + + it "calls with the taskWrap defined for operation using circuit interface" do + operation = Class.new(Trailblazer::Operation) do + include Trailblazer::Activity::Testing.def_steps(:a) + + step :a + end + + my_extension = Trailblazer::Activity::TaskWrap::Extension( + [CallTest.method(:add_1), id: "my.add_1", append: "task_wrap.call_task"] + ) + + # circuit interface invocation using call + signal, (ctx, _) = operation.call( + [{seq: []}, {}], + wrap_runtime: Hash.new(my_extension), + runner: Trailblazer::Activity::TaskWrap::Runner + ) + + assert_equal signal.to_h[:semantic], :success + assert_equal ctx[:seq], [1, :a, 1, 1] + end end