diff --git a/lib/bas/utils/operaton/process_client.rb b/lib/bas/utils/operaton/process_client.rb index 96cbdad..8382633 100644 --- a/lib/bas/utils/operaton/process_client.rb +++ b/lib/bas/utils/operaton/process_client.rb @@ -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) @@ -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 diff --git a/spec/bas/operaton/process_client_spec.rb b/spec/bas/operaton/process_client_spec.rb index 3531597..34e98ca 100644 --- a/spec/bas/operaton/process_client_spec.rb +++ b/spec/bas/operaton/process_client_spec.rb @@ -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