Skip to content

Commit

Permalink
we can generate iteration_set, state_table and state_guards template.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Mar 14, 2024
1 parent 8be6700 commit 0b9fa06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1,111 deletions.
5 changes: 4 additions & 1 deletion lib/trailblazer/workflow/task/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def call(schema:, namespace:, target_dir:, start_activity_json_id:, run_multiple
iteration_set,
lanes_cfg: lanes_cfg,
filename: state_guard_filename,
state_table_filename: state_table_filename,
namespace: namespace,
)
end
Expand Down Expand Up @@ -113,12 +114,14 @@ class #{namespace.gsub("::", "_")}CollaborationTest < Minitest::Spec
module StateGuards
module_function

def call(iteration_set, filename:, lanes_cfg:, namespace:, **)
def call(iteration_set, filename:, state_table_filename:, lanes_cfg:, namespace:, **)
# ruby_output = Trailblazer::Workflow::Introspect::StateTable::Generate.(iteration_set, lanes_cfg: lanes_cfg, namespace: namespace)
_, (ctx, _) = Trailblazer::Workflow::Generate::StateTable.invoke([{iteration_set: iteration_set, lanes_cfg: lanes_cfg, namespace: "App::Posting"}, {}])
state_table_output = ctx[:snippet]
_, (ctx, _) = Trailblazer::Workflow::Generate::StateGuards.invoke([{rows: ctx[:rows], namespace: "App::Posting"}, {}])
ruby_output = ctx[:snippet]

File.write(state_table_filename, state_table_output)
File.write(filename, ruby_output)
end
end
Expand Down
21 changes: 19 additions & 2 deletions test/discover_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ def build_schema()
namespace: "Posting::Collaboration",
target_dir: "app/concepts/posting/collaboration",
start_activity_json_id: "<ui> author workflow",
# iteration_set_filename: "test/tmp/bla.json",
test_filename: "test/bla_test.rb",
)
end

#@ We serialized the discovered iterations, so we don't need to run discovery on every startup.
assert_equal (serialized_iteration_set = File.read("test/tmp/bla.json")).size, 20925
assert_equal (serialized_iteration_set = File.read("#{TEST_ROOT}/app/concepts/posting/collaboration/generated/iteration_set.json")).size, 20925

# raise
# iteration_set = Trailblazer::Workflow::Introspect::Iteration::Set.from_discovered_states(states, lanes_cfg: lanes_cfg)
Expand Down Expand Up @@ -115,6 +114,24 @@ def build_schema()
state_table: StateTable,
)
end
)

assert_equal File.read("#{TEST_ROOT}/app/concepts/posting/collaboration/generated/state_table.rb"),
%(# This file is generated by trailblazer-workflow.
module App::Posting::Generated
StateTable = {
"⏸︎ Create form" => {id: ["catch-before-Activity_0wc2mcq"],
"⏸︎ Create" => {id: ["catch-before-Activity_1psp91r"],
"⏸︎ Update form♦Notify approver" => {id: ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"],
"⏸︎ Update" => {id: ["catch-before-Activity_0j78uzd"],
"⏸︎ Approve♦Reject" => {id: ["catch-before-Activity_13fw5nm", "catch-before-Activity_1j7d8sd"],
"⏸︎ Delete? form♦Publish" => {id: ["catch-before-Activity_0bsjggk", "catch-before-Activity_0ha7224"],
"⏸︎ Revise form" => {id: ["catch-before-Activity_0zsock2"],
"⏸︎ Delete♦Cancel" => {id: ["catch-before-Activity_15nnysv", "catch-before-Activity_1uhozy1"],
"⏸︎ Archive" => {id: ["catch-before-Activity_0fy41qq"],
"⏸︎ Revise" => {id: ["catch-before-Activity_1wiumzv"],
}
end
)

end
Expand Down
Loading

0 comments on commit 0b9fa06

Please sign in to comment.