-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Task::Import and tests, so we can pull diagrams from the PRO server.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "trailblazer/pro" | ||
|
||
module Trailblazer | ||
module Workflow | ||
module Task | ||
class Import < Trailblazer::Activity::Railway | ||
step Subprocess(Pro::Client::Connect), id: :connect, | ||
Output(:failure) => End(:failure) | ||
step :retrieve_document | ||
fail :error_for_retrieve | ||
step :store_document | ||
|
||
def retrieve_document(ctx, session:, diagram_slug:, **) | ||
id_token = session.id_token | ||
|
||
ctx[:response] = response = Faraday.get( | ||
"#{session.trailblazer_pro_host}/api/v1/diagrams/#{diagram_slug}/export", | ||
{}, | ||
{'Content-Type'=>'application/json', "Accept": "application/json", | ||
"Authorization": "Bearer #{id_token}" | ||
} | ||
) | ||
|
||
return false unless response.status == 200 # TODO: abstract this for other users, and use "endpoint" paths. | ||
|
||
ctx[:pro_json_document] = ctx[:response].body | ||
end | ||
|
||
def store_document(ctx, pro_json_document:, target_filename:, **) | ||
File.write(target_filename, pro_json_document) > 0 | ||
end | ||
|
||
def error_for_retrieve(ctx, response:, diagram_slug:, **) | ||
ctx[:error_message] = %(Diagram #{diagram_slug.inspect} couldn't be retrieved. HTTP status: #{response.status}) | ||
end | ||
end | ||
|
||
end # Task | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "test_helper" | ||
require "trailblazer/workflow/task/import" # FIXME. | ||
|
||
class ImportTaskTest < Minitest::Spec | ||
let(:api_key) { "tpka_909ae987_c834_43e4_9869_2eefd2aa9bcf" } | ||
let(:trailblazer_pro_host) { "https://testbackend-pro.trb.to" } # NOTE: it's a bit clumsy to share PRO testing knowledge across several gems, but this code belongs here. | ||
|
||
let(:session_static_options) do | ||
{ | ||
api_key: api_key, | ||
trailblazer_pro_host: trailblazer_pro_host, | ||
firebase_refresh_url: "https://securetoken.googleapis.com/v1/token?key=AIzaSyDVZOdUrI6wOji774hGU0yY_cQw9OAVwzs", | ||
} | ||
end # FIXME: do we need this? | ||
|
||
|
||
it "Import retrieves editor JSON file" do | ||
#@ Uninitialized sigin | ||
initial_session = Trailblazer::Pro::Session::Uninitialized.new(trailblazer_pro_host: trailblazer_pro_host, api_key: api_key) | ||
|
||
# 79d163 /tmp/79d163.json | ||
signal, (ctx, _) = Trailblazer::Developer.wtf?(Trailblazer::Workflow::Task::Import, [{ | ||
session: initial_session, | ||
diagram_slug: "79d163", | ||
target_filename: "/tmp/79d163.json", | ||
}, {}]) | ||
|
||
assert_equal signal.to_h[:semantic], :success | ||
assert_equal File.read("/tmp/79d163.json").size, 4635 | ||
# output, _ = capture_io do | ||
end | ||
end |