From d72ee26d2101e661e6df4cd6600920fda7f27b43 Mon Sep 17 00:00:00 2001 From: an-tk Date: Mon, 25 Oct 2021 19:51:37 +0300 Subject: [PATCH 1/9] Added tests for few endpoints --- .gitignore | 3 +- .rspec | 3 +- README.md | 28 +- tests/.env.example | 5 + tests/Gemfile | 2 +- tests/spec/unit_tests_using_jwt_spec.rb | 494 ++++++++++++++++-------- 6 files changed, 373 insertions(+), 162 deletions(-) create mode 100644 tests/.env.example diff --git a/.gitignore b/.gitignore index 1e8cace8..ced81a41 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,5 @@ build-iPhoneSimulator/ .rvmrc tests/docs/private.pem -Gemfile.* \ No newline at end of file +tests/.env +Gemfile.* diff --git a/.rspec b/.rspec index d74dd626..7c4bbb4d 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --color ---require spec_helper ---debuger +--default-path 'tests' diff --git a/README.md b/README.md index dcd2241f..9391dda3 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,32 @@ For details regarding which type of OAuth grant will work best for your DocuSign For security purposes, DocuSign recommends using the [Authorization Code Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) flow. +## Running tests: + +To run tests, you need: +1. Create a .env file at the `tests` dir (or rename an existing .env.example file) +2. Enter your data from the developer account +* SECRET=< The secret key of your application > \ + settings => Apps and Keys => + Apps and Integration Keys your app "ACTIONS" => Edit => + Authentication => Secret Keys +* INTEGRATOR_KEY_JWT=< your Integration Key > \ + settings => Apps and Keys => Integration Key of your app +* TEMPLATE_ID=< your template id > \ + templates => in MyTemplates list click by choosen template => template id +* USER_ID=< your User ID > \ + settings => Apps and Keys => User ID + +3. Copy private key to `tests/docs/private.pem ` \ + Settings => "Apps and Keys" + in Apps and Integration Keys choose your application name => "ACTIONS" Edit => Service Integration => + GENERATE RSA + +4. Install dependencies bundle install + +5. Run tests: \ + `cd tests`\ + `rspec` + ## Support Log issues against this client through GitHub. We also have an [active developer community on Stack Overflow](https://stackoverflow.com/questions/tagged/docusignapi). @@ -48,4 +74,4 @@ The DocuSign eSignature Ruby Client SDK is licensed under the [MIT License](http * [DocuSign Developer Center](https://developers.docusign.com/) * [DocuSign API on Twitter](https://twitter.com/docusignapi) * [DocuSign For Developers on LinkedIn](https://www.linkedin.com/showcase/docusign-for-developers/) -* [DocuSign For Developers on YouTube](https://www.youtube.com/channel/UCJSJ2kMs_qeQotmw4-lX2NQ) \ No newline at end of file +* [DocuSign For Developers on YouTube](https://www.youtube.com/channel/UCJSJ2kMs_qeQotmw4-lX2NQ) diff --git a/tests/.env.example b/tests/.env.example new file mode 100644 index 00000000..786ea001 --- /dev/null +++ b/tests/.env.example @@ -0,0 +1,5 @@ +RECIPIENT_EMAIL = 'email@example.com' +SECRET = 'xxx' +INTEGRATOR_KEY_JWT='xxx' +TEMPLATE_ID = 'xxx' +USER_ID='xxx' diff --git a/tests/Gemfile b/tests/Gemfile index 0e06e1ee..9a6662d5 100644 --- a/tests/Gemfile +++ b/tests/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' gem 'rspec' - +gem 'dotenv' gem 'docusign_esign', path: '../' diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index 15b2eeb0..69e6bc37 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -1,3 +1,4 @@ +require 'dotenv/load' require 'docusign_esign' require 'base64' require 'uri' @@ -10,18 +11,13 @@ def login configuration.host = $host $api_client = DocuSign_eSign::ApiClient.new(configuration) - $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) - # $api_client.get_authorization_uri($integrator_key,'signature',$return_url,'code') - # $api_client.request_jwt_application_token($integrator_key,File.read($private_key_filename),$expires_in_seconds,'' ) + $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) + # $api_client.get_authorization_uri($integrator_key,%w[signature impersonation],$return_url,'code') + # $api_client.request_jwt_application_token($integrator_key,File.read($private_key_filename),$expires_in_seconds,%w[signature impersonation] ) # code = 'code_here' # $api_client.generate_access_token($integrator_key,$secret,code) end - decode_base64_content = Base64.decode64(ENV["PRIVATE_KEY"]) - File.open($private_key_filename, "wb") do |f| - f.write(decode_base64_content) - end - token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"],ENV["USER_ID"], File.read($private_key_filename),$expires_in_seconds) user_info = $api_client.get_user_info(token_obj.access_token) @@ -60,13 +56,13 @@ def create_api_client def create_envelope_on_document(status, is_embedded_signing) if(!$account_id.nil?) # STEP 2: Create envelope definition - # Add a document to the envelope - document_path = "../docs/Test.pdf" + # Add a document to the envelope + document_path = "docs/Test.pdf" document_name = "Test.docx" document = DocuSign_eSign::Document.new - document.document_base64 = Base64.encode64(File.open(document_path).read) - document.name = document_name - document.document_id = '1' + document.document_base64 = Base64.encode64(File.open(document_path).read) + document.name = document_name + document.document_id = '1' # Create a |SignHere| tab somewhere on the document for the recipient to sign signHere = DocuSign_eSign::SignHere.new @@ -117,13 +113,15 @@ def create_envelope_on_document(status, is_embedded_signing) $expires_in_seconds = 3600 #1 hour $auth_server = 'account-d.docusign.com' - $private_key_filename = '../docs/private.pem' - - $recipient_name = "Ruby SDK" + $private_key_filename = 'docs/private.pem' + + $recipient_name = "Ruby SDK" - # Required for embedded signing url - $client_user_id = '1234' - $return_url = 'https://developers.docusign.com/' + # Required for embedded signing url + $client_user_id = ENV['USER_ID'] + $integrator_key = ENV['INTEGRATOR_KEY_JWT'] + $secret = ENV['SECRET'] + $return_url = 'https://developers.docusign.com/' $authentication_method = 'email' $template_id = '' @@ -139,7 +137,7 @@ def create_envelope_on_document(status, is_embedded_signing) end describe DocuSign_eSign::OAuth do - describe '.login' do + describe '.login' do context 'given correct credentials' do it 'return Account' do account = login() @@ -157,7 +155,7 @@ def create_envelope_on_document(status, is_embedded_signing) end describe DocuSign_eSign::EnvelopesApi do - describe '.create' do + describe '.create' do context 'request signature on a document' do it 'successfully create an envelope' do @@ -173,117 +171,193 @@ def create_envelope_on_document(status, is_embedded_signing) expect($envelope_id).to be_truthy end end - end + end - context 'request signature using a template' do - it 'successfully send an envelope' do - # TODO - end - end + context 'create tabs for recipient' do + it 'successfully creates tabs' do + tabs_summary = nil + created_tab = nil + new_tab_name = 'NewTabName' - context 'sender view' do - it 'successfully returns sender view url' do - view_url = nil - - if !$envelope_id.nil? - api_client = create_api_client() + if !$envelope_id.nil? + api_client = create_api_client() envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + recipients = envelopes_api.list_recipients($account_id, $envelope_id) + signer = recipients.signers.first + recipient_id = signer.recipient_id + + + # Build new tab somewhere on the document for the recipient to sign + sign_tab = DocuSign_eSign::SignHere.new + sign_tab.name = new_tab_name + sign_tab.anchor_units = 'pixels' + sign_tab.anchor_y_offset = '123' + sign_tab.anchor_x_offset = '234' + sign_tab.document_id = '1' + sign_tab.page_number = '1' + sign_tab.recipient_id = '1' + + tabs = DocuSign_eSign::Tabs.new + tabs.sign_here_tabs = Array(sign_tab) + + # send create request + tabs_summary = envelopes_api.create_tabs($account_id, $envelope_id, recipient_id, tabs) + + tabs_list = envelopes_api.list_tabs($account_id, $envelope_id, recipient_id) + created_tab = tabs_list.sign_here_tabs.last + end + + expect(tabs_summary).to be_truthy + expect(tabs_summary).to be_a(DocuSign_eSign::Tabs) + expect(created_tab).to be_a(DocuSign_eSign::SignHere) + expect(created_tab.name).to eq(new_tab_name) + end + end - return_url_request = DocuSign_eSign::ReturnUrlRequest.new - return_url_request.return_url = $return_url + context 'create user' do + it 'successfully creates user' do + user = nil - view_url = envelopes_api.create_sender_view($account_id, $envelope_id, return_url_request) - end + user_information = DocuSign_eSign::UserInformation.new + user_information.email = 'test-user@example.com' + user_information.first_name = 'user-name' + user_information.last_name = 'user-last-name' + user_information.user_name = 'test-user-name' - expect(view_url).to be_truthy - if !view_url.nil? - expect(view_url.url).to be_truthy - end + if !$account_id.nil? + api_client = create_api_client() + users_api = DocuSign_eSign::UsersApi.new(api_client) + + user_definition = DocuSign_eSign::NewUsersDefinition.new + user_definition.new_users = Array(user_information) + + users_summary = users_api.create($account_id, user_definition) + user = users_summary.new_users.last + end + + expect(user).to be_truthy + expect(user).to be_a(DocuSign_eSign::NewUser) + expect(user.email).to eq(user_information.email) + expect(user.user_name).to eq(user_information.user_name) + end + end + + context 'request signature using a template' do + it 'successfully send an envelope' do + # TODO end end + end - context 'recipient view' do - it 'successfully returns embedded signing view url' do - view_url = nil + describe '.update' do + context 'update envelope' do + it 'updates envelope' do + updated_envelope = nil + envelope = nil + if !$envelope_id.nil? - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + envelope = DocuSign_eSign::EnvelopeDefinition.new + envelope.envelope_id = $envelope_id + envelope.email_subject = 'new email subject' + envelope.email_blurb = 'new email message' + envelope.status = 'created' + envelopes_api = DocuSign_eSign::EnvelopesApi.new(create_api_client) - envelope = DocuSign_eSign::Envelope.new - envelope.status = 'sent' + update_result = envelopes_api.update($account_id, $envelope_id, envelope) - options = DocuSign_eSign::UpdateOptions.new + updated_envelope = envelopes_api.get_envelope($account_id, update_result.envelope_id) + updated_envelope + end - envelope_update_summary = envelopes_api.update($account_id, $envelope_id, envelope, options) + expect(updated_envelope).not_to be_nil + expect(updated_envelope.email_subject).to eq(envelope.email_subject) + expect(updated_envelope.email_blurb).to eq(envelope.email_blurb) + expect(updated_envelope.status).to eq(envelope.status) + end + end - expect(envelope_update_summary).to be_truthy - if(!envelope_update_summary.nil?) - expect(envelope_update_summary.envelope_id).to be_truthy - end + context 'updates envelope recipients' do + it 'successfully updates envelope recipients' do + envelope = create_envelope_on_document('sent', true) - recipient_view_request = DocuSign_eSign::RecipientViewRequest.new - recipient_view_request.return_url = $return_url - recipient_view_request.client_user_id = $client_user_id - recipient_view_request.authentication_method = $authentication_method - recipient_view_request.user_name = $recipient_name - recipient_view_request.email = ENV["RECIPIENT_EMAIL"] + signer = DocuSign_eSign::Signer.new( + email: 'test_recipient@example.com', + name: 'test_name', + routingOrder: '3', + recipientId: '3', + ) - view_url = envelopes_api.create_recipient_view($account_id, $envelope_id, recipient_view_request) - end - expect(view_url).to be_truthy - if !view_url.nil? - expect(view_url.url).to be_truthy - end - end - end + cc = DocuSign_eSign::CarbonCopy.new( + email: 'test_recipient@example.com', + name: 'test_cc_name', + routingOrder: '4', + recipientId: '4', + ) - context 'embedded console view' do - it 'successfully returns embedded console view url' do - view_url = nil + recipients = DocuSign_eSign::Recipients.new( + signers: [signer], + carbonCopies: [cc] + ) - if !$envelope_id.nil? - api_client = create_api_client() + if !envelope.nil? + api_client = create_api_client() envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + options = DocuSign_eSign::UpdateRecipientsOptions.new - console_view_request = DocuSign_eSign::ConsoleViewRequest.new - console_view_request.envelope_id = $envelope_id - console_view_request.return_url = $return_url - - view_url = envelopes_api.create_console_view($account_id, console_view_request) - end + update_result = envelopes_api.update_recipients($account_id, envelope.envelope_id, recipients, options) + end - expect(view_url).to be_truthy - if !view_url.nil? - expect(view_url.url).to be_truthy - end - end - end - end + expect(update_result).to be_truthy + if !update_result.nil? + expect(update_result.recipient_update_results.map(&:recipient_id)).to match_array([signer.recipient_id, cc.recipient_id]) + end + end + end + end - describe '.get' do - context 'get envelope information' do + describe '.get' do + context 'get envelope information' do it 'successfully returns envelope summary' do - envelope_summary = nil + envelope_summary = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - options = DocuSign_eSign::GetEnvelopeOptions.new + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + options = DocuSign_eSign::GetEnvelopeOptions.new - envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) + envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) + end + + expect(envelope_summary).to be_truthy + if !envelope_summary.nil? + expect(envelope_summary.envelope_id).to eq($envelope_id) + end end + end + + context 'get users information' do + it 'successfully returns users info' do + users_information = nil + + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - expect(envelope_summary).to be_truthy - if !envelope_summary.nil? - expect(envelope_summary.envelope_id).to eq($envelope_id) + options = DocuSign_eSign::GetEnvelopeOptions.new + + users_information = envelopes_api.get_envelope($account_id, $envelope_id, options) + end + + expect(users_information).to be_truthy + if !users_information.nil? + expect(users_information.envelope_id).to eq($envelope_id) + end end - end - end + end - context 'get template information' do + context 'get template information' do it 'successfully returns template' do template_summary = nil @@ -305,53 +379,81 @@ def create_envelope_on_document(status, is_embedded_signing) expect(template_summary.template_id).to eq($template_id) end end - end + end - context 'get form data' do - it 'successfully returns envelope form data' do - envelope_form_data = nil + context 'get account information' do + it 'successfully returns account' do + api_client = create_api_client() + accounts_api = DocuSign_eSign::AccountsApi.new(api_client) + account_summary = accounts_api.get_account_information($account_id) - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - envelope_form_data = envelopes_api.get_form_data($account_id, $envelope_id) - end - - expect(envelope_form_data).to be_truthy - if !envelope_form_data.nil? - expect(envelope_form_data.form_data).to be_truthy - if !envelope_form_data.form_data.nil? + expect(account_summary).to be_truthy + if !account_summary.nil? + expect(account_summary.account_id_guid).to eq($account_id) + end + end + end + + context 'get form data' do + it 'successfully returns envelope form data' do + envelope_form_data = nil + + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + envelope_form_data = envelopes_api.get_form_data($account_id, $envelope_id) + end + + expect(envelope_form_data).to be_truthy + if !envelope_form_data.nil? expect(envelope_form_data.form_data).to be_truthy - # expect(envelope_form_data.form_data.length).to be > 0 - # if envelope_form_data.form_data.length > 0 - # expect(envelope_form_data.form_data[0].name).to be_truthy - # expect(envelope_form_data.prefill_form_data).to be_truthy - # if !envelope_form_data.prefill_form_data.nil? - # expect(envelope_form_data.prefill_form_data.form_data).to be_truthy - # expect(envelope_form_data.prefill_form_data.form_data.length).to be > 0 - # if envelope_form_data.prefill_form_data.form_data.length > 0 - # expect(envelope_form_data.prefill_form_data.form_data[0].name).to be_truthy - # end - # end - # end + if !envelope_form_data.form_data.nil? + expect(envelope_form_data.form_data).to be_truthy + # expect(envelope_form_data.form_data.length).to be > 0 + # if envelope_form_data.form_data.length > 0 + # expect(envelope_form_data.form_data[0].name).to be_truthy + # expect(envelope_form_data.prefill_form_data).to be_truthy + # if !envelope_form_data.prefill_form_data.nil? + # expect(envelope_form_data.prefill_form_data.form_data).to be_truthy + # expect(envelope_form_data.prefill_form_data.form_data.length).to be > 0 + # if envelope_form_data.prefill_form_data.form_data.length > 0 + # expect(envelope_form_data.prefill_form_data.form_data[0].name).to be_truthy + # end + # end + # end + end + end + end + end + + context 'get user logging setting' do + it 'successfully returns settings' do + diagnostics_settings_info = nil + + if !$account_id.nil? + api_client = create_api_client() + diagnostics_api = DocuSign_eSign::DiagnosticsApi.new(api_client) + + diagnostics_settings_info = diagnostics_api.get_request_log_settings end - end + + expect(diagnostics_settings_info).not_to be_nil + expect(diagnostics_settings_info).to be_a(DocuSign_eSign::DiagnosticsSettingsInformation) + end end - end end - describe '.list' do - context 'list envelopes' do + describe '.list' do + context 'list envelopes' do it 'successfully list envelope' do - recipients = nil - - envelope_ids = "" + recipients = nil + envelope_ids = "" count1 = 0 count2 = 0 if !$envelope_id.nil? - api_client = create_api_client() + api_client = create_api_client() envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) options = DocuSign_eSign::ListStatusChangesOptions.new @@ -381,7 +483,7 @@ def create_envelope_on_document(status, is_embedded_signing) end end - context 'list recipients' do + context 'list recipients' do it 'successfully list envelope recipients' do recipients = nil @@ -401,7 +503,7 @@ def create_envelope_on_document(status, is_embedded_signing) end end - context 'list status changes' do + context 'list status changes' do it 'successfully lists envelope status changes' do envelopes_information = nil @@ -422,7 +524,7 @@ def create_envelope_on_document(status, is_embedded_signing) end end - context 'list documents and download' do + context 'list documents and download' do it 'successfully lists and download envelope documents' do envelope_documents_result = nil @@ -453,32 +555,110 @@ def create_envelope_on_document(status, is_embedded_signing) end end end - end - end + end - context 'list tabs' do - it 'successfully lists envelope tabs' do - envelope_summary = nil + context 'list tabs' do + it 'successfully lists envelope tabs' do + envelope_summary = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - options = DocuSign_eSign::GetEnvelopeOptions.new + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + options = DocuSign_eSign::GetEnvelopeOptions.new + + envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) - envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) + options = DocuSign_eSign::ListRecipientsOptions.new + + recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) + + tabs = envelopes_api.list_tabs($account_id, $envelope_id, recipients.signers[0].recipient_id) + + sign_here_tabs = tabs.sign_here_tabs + + expect(sign_here_tabs).to be_truthy + end + end + end + + context 'list users' do + it 'successfully list account users' do + user_info_list = nil + + if !$account_id.nil? + api_client = create_api_client() + users_api = DocuSign_eSign::UsersApi.new(api_client) + options = DocuSign_eSign::ListOptions.new + + user_info_list = users_api.list($account_id, options) + end + + expect(user_info_list).to be_truthy + if !user_info_list.nil? + expect(user_info_list.users).not_to be_empty + end + end + end + + context 'list audit events' do + it 'successfully list envelope audit events' do + audit_events_response = nil - options = DocuSign_eSign::ListRecipientsOptions.new + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) + audit_events_response = envelopes_api.list_audit_events($account_id, $envelope_id) + end - tabs = envelopes_api.list_tabs($account_id, $envelope_id, recipients.signers[0].recipient_id) + expect(audit_events_response).to be_truthy + if !audit_events_response.nil? + expect(audit_events_response.audit_events).not_to be_empty + end + end + end - sign_here_tabs = tabs.sign_here_tabs + context 'list envelope statuses' do + it 'returns envelope statuses' do + status = nil + if !$envelope_id.nil? + envelopes_api = DocuSign_eSign::EnvelopesApi.new(create_api_client) + envelope = envelopes_api.get_envelope($account_id, $envelope_id) + + list_status_options = DocuSign_eSign::ListStatusOptions.new + list_status_options.envelope_ids = $envelope_id + list_status_options.transaction_ids = envelope.transaction_id + + envelope_ids_request = DocuSign_eSign::EnvelopeIdsRequest.new + envelope_ids_request.envelope_ids = Array($envelope_id) + envelope_ids_request.transaction_ids = Array(envelope.transaction_id) + + status = envelopes_api.list_status($account_id, envelope_ids_request, list_status_options) + end + + expect(status).not_to be_nil + expect(status).to be_a(DocuSign_eSign::EnvelopesInformation) + expect(status.envelopes).not_to be_nil + expect(status.envelopes.size > 0).to be_truthy + end + end + + context 'list custom fields' do + it 'successfully list custom fields' do + custom_fields = nil + + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + custom_fields = envelopes_api.list_custom_fields($account_id, $envelope_id) + end - expect(sign_here_tabs).to be_truthy + expect(custom_fields).to be_truthy + expect(custom_fields).to be_a(DocuSign_eSign::CustomFieldsEnvelope) end end end end -end \ No newline at end of file +end From 8ab8c90f07415ac82fc8ec9c7d9e5c9a86e8dafd Mon Sep 17 00:00:00 2001 From: an-tk Date: Tue, 26 Oct 2021 22:10:38 +0300 Subject: [PATCH 2/9] Fix formatting: replace tab with whitespaces --- tests/spec/unit_tests_using_jwt_spec.rb | 952 ++++++++++++------------ 1 file changed, 468 insertions(+), 484 deletions(-) diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index 69e6bc37..2481c93c 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -4,126 +4,125 @@ require 'uri' describe 'DocuSign Ruby Client Tests' do - def login - begin - if $api_client.nil? - configuration = DocuSign_eSign::Configuration.new - configuration.host = $host + def login + begin + if $api_client.nil? + configuration = DocuSign_eSign::Configuration.new + configuration.host = $host + + $api_client = DocuSign_eSign::ApiClient.new(configuration) + $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) + # $api_client.get_authorization_uri($integrator_key,%w[signature impersonation],$return_url,'code') + # $api_client.request_jwt_application_token($integrator_key,File.read($private_key_filename),$expires_in_seconds,%w[signature impersonation] ) + # code = 'code_here' + # $api_client.generate_access_token($integrator_key,$secret,code) + end - $api_client = DocuSign_eSign::ApiClient.new(configuration) - $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) - # $api_client.get_authorization_uri($integrator_key,%w[signature impersonation],$return_url,'code') - # $api_client.request_jwt_application_token($integrator_key,File.read($private_key_filename),$expires_in_seconds,%w[signature impersonation] ) - # code = 'code_here' - # $api_client.generate_access_token($integrator_key,$secret,code) - end + token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds) - token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"],ENV["USER_ID"], File.read($private_key_filename),$expires_in_seconds) + user_info = $api_client.get_user_info(token_obj.access_token) - user_info = $api_client.get_user_info(token_obj.access_token) + if !user_info.nil? + user_info.accounts.each do |account| + if account.is_default == "true" + $base_uri = account.base_uri + $account_id = account.account_id + # IMPORTANT: Use the base url from the login account to instantiant the api_client + base_uri = URI.parse($base_uri) + $api_client.set_base_path("%s://%s/restapi" % [base_uri.scheme, base_uri.host]) - if !user_info.nil? - user_info.accounts.each do |account| - if account.is_default == "true" - $base_uri = account.base_uri - $account_id = account.account_id + return account + end + end + end + rescue => e + puts "Error during processing: #{$!}" + # puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" + end - # IMPORTANT: Use the base url from the login account to instantiant the api_client - base_uri = URI.parse($base_uri) - $api_client.set_base_path( "%s://%s/restapi" % [base_uri.scheme, base_uri.host]) - - return account - end - end - end - rescue => e - puts "Error during processing: #{$!}" - # puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" - end - - return nil - end - - def create_api_client - if $api_client.nil? - self.login() - end - - return $api_client - end - - def create_envelope_on_document(status, is_embedded_signing) - if(!$account_id.nil?) - # STEP 2: Create envelope definition - # Add a document to the envelope - document_path = "docs/Test.pdf" - document_name = "Test.docx" - document = DocuSign_eSign::Document.new - document.document_base64 = Base64.encode64(File.open(document_path).read) - document.name = document_name - document.document_id = '1' - - # Create a |SignHere| tab somewhere on the document for the recipient to sign - signHere = DocuSign_eSign::SignHere.new - signHere.x_position = "100" - signHere.y_position = "100" - signHere.document_id = "1" - signHere.page_number = "1" - signHere.recipient_id = "1" - - tabs = DocuSign_eSign::Tabs.new - tabs.sign_here_tabs = Array(signHere) - - signer = DocuSign_eSign::Signer.new - signer.email = ENV["RECIPIENT_EMAIL"] - signer.name = $recipient_name - signer.recipient_id = "1" - - if(is_embedded_signing) - signer.client_user_id = $client_user_id - end - - signer.tabs = tabs - - # Add a recipient to sign the document - recipients = DocuSign_eSign::Recipients.new - recipients.signers = Array(signer) - - envelop_definition = DocuSign_eSign::EnvelopeDefinition.new - envelop_definition.email_subject = "[DocuSign Ruby SDK] - Please sign this doc" - - # set envelope status to "sent" to immediately send the signature request - envelop_definition.status = status.nil? ? 'sent' : status - envelop_definition.recipients = recipients - envelop_definition.documents = Array(document) - - options = DocuSign_eSign::CreateEnvelopeOptions.new - - # STEP 3: Create envelope - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - return envelopes_api.create_envelope($account_id, envelop_definition, options) - end - end + return nil + end + + def create_api_client + if $api_client.nil? + self.login() + end + + return $api_client + end + + def create_envelope_on_document(status, is_embedded_signing) + if (!$account_id.nil?) + # STEP 2: Create envelope definition + # Add a document to the envelope + document_path = "docs/Test.pdf" + document_name = "Test.docx" + document = DocuSign_eSign::Document.new + document.document_base64 = Base64.encode64(File.open(document_path).read) + document.name = document_name + document.document_id = '1' + + # Create a |SignHere| tab somewhere on the document for the recipient to sign + signHere = DocuSign_eSign::SignHere.new + signHere.x_position = "100" + signHere.y_position = "100" + signHere.document_id = "1" + signHere.page_number = "1" + signHere.recipient_id = "1" + + tabs = DocuSign_eSign::Tabs.new + tabs.sign_here_tabs = Array(signHere) + + signer = DocuSign_eSign::Signer.new + signer.email = ENV["RECIPIENT_EMAIL"] + signer.name = $recipient_name + signer.recipient_id = "1" + + if (is_embedded_signing) + signer.client_user_id = $client_user_id + end + + signer.tabs = tabs + + # Add a recipient to sign the document + recipients = DocuSign_eSign::Recipients.new + recipients.signers = Array(signer) + + envelop_definition = DocuSign_eSign::EnvelopeDefinition.new + envelop_definition.email_subject = "[DocuSign Ruby SDK] - Please sign this doc" + + # set envelope status to "sent" to immediately send the signature request + envelop_definition.status = status.nil? ? 'sent' : status + envelop_definition.recipients = recipients + envelop_definition.documents = Array(document) + + options = DocuSign_eSign::CreateEnvelopeOptions.new + + # STEP 3: Create envelope + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + return envelopes_api.create_envelope($account_id, envelop_definition, options) + end + end before(:all) do # run before each test $host = "https://demo.docusign.net/restapi" - $expires_in_seconds = 3600 #1 hour - $auth_server = 'account-d.docusign.com' - $private_key_filename = 'docs/private.pem' + $expires_in_seconds = 3600 #1 hour + $auth_server = 'account-d.docusign.com' + $private_key_filename = 'docs/private.pem' - $recipient_name = "Ruby SDK" + $recipient_name = "Ruby SDK" - # Required for embedded signing url - $client_user_id = ENV['USER_ID'] - $integrator_key = ENV['INTEGRATOR_KEY_JWT'] - $secret = ENV['SECRET'] - $return_url = 'https://developers.docusign.com/' + # Required for embedded signing url + $client_user_id = ENV['USER_ID'] + $integrator_key = ENV['INTEGRATOR_KEY_JWT'] + $secret = ENV['SECRET'] + $return_url = 'https://developers.docusign.com/' $authentication_method = 'email' - + $template_id = '' $envelope_id = nil @@ -138,527 +137,512 @@ def create_envelope_on_document(status, is_embedded_signing) describe DocuSign_eSign::OAuth do describe '.login' do - context 'given correct credentials' do - it 'return Account' do - account = login() - - if !account.nil? - $base_uri = account.base_uri - $account_id = account.account_id - end - - expect($account_id).to be_truthy - expect($base_uri).to be_truthy - end - end - end + context 'given correct credentials' do + it 'return Account' do + account = login() + + if !account.nil? + $base_uri = account.base_uri + $account_id = account.account_id + end + + expect($account_id).to be_truthy + expect($base_uri).to be_truthy + end + end + end end describe DocuSign_eSign::EnvelopesApi do describe '.create' do - context 'request signature on a document' do - it 'successfully create an envelope' do - - # STEP 1: Login and get the account_id & base_uri - login() + context 'request signature on a document' do + it 'successfully create an envelope' do + + # STEP 1: Login and get the account_id & base_uri + login() - envelope_summary = create_envelope_on_document('created', true) + envelope_summary = create_envelope_on_document('created', true) - expect(envelope_summary).to be_truthy + expect(envelope_summary).to be_truthy - if !envelope_summary.nil? - $envelope_id = envelope_summary.envelope_id - expect($envelope_id).to be_truthy - end - end + if !envelope_summary.nil? + $envelope_id = envelope_summary.envelope_id + expect($envelope_id).to be_truthy + end + end end context 'create tabs for recipient' do - it 'successfully creates tabs' do + it 'successfully creates tabs' do tabs_summary = nil - created_tab = nil + created_tab = nil new_tab_name = 'NewTabName' - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - recipients = envelopes_api.list_recipients($account_id, $envelope_id) - signer = recipients.signers.first - recipient_id = signer.recipient_id - - - # Build new tab somewhere on the document for the recipient to sign - sign_tab = DocuSign_eSign::SignHere.new - sign_tab.name = new_tab_name - sign_tab.anchor_units = 'pixels' - sign_tab.anchor_y_offset = '123' - sign_tab.anchor_x_offset = '234' - sign_tab.document_id = '1' - sign_tab.page_number = '1' - sign_tab.recipient_id = '1' - - tabs = DocuSign_eSign::Tabs.new - tabs.sign_here_tabs = Array(sign_tab) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + recipients = envelopes_api.list_recipients($account_id, $envelope_id) + signer = recipients.signers.first + recipient_id = signer.recipient_id + + # Build new tab somewhere on the document for the recipient to sign + sign_tab = DocuSign_eSign::SignHere.new + sign_tab.name = new_tab_name + sign_tab.anchor_units = 'pixels' + sign_tab.anchor_y_offset = '123' + sign_tab.anchor_x_offset = '234' + sign_tab.document_id = '1' + sign_tab.page_number = '1' + sign_tab.recipient_id = '1' + + tabs = DocuSign_eSign::Tabs.new + tabs.sign_here_tabs = Array(sign_tab) # send create request - tabs_summary = envelopes_api.create_tabs($account_id, $envelope_id, recipient_id, tabs) + tabs_summary = envelopes_api.create_tabs($account_id, $envelope_id, recipient_id, tabs) - tabs_list = envelopes_api.list_tabs($account_id, $envelope_id, recipient_id) - created_tab = tabs_list.sign_here_tabs.last + tabs_list = envelopes_api.list_tabs($account_id, $envelope_id, recipient_id) + created_tab = tabs_list.sign_here_tabs.last end - expect(tabs_summary).to be_truthy - expect(tabs_summary).to be_a(DocuSign_eSign::Tabs) + expect(tabs_summary).to be_truthy + expect(tabs_summary).to be_a(DocuSign_eSign::Tabs) expect(created_tab).to be_a(DocuSign_eSign::SignHere) expect(created_tab.name).to eq(new_tab_name) - end + end end context 'create user' do - it 'successfully creates user' do + it 'successfully creates user' do user = nil - user_information = DocuSign_eSign::UserInformation.new - user_information.email = 'test-user@example.com' - user_information.first_name = 'user-name' - user_information.last_name = 'user-last-name' - user_information.user_name = 'test-user-name' + user_information = DocuSign_eSign::UserInformation.new + user_information.email = 'test-user@example.com' + user_information.first_name = 'user-name' + user_information.last_name = 'user-last-name' + user_information.user_name = 'test-user-name' - if !$account_id.nil? - api_client = create_api_client() + if !$account_id.nil? + api_client = create_api_client() users_api = DocuSign_eSign::UsersApi.new(api_client) - user_definition = DocuSign_eSign::NewUsersDefinition.new - user_definition.new_users = Array(user_information) + user_definition = DocuSign_eSign::NewUsersDefinition.new + user_definition.new_users = Array(user_information) - users_summary = users_api.create($account_id, user_definition) - user = users_summary.new_users.last - end + users_summary = users_api.create($account_id, user_definition) + user = users_summary.new_users.last + end - expect(user).to be_truthy - expect(user).to be_a(DocuSign_eSign::NewUser) - expect(user.email).to eq(user_information.email) - expect(user.user_name).to eq(user_information.user_name) - end - end + expect(user).to be_truthy + expect(user).to be_a(DocuSign_eSign::NewUser) + expect(user.email).to eq(user_information.email) + expect(user.user_name).to eq(user_information.user_name) + end + end context 'request signature using a template' do - it 'successfully send an envelope' do - # TODO - end - end - end + it 'successfully send an envelope' do + # TODO + end + end + end describe '.update' do context 'update envelope' do - it 'updates envelope' do - updated_envelope = nil - envelope = nil - if !$envelope_id.nil? - - envelope = DocuSign_eSign::EnvelopeDefinition.new - envelope.envelope_id = $envelope_id - envelope.email_subject = 'new email subject' - envelope.email_blurb = 'new email message' - envelope.status = 'created' - envelopes_api = DocuSign_eSign::EnvelopesApi.new(create_api_client) + it 'updates envelope' do + updated_envelope = nil + envelope = nil + if !$envelope_id.nil? + + envelope = DocuSign_eSign::EnvelopeDefinition.new + envelope.envelope_id = $envelope_id + envelope.email_subject = 'new email subject' + envelope.email_blurb = 'new email message' + envelope.status = 'created' + envelopes_api = DocuSign_eSign::EnvelopesApi.new(create_api_client) - update_result = envelopes_api.update($account_id, $envelope_id, envelope) + update_result = envelopes_api.update($account_id, $envelope_id, envelope) - updated_envelope = envelopes_api.get_envelope($account_id, update_result.envelope_id) - updated_envelope - end + updated_envelope = envelopes_api.get_envelope($account_id, update_result.envelope_id) + updated_envelope + end expect(updated_envelope).not_to be_nil expect(updated_envelope.email_subject).to eq(envelope.email_subject) expect(updated_envelope.email_blurb).to eq(envelope.email_blurb) expect(updated_envelope.status).to eq(envelope.status) - end + end end context 'updates envelope recipients' do - it 'successfully updates envelope recipients' do + it 'successfully updates envelope recipients' do envelope = create_envelope_on_document('sent', true) - signer = DocuSign_eSign::Signer.new( - email: 'test_recipient@example.com', - name: 'test_name', - routingOrder: '3', - recipientId: '3', - ) - + signer = DocuSign_eSign::Signer.new(email: 'test_recipient@example.com', name: 'test_name', routingOrder: '3', recipientId: '3',) - cc = DocuSign_eSign::CarbonCopy.new( - email: 'test_recipient@example.com', - name: 'test_cc_name', - routingOrder: '4', - recipientId: '4', - ) + cc = DocuSign_eSign::CarbonCopy.new(email: 'test_recipient@example.com', name: 'test_cc_name', routingOrder: '4', recipientId: '4',) - recipients = DocuSign_eSign::Recipients.new( - signers: [signer], - carbonCopies: [cc] - ) + recipients = DocuSign_eSign::Recipients.new(signers: [signer], carbonCopies: [cc] + ) - if !envelope.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - options = DocuSign_eSign::UpdateRecipientsOptions.new + if !envelope.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + options = DocuSign_eSign::UpdateRecipientsOptions.new - update_result = envelopes_api.update_recipients($account_id, envelope.envelope_id, recipients, options) - end + update_result = envelopes_api.update_recipients($account_id, envelope.envelope_id, recipients, options) + end - expect(update_result).to be_truthy - if !update_result.nil? - expect(update_result.recipient_update_results.map(&:recipient_id)).to match_array([signer.recipient_id, cc.recipient_id]) - end - end + expect(update_result).to be_truthy + if !update_result.nil? + expect(update_result.recipient_update_results.map(&:recipient_id)).to match_array([signer.recipient_id, cc.recipient_id]) + end + end end - end + end describe '.get' do context 'get envelope information' do - it 'successfully returns envelope summary' do - envelope_summary = nil + it 'successfully returns envelope summary' do + envelope_summary = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - options = DocuSign_eSign::GetEnvelopeOptions.new + options = DocuSign_eSign::GetEnvelopeOptions.new - envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) - end + envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) + end - expect(envelope_summary).to be_truthy - if !envelope_summary.nil? - expect(envelope_summary.envelope_id).to eq($envelope_id) - end - end + expect(envelope_summary).to be_truthy + if !envelope_summary.nil? + expect(envelope_summary.envelope_id).to eq($envelope_id) + end + end end context 'get users information' do - it 'successfully returns users info' do - users_information = nil + it 'successfully returns users info' do + users_information = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - options = DocuSign_eSign::GetEnvelopeOptions.new + options = DocuSign_eSign::GetEnvelopeOptions.new - users_information = envelopes_api.get_envelope($account_id, $envelope_id, options) - end + users_information = envelopes_api.get_envelope($account_id, $envelope_id, options) + end - expect(users_information).to be_truthy - if !users_information.nil? - expect(users_information.envelope_id).to eq($envelope_id) - end - end - end + expect(users_information).to be_truthy + if !users_information.nil? + expect(users_information.envelope_id).to eq($envelope_id) + end + end + end context 'get template information' do - it 'successfully returns template' do - template_summary = nil - - if !$envelope_id.nil? - api_client = create_api_client() - templates_api = DocuSign_eSign::TemplatesApi.new(api_client) - - options = DocuSign_eSign::GetEnvelopeOptions.new - $template_id = ENV["TEMPLATE_ID"] - - options = DocuSign_eSign::GetOptions.new - options.include = "tabs" - - template_summary = templates_api.get($account_id, $template_id, options) - end - - expect(template_summary).to be_truthy - if !template_summary.nil? - expect(template_summary.template_id).to eq($template_id) - end - end + it 'successfully returns template' do + template_summary = nil + + if !$envelope_id.nil? + api_client = create_api_client() + templates_api = DocuSign_eSign::TemplatesApi.new(api_client) + + options = DocuSign_eSign::GetEnvelopeOptions.new + $template_id = ENV["TEMPLATE_ID"] + + options = DocuSign_eSign::GetOptions.new + options.include = "tabs" + + template_summary = templates_api.get($account_id, $template_id, options) + end + + expect(template_summary).to be_truthy + if !template_summary.nil? + expect(template_summary.template_id).to eq($template_id) + end + end end context 'get account information' do - it 'successfully returns account' do - api_client = create_api_client() + it 'successfully returns account' do + api_client = create_api_client() accounts_api = DocuSign_eSign::AccountsApi.new(api_client) - account_summary = accounts_api.get_account_information($account_id) + account_summary = accounts_api.get_account_information($account_id) - expect(account_summary).to be_truthy - if !account_summary.nil? - expect(account_summary.account_id_guid).to eq($account_id) - end - end - end + expect(account_summary).to be_truthy + if !account_summary.nil? + expect(account_summary.account_id_guid).to eq($account_id) + end + end + end context 'get form data' do - it 'successfully returns envelope form data' do - envelope_form_data = nil - - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - envelope_form_data = envelopes_api.get_form_data($account_id, $envelope_id) - end - - expect(envelope_form_data).to be_truthy - if !envelope_form_data.nil? - expect(envelope_form_data.form_data).to be_truthy - if !envelope_form_data.form_data.nil? - expect(envelope_form_data.form_data).to be_truthy - # expect(envelope_form_data.form_data.length).to be > 0 - # if envelope_form_data.form_data.length > 0 - # expect(envelope_form_data.form_data[0].name).to be_truthy - # expect(envelope_form_data.prefill_form_data).to be_truthy - # if !envelope_form_data.prefill_form_data.nil? - # expect(envelope_form_data.prefill_form_data.form_data).to be_truthy - # expect(envelope_form_data.prefill_form_data.form_data.length).to be > 0 - # if envelope_form_data.prefill_form_data.form_data.length > 0 - # expect(envelope_form_data.prefill_form_data.form_data[0].name).to be_truthy - # end - # end - # end - end - end - end + it 'successfully returns envelope form data' do + envelope_form_data = nil + + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + envelope_form_data = envelopes_api.get_form_data($account_id, $envelope_id) + end + + expect(envelope_form_data).to be_truthy + if !envelope_form_data.nil? + expect(envelope_form_data.form_data).to be_truthy + if !envelope_form_data.form_data.nil? + expect(envelope_form_data.form_data).to be_truthy + # expect(envelope_form_data.form_data.length).to be > 0 + # if envelope_form_data.form_data.length > 0 + # expect(envelope_form_data.form_data[0].name).to be_truthy + # expect(envelope_form_data.prefill_form_data).to be_truthy + # if !envelope_form_data.prefill_form_data.nil? + # expect(envelope_form_data.prefill_form_data.form_data).to be_truthy + # expect(envelope_form_data.prefill_form_data.form_data.length).to be > 0 + # if envelope_form_data.prefill_form_data.form_data.length > 0 + # expect(envelope_form_data.prefill_form_data.form_data[0].name).to be_truthy + # end + # end + # end + end + end + end end context 'get user logging setting' do - it 'successfully returns settings' do - diagnostics_settings_info = nil + it 'successfully returns settings' do + diagnostics_settings_info = nil - if !$account_id.nil? - api_client = create_api_client() + if !$account_id.nil? + api_client = create_api_client() diagnostics_api = DocuSign_eSign::DiagnosticsApi.new(api_client) diagnostics_settings_info = diagnostics_api.get_request_log_settings - end + end - expect(diagnostics_settings_info).not_to be_nil - expect(diagnostics_settings_info).to be_a(DocuSign_eSign::DiagnosticsSettingsInformation) - end - end - end + expect(diagnostics_settings_info).not_to be_nil + expect(diagnostics_settings_info).to be_a(DocuSign_eSign::DiagnosticsSettingsInformation) + end + end + end describe '.list' do context 'list envelopes' do - it 'successfully list envelope' do - recipients = nil - envelope_ids = "" - count1 = 0 - count2 = 0 - - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - options = DocuSign_eSign::ListStatusChangesOptions.new - options.count = "10" - options.from_date = (Date.today-30).strftime("%Y-%m-%d") - - envelopes_information = envelopes_api.list_status_changes($account_id, options) - expect(envelopes_information).to be_truthy - if !envelopes_information.nil? - expect(envelopes_information.envelopes.length).to be > 0 - count1 = envelopes_information.envelopes.length - envelope_ids = envelopes_information.envelopes.map { |f| f.envelope_id }.join ',' - end - - options = DocuSign_eSign::ListStatusChangesOptions.new - options.envelope_ids = envelope_ids - - envelopes_information = envelopes_api.list_status_changes($account_id, options) - end - - expect(envelopes_information).to be_truthy - if !envelopes_information.nil? - expect(envelopes_information.envelopes.length).to be > 0 - count2 = envelopes_information.envelopes.length - expect(count1 == count2) - end - end - end + it 'successfully list envelope' do + recipients = nil + envelope_ids = "" + count1 = 0 + count2 = 0 + + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + options = DocuSign_eSign::ListStatusChangesOptions.new + options.count = "10" + options.from_date = (Date.today - 30).strftime("%Y-%m-%d") + + envelopes_information = envelopes_api.list_status_changes($account_id, options) + expect(envelopes_information).to be_truthy + if !envelopes_information.nil? + expect(envelopes_information.envelopes.length).to be > 0 + count1 = envelopes_information.envelopes.length + envelope_ids = envelopes_information.envelopes.map { |f| f.envelope_id }.join ',' + end + + options = DocuSign_eSign::ListStatusChangesOptions.new + options.envelope_ids = envelope_ids + + envelopes_information = envelopes_api.list_status_changes($account_id, options) + end + + expect(envelopes_information).to be_truthy + if !envelopes_information.nil? + expect(envelopes_information.envelopes.length).to be > 0 + count2 = envelopes_information.envelopes.length + expect(count1 == count2) + end + end + end context 'list recipients' do - it 'successfully list envelope recipients' do - recipients = nil + it 'successfully list envelope recipients' do + recipients = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - options = DocuSign_eSign::ListRecipientsOptions.new + options = DocuSign_eSign::ListRecipientsOptions.new - recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) - end + recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) + end - expect(recipients).to be_truthy - if !recipients.nil? - expect(recipients.recipient_count.to_i).to be > 0 - end - end - end + expect(recipients).to be_truthy + if !recipients.nil? + expect(recipients.recipient_count.to_i).to be > 0 + end + end + end context 'list status changes' do - it 'successfully lists envelope status changes' do - envelopes_information = nil - - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - - options = DocuSign_eSign::ListStatusChangesOptions.new - options.from_date = Time.now.strftime("%Y-%m-%d") - - envelopes_information = envelopes_api.list_status_changes($account_id, options) - end - - expect(envelopes_information).to be_truthy - if !envelopes_information.nil? - expect(envelopes_information.total_set_size.to_i).to be > 0 - end - end - end + it 'successfully lists envelope status changes' do + envelopes_information = nil - context 'list documents and download' do - it 'successfully lists and download envelope documents' do - envelope_documents_result = nil + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + + options = DocuSign_eSign::ListStatusChangesOptions.new + options.from_date = Time.now.strftime("%Y-%m-%d") - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + envelopes_information = envelopes_api.list_status_changes($account_id, options) + end + + expect(envelopes_information).to be_truthy + if !envelopes_information.nil? + expect(envelopes_information.total_set_size.to_i).to be > 0 + end + end + end + + context 'list documents and download' do + it 'successfully lists and download envelope documents' do + envelope_documents_result = nil - envelope_documents_result = envelopes_api.list_documents($account_id, $envelope_id) - end + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - expect(envelope_documents_result).to be_truthy - if !envelope_documents_result.nil? - expect(envelope_documents_result.envelope_id).to eq($envelope_id) - expect(envelope_documents_result.envelope_documents).to be_truthy + envelope_documents_result = envelopes_api.list_documents($account_id, $envelope_id) + end - if !envelope_documents_result.envelope_documents.nil? - expect(envelope_documents_result.envelope_documents.count).to be > 0 + expect(envelope_documents_result).to be_truthy + if !envelope_documents_result.nil? + expect(envelope_documents_result.envelope_id).to eq($envelope_id) + expect(envelope_documents_result.envelope_documents).to be_truthy + if !envelope_documents_result.envelope_documents.nil? + expect(envelope_documents_result.envelope_documents.count).to be > 0 - if envelope_documents_result.envelope_documents.count > 0 - options = DocuSign_eSign::GetDocumentOptions.new + if envelope_documents_result.envelope_documents.count > 0 + options = DocuSign_eSign::GetDocumentOptions.new - envelope_documents_result.envelope_documents.each do |envelope_document| - document = envelopes_api.get_document($account_id, envelope_document.document_id, $envelope_id, options) - expect(document).to be_truthy - end - end - end - end - end + envelope_documents_result.envelope_documents.each do |envelope_document| + document = envelopes_api.get_document($account_id, envelope_document.document_id, $envelope_id, options) + expect(document).to be_truthy + end + end + end + end + end end context 'list tabs' do - it 'successfully lists envelope tabs' do - envelope_summary = nil + it 'successfully lists envelope tabs' do + envelope_summary = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - options = DocuSign_eSign::GetEnvelopeOptions.new + options = DocuSign_eSign::GetEnvelopeOptions.new - envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) + envelope_summary = envelopes_api.get_envelope($account_id, $envelope_id, options) - options = DocuSign_eSign::ListRecipientsOptions.new + options = DocuSign_eSign::ListRecipientsOptions.new - recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) + recipients = envelopes_api.list_recipients($account_id, $envelope_id, options) - tabs = envelopes_api.list_tabs($account_id, $envelope_id, recipients.signers[0].recipient_id) + tabs = envelopes_api.list_tabs($account_id, $envelope_id, recipients.signers[0].recipient_id) - sign_here_tabs = tabs.sign_here_tabs + sign_here_tabs = tabs.sign_here_tabs - expect(sign_here_tabs).to be_truthy - end - end + expect(sign_here_tabs).to be_truthy + end + end end context 'list users' do - it 'successfully list account users' do - user_info_list = nil + it 'successfully list account users' do + user_info_list = nil - if !$account_id.nil? - api_client = create_api_client() + if !$account_id.nil? + api_client = create_api_client() users_api = DocuSign_eSign::UsersApi.new(api_client) - options = DocuSign_eSign::ListOptions.new + options = DocuSign_eSign::ListOptions.new user_info_list = users_api.list($account_id, options) - end + end - expect(user_info_list).to be_truthy - if !user_info_list.nil? - expect(user_info_list.users).not_to be_empty - end - end + expect(user_info_list).to be_truthy + if !user_info_list.nil? + expect(user_info_list.users).not_to be_empty + end + end end context 'list audit events' do - it 'successfully list envelope audit events' do - audit_events_response = nil + it 'successfully list envelope audit events' do + audit_events_response = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) audit_events_response = envelopes_api.list_audit_events($account_id, $envelope_id) - end + end - expect(audit_events_response).to be_truthy - if !audit_events_response.nil? - expect(audit_events_response.audit_events).not_to be_empty - end - end + expect(audit_events_response).to be_truthy + if !audit_events_response.nil? + expect(audit_events_response.audit_events).not_to be_empty + end + end end context 'list envelope statuses' do - it 'returns envelope statuses' do + it 'returns envelope statuses' do status = nil - if !$envelope_id.nil? + if !$envelope_id.nil? envelopes_api = DocuSign_eSign::EnvelopesApi.new(create_api_client) - envelope = envelopes_api.get_envelope($account_id, $envelope_id) + envelope = envelopes_api.get_envelope($account_id, $envelope_id) list_status_options = DocuSign_eSign::ListStatusOptions.new - list_status_options.envelope_ids = $envelope_id - list_status_options.transaction_ids = envelope.transaction_id + list_status_options.envelope_ids = $envelope_id + list_status_options.transaction_ids = envelope.transaction_id - envelope_ids_request = DocuSign_eSign::EnvelopeIdsRequest.new - envelope_ids_request.envelope_ids = Array($envelope_id) - envelope_ids_request.transaction_ids = Array(envelope.transaction_id) + envelope_ids_request = DocuSign_eSign::EnvelopeIdsRequest.new + envelope_ids_request.envelope_ids = Array($envelope_id) + envelope_ids_request.transaction_ids = Array(envelope.transaction_id) - status = envelopes_api.list_status($account_id, envelope_ids_request, list_status_options) - end + status = envelopes_api.list_status($account_id, envelope_ids_request, list_status_options) + end - expect(status).not_to be_nil - expect(status).to be_a(DocuSign_eSign::EnvelopesInformation) - expect(status.envelopes).not_to be_nil - expect(status.envelopes.size > 0).to be_truthy - end + expect(status).not_to be_nil + expect(status).to be_a(DocuSign_eSign::EnvelopesInformation) + expect(status.envelopes).not_to be_nil + expect(status.envelopes.size > 0).to be_truthy + end end - context 'list custom fields' do - it 'successfully list custom fields' do + context 'list custom fields' do + it 'successfully list custom fields' do custom_fields = nil - if !$envelope_id.nil? - api_client = create_api_client() - envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) + if !$envelope_id.nil? + api_client = create_api_client() + envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client) - custom_fields = envelopes_api.list_custom_fields($account_id, $envelope_id) - end + custom_fields = envelopes_api.list_custom_fields($account_id, $envelope_id) + end - expect(custom_fields).to be_truthy - expect(custom_fields).to be_a(DocuSign_eSign::CustomFieldsEnvelope) - end - end - end - end + expect(custom_fields).to be_truthy + expect(custom_fields).to be_a(DocuSign_eSign::CustomFieldsEnvelope) + end + end + end + end end From 80e336cd6ce7d2507172dfcbaee6053d64a6d629 Mon Sep 17 00:00:00 2001 From: an-tk Date: Wed, 27 Oct 2021 13:20:54 +0300 Subject: [PATCH 3/9] Removed commented out code --- tests/spec/unit_tests_using_jwt_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index 2481c93c..ac6afd81 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -38,7 +38,6 @@ def login end rescue => e puts "Error during processing: #{$!}" - # puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end return nil @@ -395,18 +394,6 @@ def create_envelope_on_document(status, is_embedded_signing) expect(envelope_form_data.form_data).to be_truthy if !envelope_form_data.form_data.nil? expect(envelope_form_data.form_data).to be_truthy - # expect(envelope_form_data.form_data.length).to be > 0 - # if envelope_form_data.form_data.length > 0 - # expect(envelope_form_data.form_data[0].name).to be_truthy - # expect(envelope_form_data.prefill_form_data).to be_truthy - # if !envelope_form_data.prefill_form_data.nil? - # expect(envelope_form_data.prefill_form_data.form_data).to be_truthy - # expect(envelope_form_data.prefill_form_data.form_data.length).to be > 0 - # if envelope_form_data.prefill_form_data.form_data.length > 0 - # expect(envelope_form_data.prefill_form_data.form_data[0].name).to be_truthy - # end - # end - # end end end end From 06f8db574dd9547e94b8791c609e7286299a1ff0 Mon Sep 17 00:00:00 2001 From: an-tk Date: Thu, 11 Nov 2021 16:24:38 +0200 Subject: [PATCH 4/9] Updated README and tests comments --- .travis.yml | 2 +- README.md | 33 ++++++++++++++++++------- tests/Gemfile | 1 + tests/spec/unit_tests_using_jwt_spec.rb | 20 +++++++-------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09d07ec0..fe5b5b4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ branches: language: ruby #before_install: openssl aes-256-cbc -K $encrypted_7aa52200b8fc_key -iv $encrypted_7aa52200b8fc_iv -in tests/keys/docusign_private_key.txt.enc -out tests/keys/docusign_private_key.txt -d # command to install dependencies -install: cd tests/spec && bundle install +install: cd tests && bundle install # command to run tests script: bundle exec rspec unit_tests_using_jwt_spec.rb --format documentation diff --git a/README.md b/README.md index 9391dda3..0948b0f6 100644 --- a/README.md +++ b/README.md @@ -39,30 +39,45 @@ For details regarding which type of OAuth grant will work best for your DocuSign For security purposes, DocuSign recommends using the [Authorization Code Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) flow. ## Running tests: +Pre-conditions: +1. Make sure ruby is installed or install it fallowing the [instructions](https://www.ruby-lang.org/en/documentation/installation/) +2. Login with your DocuSign account on https://appdemo.docusign.com. +3. Open Apps and Keys section in Settings and press Add App and Integration Key button. +4. Enter App name, add secret key, generate RSA key and press Save button, add `https://developers.docusign.com/` to Redirect URIs. +5. Create new template on https://appdemo.docusign.com/templates page and save its ID. + +After complete all previous steps for run on the Windows 10 need to do the following: +1. Download curl from https://curl.se/windows/ +2. Inside archive find "bin" directory +3. Rename libcurl-x64.def to libcurl.def +4. Rename libcurl-x64.dll to libcurl.dll +5. Copy all files from "bin" directory to C:\Ruby30-x64\bin To run tests, you need: 1. Create a .env file at the `tests` dir (or rename an existing .env.example file) 2. Enter your data from the developer account -* SECRET=< The secret key of your application > \ +* `SECRET` \ settings => Apps and Keys => Apps and Integration Keys your app "ACTIONS" => Edit => Authentication => Secret Keys -* INTEGRATOR_KEY_JWT=< your Integration Key > \ +* `INTEGRATOR_KEY_JWT` \ settings => Apps and Keys => Integration Key of your app -* TEMPLATE_ID=< your template id > \ - templates => in MyTemplates list click by choosen template => template id -* USER_ID=< your User ID > \ +* `TEMPLATE_ID` \ + templates => in MyTemplates list click by chosen template or _create new one_ => template id +* `USER_ID` \ settings => Apps and Keys => User ID 3. Copy private key to `tests/docs/private.pem ` \ Settings => "Apps and Keys" in Apps and Integration Keys choose your application name => "ACTIONS" Edit => Service Integration => + GENERATE RSA -4. Install dependencies bundle install +4. Run tests: \ + `cd tests && bundle install`\ + `bundle exec rspec spec/unit_tests_using_jwt_spec.rb --format documentation` + +### Important note: +First time you ask for a JWT access token you might need to uncomment lines 19-21 in `tests/spec/unit_tests_using_jwt_spec.rb:19` and grant access to the API -5. Run tests: \ - `cd tests`\ - `rspec` ## Support Log issues against this client through GitHub. We also have an [active developer community on Stack Overflow](https://stackoverflow.com/questions/tagged/docusignapi). diff --git a/tests/Gemfile b/tests/Gemfile index 9a6662d5..3071d19f 100644 --- a/tests/Gemfile +++ b/tests/Gemfile @@ -2,4 +2,5 @@ source 'https://rubygems.org' gem 'rspec' gem 'dotenv' +gem 'launchy' gem 'docusign_esign', path: '../' diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index ac6afd81..9e2d0c24 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -2,6 +2,7 @@ require 'docusign_esign' require 'base64' require 'uri' +require 'launchy' describe 'DocuSign Ruby Client Tests' do def login @@ -12,10 +13,13 @@ def login $api_client = DocuSign_eSign::ApiClient.new(configuration) $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) - # $api_client.get_authorization_uri($integrator_key,%w[signature impersonation],$return_url,'code') - # $api_client.request_jwt_application_token($integrator_key,File.read($private_key_filename),$expires_in_seconds,%w[signature impersonation] ) - # code = 'code_here' - # $api_client.generate_access_token($integrator_key,$secret,code) + # IMPORTANT NOTE: + # the first time you ask for a JWT access token, you should grant access by making the following call + # visit DocuSign OAuth authorization url in the browser, login, grant access and restart the tests + # url = $api_client.get_authorization_uri($integrator_key,%w[signature organization_read impersonation],$return_url,'code') + # Launchy.open(url) + # abort "Please restart the tests" + # END OF NOTE end token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds) @@ -348,19 +352,15 @@ def create_envelope_on_document(status, is_embedded_signing) if !$envelope_id.nil? api_client = create_api_client() templates_api = DocuSign_eSign::TemplatesApi.new(api_client) - - options = DocuSign_eSign::GetEnvelopeOptions.new - $template_id = ENV["TEMPLATE_ID"] - options = DocuSign_eSign::GetOptions.new options.include = "tabs" - template_summary = templates_api.get($account_id, $template_id, options) + template_summary = templates_api.get($account_id, ENV["TEMPLATE_ID"], options) end expect(template_summary).to be_truthy if !template_summary.nil? - expect(template_summary.template_id).to eq($template_id) + expect(template_summary.template_id).to eq(ENV["TEMPLATE_ID"]) end end end From 2824ec74c60326cf3fc6fa4eabb4fa1208df837a Mon Sep 17 00:00:00 2001 From: Naveen Gopala Date: Wed, 15 Dec 2021 13:23:38 -0800 Subject: [PATCH 5/9] Fixed the file path issues --- tests/spec/unit_tests_using_jwt_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index 9e2d0c24..ed065d0c 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -22,6 +22,11 @@ def login # END OF NOTE end + decode_base64_content = Base64.decode64(ENV["PRIVATE_KEY"]) + File.open($private_key_filename, "wb") do |f| + f.write(decode_base64_content) + end + token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds) user_info = $api_client.get_user_info(token_obj.access_token) @@ -59,7 +64,7 @@ def create_envelope_on_document(status, is_embedded_signing) if (!$account_id.nil?) # STEP 2: Create envelope definition # Add a document to the envelope - document_path = "docs/Test.pdf" + document_path = "../docs/Test.pdf" document_name = "Test.docx" document = DocuSign_eSign::Document.new document.document_base64 = Base64.encode64(File.open(document_path).read) @@ -115,7 +120,7 @@ def create_envelope_on_document(status, is_embedded_signing) $expires_in_seconds = 3600 #1 hour $auth_server = 'account-d.docusign.com' - $private_key_filename = 'docs/private.pem' + $private_key_filename = '../docs/private.pem' $recipient_name = "Ruby SDK" From 6ddc0cb3f02232286293f48542ff5c9ba5bbc908 Mon Sep 17 00:00:00 2001 From: Nima Date: Tue, 11 Jan 2022 10:39:36 -0800 Subject: [PATCH 6/9] Fix travis file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fe5b5b4e..09d07ec0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ branches: language: ruby #before_install: openssl aes-256-cbc -K $encrypted_7aa52200b8fc_key -iv $encrypted_7aa52200b8fc_iv -in tests/keys/docusign_private_key.txt.enc -out tests/keys/docusign_private_key.txt -d # command to install dependencies -install: cd tests && bundle install +install: cd tests/spec && bundle install # command to run tests script: bundle exec rspec unit_tests_using_jwt_spec.rb --format documentation From db0f22f0c454aaf0673c391a5e2012ab0686f516 Mon Sep 17 00:00:00 2001 From: Nima Date: Tue, 11 Jan 2022 12:12:24 -0800 Subject: [PATCH 7/9] Fix the dependencies --- docusign_esign.gemspec | 2 ++ tests/Gemfile | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docusign_esign.gemspec b/docusign_esign.gemspec index f08f128b..7482004f 100644 --- a/docusign_esign.gemspec +++ b/docusign_esign.gemspec @@ -40,6 +40,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2' s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16' s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.11' + s.add_development_dependency 'dotenv', '~> 2.1', '>= 2.1.1' + s.add_development_dependency 'launchy', '~> 2.5' s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? } s.test_files = `find spec/*`.split("\n") diff --git a/tests/Gemfile b/tests/Gemfile index 3071d19f..0e06e1ee 100644 --- a/tests/Gemfile +++ b/tests/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' gem 'rspec' -gem 'dotenv' -gem 'launchy' + gem 'docusign_esign', path: '../' From 5efc163804fa0dd42d0d52af6166b524a8dc2081 Mon Sep 17 00:00:00 2001 From: Nima Date: Tue, 11 Jan 2022 13:53:27 -0800 Subject: [PATCH 8/9] Debug broken Travis build --- tests/spec/unit_tests_using_jwt_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index ed065d0c..6c3fff7c 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -7,10 +7,12 @@ describe 'DocuSign Ruby Client Tests' do def login begin + puts "1" if $api_client.nil? configuration = DocuSign_eSign::Configuration.new configuration.host = $host + puts "2" $api_client = DocuSign_eSign::ApiClient.new(configuration) $api_client.set_oauth_base_path(DocuSign_eSign::OAuth::DEMO_OAUTH_BASE_PATH) # IMPORTANT NOTE: @@ -22,15 +24,21 @@ def login # END OF NOTE end + puts "3" decode_base64_content = Base64.decode64(ENV["PRIVATE_KEY"]) + puts $decode_base64_content + File.open($private_key_filename, "wb") do |f| f.write(decode_base64_content) end token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds) + puts "4" + puts $token_obj user_info = $api_client.get_user_info(token_obj.access_token) - + puts "4" + if !user_info.nil? user_info.accounts.each do |account| if account.is_default == "true" From d5615d5388be4c240262f8d7ee6f9a59e617fb0a Mon Sep 17 00:00:00 2001 From: Nima Date: Tue, 11 Jan 2022 14:05:18 -0800 Subject: [PATCH 9/9] Add more debugging information --- tests/spec/unit_tests_using_jwt_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/spec/unit_tests_using_jwt_spec.rb b/tests/spec/unit_tests_using_jwt_spec.rb index 6c3fff7c..78b68a27 100644 --- a/tests/spec/unit_tests_using_jwt_spec.rb +++ b/tests/spec/unit_tests_using_jwt_spec.rb @@ -25,20 +25,25 @@ def login end puts "3" + encodedprokey = ENV["PRIVATE_KEY"] + puts $encodedprokey + decode_base64_content = Base64.decode64(ENV["PRIVATE_KEY"]) puts $decode_base64_content + puts "3.1" File.open($private_key_filename, "wb") do |f| f.write(decode_base64_content) end + puts "3.2" token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds) puts "4" puts $token_obj user_info = $api_client.get_user_info(token_obj.access_token) - puts "4" - + puts "5" + if !user_info.nil? user_info.accounts.each do |account| if account.is_default == "true"