Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/bas/utils/operaton/process_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ def deploy_process(file_path, deployment_name:)
def instance_with_business_key_exists?(process_key, business_key)
query_params = {
processDefinitionKey: process_key,
maxResults: 50
maxResults: 50,
active: true
}

response = get("/history/process-instance", query_params)
response.any? { |instance| instance["businessKey"] == business_key }
end

def start_process_instance_by_key(process_key, business_key:, variables: {}, validate_business_key: true)
validate_uniqueness!(process_key, business_key) if validate_business_key

def start_process_instance_by_key(process_key, business_key:, variables: {})
json_payload = {
businessKey: business_key,
variables: format_variables(variables)
Expand All @@ -72,12 +71,6 @@ def build_conn
f.adapter Faraday.default_adapter
end
end

def validate_uniqueness!(process_key, business_key)
return unless instance_with_business_key_exists?(process_key, business_key)

raise "There is already an instance for processing '#{process_key}' with business key '#{business_key}'"
end
end
end
end
20 changes: 0 additions & 20 deletions spec/bas/operaton/process_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,10 @@
[200, { "Content-Type" => "application/json" }, '{"id": "inst1"}']
end

allow(client).to receive(:instance_with_business_key_exists?).and_return(false)

response = client.start_process_instance_by_key(process_key, business_key: business_key,
variables: { amount: 100 })
expect(response).to eq({ "id" => "inst1" })
end

it "raises an error if business key already exists and validation is on" do
allow(client).to receive(:instance_with_business_key_exists?).with(process_key, business_key).and_return(true)

expect do
client.start_process_instance_by_key(process_key, business_key: business_key, validate_business_key: true)
end.to raise_error("There is already an instance for processing 'my-process' with business key 'biz-123'")
end

it "does not raise an error if business key exists and validation is off" do
stubs.post("#{base_url}/process-definition/key/#{process_key}/start") do
[200, { "Content-Type" => "application/json" }, '{"id": "inst2"}']
end

expect(client).not_to receive(:instance_with_business_key_exists?)

client.start_process_instance_by_key(process_key, business_key: business_key, validate_business_key: false)
end
end

describe "#instance_with_business_key_exists?" do
Expand Down
Loading