Skip to content

Commit

Permalink
start testing the public/circuit call API.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 24, 2023
1 parent d109db7 commit fa7326a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/operation_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
require "test_helper"

# Tests around {Operation.call}.
class OperationTest < Minitest::Spec
class Noop < Trailblazer::Operation
def self.capture_circuit_options((ctx, flow_options), **circuit_options)
ctx[:capture_circuit_options] = circuit_options.keys.inspect

return Trailblazer::Activity::Right, [ctx, flow_options]
end

step task: method(:capture_circuit_options)
end

it "doesn't mistake circuit options as ctx variables when using circuit-interface" do
signal, (ctx, _) = Noop.call([{params: {}}, {}], variable_for_circuit_options: true) # call_with_public_interface
#@ {:variable_for_circuit_options} is not supposed to be in {ctx}.
assert_equal ctx.inspect, %({:params=>{}, :capture_circuit_options=>"[:variable_for_circuit_options, :exec_context, :activity, :runner]"})
end

it "doesn't mistake circuit options as ctx variables when using the call interface" do
result = Noop.call(params: {}, model: true, "current_user" => Object) # call with public interface.
#@ {:variable_for_circuit_options} is not supposed to be in {ctx}.
assert_equal result.inspect, %(<Result:true #<Trailblazer::Context::Container wrapped_options={:params=>{}, :model=>true, "current_user"=>Object} mutable_options={:capture_circuit_options=>"[:exec_context, :wrap_runtime, :activity, :runner]"}> >)
end
end

# TODO: remove this test as many cases are covered via autogenerated activity tests.

class DeclarativeApiTest < Minitest::Spec
it "doesn't invoke {call} twice when using public interface" do
class MyOp < Trailblazer::Operation
Expand Down

0 comments on commit fa7326a

Please sign in to comment.