Skip to content

Commit

Permalink
first tests with #assert_advance running! 💪
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 13, 2024
1 parent 824dc5d commit 32aa219
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
8 changes: 5 additions & 3 deletions lib/trailblazer/workflow/test/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def assert_positions(asserted_positions, expected_tuples, lanes:)
end

# Compile error message when the expected lane position doesn't match the actual one.
def self.error_message_for(position, expected_position, lanes:)
def self.error_message_for(position, expected_position, lanes:) # TODO: test me.
# TODO: make the labels use UTF8 icons etc, as in the CLI rendering code.
expected_label = State::Discovery::Testing.serialize_lane_position(position, lanes: lanes)[:comment]
actual_label = State::Discovery::Testing.serialize_lane_position(expected_position, lanes: lanes)[:comment]
Expand All @@ -33,7 +33,7 @@ def self.error_message_for(position, expected_position, lanes:)

# Grab the start_position and expected_lane_positions from the discovered plan, run
# the collaboration from there and check if it actually reached the expected configuration.
def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expected_ctx:, **) # TODO: allow {ctx}
def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expected_ctx:, ctx: {seq: []}, **) # TODO: allow {ctx}
testing_row = test_plan.find { |row| row[:event_label] == event_label }

start_position = testing_row[:start_position]
Expand All @@ -48,9 +48,11 @@ def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expe

lane_positions = Trailblazer::Workflow::Collaboration::Positions.new(lane_positions)

ctx_for_advance = ctx

configuration, (ctx, flow) = Trailblazer::Workflow::Collaboration::Synchronous.advance(
schema,
[{seq: []}, {throw: []}],
[ctx_for_advance, {throw: []}],
{}, # circuit_options

start_position: start_position,
Expand Down
58 changes: 27 additions & 31 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,6 @@ def render_states(states, lanes:, additional_state_data:, task_map:)

lanes = ___lanes___.invert

# test: ☝ ▶Revise
ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]

# +----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
# | triggered catch | start_configuration_formatted | expected_lane_positions_formatted |
# +----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
Expand All @@ -623,63 +619,63 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
# 15 rows in set

# test: ☝ ▶Create form
ctx = assert_advance "☝ ▶Create form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
ctx = assert_advance "☝ ▶Create form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:create_form], reader: :[]

# test: ☝ ▶Create
ctx = assert_advance "☝ ▶Create", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
ctx = assert_advance "☝ ▶Create", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:ui_create, :create], reader: :[]

# test: ☝ ▶Create ⛞
ctx = assert_advance "☝ ▶Create ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Create ⛞", ctx: {seq: [], create: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:ui_create, :create, :create_form_with_errors], reader: :[]

# test: ☝ ▶Update form
ctx = assert_advance "☝ ▶Update form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Update form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:update_form], reader: :[]

# test: ☝ ▶Notify approver
ctx = assert_advance "☝ ▶Notify approver", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Notify approver", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:notify_approver, :notify_approver, :approve], reader: :[]

# test: ☝ ▶Update
ctx = assert_advance "☝ ▶Update", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Update", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:ui_update, :update], reader: :[]

# test: ☝ ▶Notify approver ⛞
ctx = assert_advance "☝ ▶Notify approver ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Notify approver ⛞", ctx: {seq: [], decision: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:notify_approver, :notify_approver, :reject], reader: :[]

# test: ☝ ▶Delete? form
ctx = assert_advance "☝ ▶Delete? form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Delete? form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:delete_form], reader: :[]

# test: ☝ ▶Publish
ctx = assert_advance "☝ ▶Publish", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Publish", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:publish, :publish], reader: :[]

# test: ☝ ▶Update ⛞
ctx = assert_advance "☝ ▶Update ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Update ⛞", ctx: {seq: [], update: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:ui_update, :update, :update_form_with_errors], reader: :[]

# test: ☝ ▶Revise form
ctx = assert_advance "☝ ▶Revise form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Revise form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:revise_form], reader: :[]

# test: ☝ ▶Delete
ctx = assert_advance "☝ ▶Delete", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Delete", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:delete, :delete], reader: :[]

# test: ☝ ▶Cancel
ctx = assert_advance "☝ ▶Cancel", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Cancel", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:cancel], reader: :[]

# test: ☝ ▶Archive
ctx = assert_advance "☝ ▶Archive", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]
ctx = assert_advance "☝ ▶Archive", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:archive, :archive], reader: :[]

# test: ☝ ▶Revise
ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow
ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow
assert_exposes ctx, seq: [:revise, :revise], reader: :[]


Expand Down

0 comments on commit 32aa219

Please sign in to comment.