Module: Trailblazer::Activity::Testing::Assertions

Defined in:
lib/trailblazer/activity/testing.rb

Instance Method Summary collapse

Instance Method Details

#assert_call(activity, terminus: :success, seq: "[]", expected_ctx_variables: {}, **ctx_variables) ⇒ Object

‘:seq` is always passed into ctx.

Parameters:

  • :seq

    String What the :seq variable in the result ctx looks like. (expected seq)

  • :expected_ctx_variables

    Variables that are added during the call by the asserted activity.



50
51
52
53
54
55
# File 'lib/trailblazer/activity/testing.rb', line 50

def assert_call(activity, terminus: :success, seq: "[]", expected_ctx_variables: {}, **ctx_variables)
  # Call without taskWrap!
  signal, (ctx, _) = activity.([{seq: [], **ctx_variables}, _flow_options = {}]) # simply call the activity with the input you want to assert.

  assert_call_for(signal, ctx, terminus: terminus, seq: seq, **expected_ctx_variables, **ctx_variables)
end

#assert_call_for(signal, ctx, terminus: :success, seq: "[]", **ctx_variables) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/trailblazer/activity/testing.rb', line 73

def assert_call_for(signal, ctx, terminus: :success, seq: "[]", **ctx_variables)
  assert_equal signal.to_h[:semantic], terminus, "assert_call expected #{terminus} terminus, not #{signal}. Use assert_call(activity, terminus: #{signal.to_h[:semantic].inspect})"

  assert_equal ctx.inspect, {seq: "%%%"}.merge(ctx_variables).inspect.sub('"%%%"', seq)

  return ctx
end

#assert_circuit(schema, circuit) ⇒ Object



94
95
96
97
98
99
# File 'lib/trailblazer/activity/testing.rb', line 94

def assert_circuit(schema, circuit)
  cct = Cct(schema)

  cct = cct.gsub("#<Trailblazer::Activity::TaskBuilder::Task user_proc=", "<*")
  assert_equal circuit.to_s, cct
end

#assert_invoke(activity, terminus: :success, seq: "[]", circuit_options: {}, flow_options: {}, expected_ctx_variables: {}, **ctx_variables) ⇒ Object

Use Trailblazer::Activity::TaskWrap.invoke to call the activity.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/trailblazer/activity/testing.rb', line 58

def assert_invoke(activity, terminus: :success, seq: "[]", circuit_options: {}, flow_options: {}, expected_ctx_variables: {}, **ctx_variables)
  signal, (ctx, returned_flow_options) = Activity::TaskWrap.invoke(
    activity,
    [
      {seq: [], **ctx_variables},
      flow_options,
    ],
    **circuit_options
  )

  assert_call_for(signal, ctx, terminus: terminus, seq: seq, **ctx_variables, **expected_ctx_variables) # DISCUSS: ordering of variables?

  return signal, [ctx, returned_flow_options]
end

#assert_process_for(process, *args) ⇒ Object Also known as: assert_process

Tests :circuit and :outputs fields so far.



82
83
84
85
86
87
88
89
90
# File 'lib/trailblazer/activity/testing.rb', line 82

def assert_process_for(process, *args)
  semantics, circuit = args[0..-2], args[-1]

  assert_equal semantics.sort, process.to_h[:outputs].collect { |output| output[:semantic] }.sort

  assert_circuit(process, circuit)

  process
end

#Cct(activity) ⇒ Object



101
102
103
# File 'lib/trailblazer/activity/testing.rb', line 101

def Cct(activity)
  Activity::Introspect::Render.(activity, inspect_task: Trailblazer::Activity::Testing.method(:render_task))
end