From 15d21125be0a2918e88656a57d79d408f82b32bc Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 1 Sep 2022 01:34:37 +0200 Subject: [PATCH 1/3] feat: Add and to Sign Request --- src/commands/file-requests/update.js | 2 +- src/commands/sign-requests/create.js | 18 +++++++++++++++++- test/commands/file-requests.test.js | 10 +++++----- test/commands/sign-requests.test.js | 10 ++++++++-- .../sign-requests/get_sign_request_by_id.json | 6 +++++- .../sign-requests/get_sign_requests.json | 6 +++++- .../sign-requests/post_sign_requests.json | 6 +++++- .../post_sign_requests_id_cancel.json | 6 +++++- 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/commands/file-requests/update.js b/src/commands/file-requests/update.js index 908f89f5..d93827a9 100644 --- a/src/commands/file-requests/update.js +++ b/src/commands/file-requests/update.js @@ -78,7 +78,7 @@ FileRequestsUpdateCommand.flags = { description: 'New title of file request', }), etag: flags.string({ - description: `Pass in the item's last observed etag value into this header and the endpoint will fail with a 412 Precondition Failed if it has changed since.`, + description: 'Pass in the item\'s last observed etag value into this header and the endpoint will fail with a 412 Precondition Failed if it has changed since.', }), }; diff --git a/src/commands/sign-requests/create.js b/src/commands/sign-requests/create.js index 9c07c666..459bbadb 100644 --- a/src/commands/sign-requests/create.js +++ b/src/commands/sign-requests/create.js @@ -47,7 +47,7 @@ SignRequestsCreateCommand.flags = { signer: flags.string({ required: true, description: - 'A signer for the sign request. 35 is the max number of signers permitted. Can be added multiple times. Allowed properties: email,role,is_in_person,order,embed_url_external_user_id', + 'A signer for the sign request. 35 is the max number of signers permitted. Can be added multiple times. Allowed properties: email,role,is_in_person,order,embed_url_external_user_id,redirect_url,declined_redirect_url', multiple: true, parse(input) { const signer = { @@ -93,6 +93,14 @@ SignRequestsCreateCommand.flags = { signer.embed_url_external_user_id = value; break; + case 'redirect_url': + signer.redirect_url = value; + break; + + case 'declined_redirect_url': + signer.declined_redirect_url = value; + break; + default: throw new BoxCLIError(`Unknown property for signer: ${key}`); } @@ -192,6 +200,14 @@ SignRequestsCreateCommand.flags = { description: 'This can be used to reference an ID in an external system that the sign request is related to.', }), + 'redirect-url': flags.string({ + description: + 'The URL that a signer will be redirected to after signing a document. Defining this URL overrides the default redirect URL for all signers. If no declined redirect URL is specified, this URL will be used for decline actions as well.', + }), + 'declined-redirect-url': flags.string({ + description: + 'The URL that a signer will be redirected to after declining to sign a document. Defining this URL overrides the default redirect URL for all signers.', + }), }; module.exports = SignRequestsCreateCommand; diff --git a/test/commands/file-requests.test.js b/test/commands/file-requests.test.js index a387c769..7438993e 100644 --- a/test/commands/file-requests.test.js +++ b/test/commands/file-requests.test.js @@ -71,20 +71,20 @@ describe('File Requests', () => { let status = 'active'; let addParams = { - title: title, - description: description, + title, + description, expires_at: expiresAt, is_description_required: true, is_email_required: true, - status: status, + status, }; let addFlags = [ `--title=${title}`, `--description=${description}`, `--expires-at=${expiresAt}`, - `--description-required`, - `--email-required`, + '--description-required', + '--email-required', `--status=${status}`, ]; diff --git a/test/commands/sign-requests.test.js b/test/commands/sign-requests.test.js index f991f68f..e907745c 100644 --- a/test/commands/sign-requests.test.js +++ b/test/commands/sign-requests.test.js @@ -48,12 +48,16 @@ describe('Sign requests', () => { describe('sign-requests:create', () => { let signerEmail = 'bob@example.com', + signerRedirectUrl = 'https://box.com/redirect_url_signer_1', + signerDeclinedRedirectUrl = 'https://box.com/declined_redirect_url_signer_1', fileId = '1234', parentFolderId = '2345', documentTag1Id = '3456', documentTag1Value = 'hello', documentTag2Id = '4567', - fixture = getFixture('sign-requests/post_sign_requests'); + fixture = getFixture('sign-requests/post_sign_requests'), + redirectUrl = 'https://box.com/redirect_url', + declinedRedirectUrl = 'https://box.com/declined_redirect_url'; test .nock(TEST_API_ROOT, api => api @@ -91,11 +95,13 @@ describe('Sign requests', () => { .stdout() .command([ 'sign-requests:create', - `--signer=email=${signerEmail},role=approver,is_in_person=1`, + `--signer=email=${signerEmail},role=approver,is_in_person=1,redirect_url=${signerRedirectUrl},declined_redirect_url=${signerDeclinedRedirectUrl}`, `--source-files=${fileId}`, `--parent-folder=${parentFolderId}`, `--prefill-tag=id=${documentTag1Id},text=${documentTag1Value}`, `--prefill-tag=id=${documentTag2Id},checkbox=0`, + `--redirect-url=${redirectUrl}`, + `--declined-redirect-url=${declinedRedirectUrl}`, '--json', '--token=test', ]) diff --git a/test/fixtures/sign-requests/get_sign_request_by_id.json b/test/fixtures/sign-requests/get_sign_request_by_id.json index b7e93d1a..92028e71 100644 --- a/test/fixtures/sign-requests/get_sign_request_by_id.json +++ b/test/fixtures/sign-requests/get_sign_request_by_id.json @@ -25,6 +25,8 @@ } ], "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "sign_files": { "files": [ { @@ -65,7 +67,9 @@ "page_index": 4 } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "signing_log": { diff --git a/test/fixtures/sign-requests/get_sign_requests.json b/test/fixtures/sign-requests/get_sign_requests.json index b7e93d1a..92028e71 100644 --- a/test/fixtures/sign-requests/get_sign_requests.json +++ b/test/fixtures/sign-requests/get_sign_requests.json @@ -25,6 +25,8 @@ } ], "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "sign_files": { "files": [ { @@ -65,7 +67,9 @@ "page_index": 4 } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "signing_log": { diff --git a/test/fixtures/sign-requests/post_sign_requests.json b/test/fixtures/sign-requests/post_sign_requests.json index b7e93d1a..92028e71 100644 --- a/test/fixtures/sign-requests/post_sign_requests.json +++ b/test/fixtures/sign-requests/post_sign_requests.json @@ -25,6 +25,8 @@ } ], "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "sign_files": { "files": [ { @@ -65,7 +67,9 @@ "page_index": 4 } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "signing_log": { diff --git a/test/fixtures/sign-requests/post_sign_requests_id_cancel.json b/test/fixtures/sign-requests/post_sign_requests_id_cancel.json index b7e93d1a..92028e71 100644 --- a/test/fixtures/sign-requests/post_sign_requests_id_cancel.json +++ b/test/fixtures/sign-requests/post_sign_requests_id_cancel.json @@ -25,6 +25,8 @@ } ], "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "sign_files": { "files": [ { @@ -65,7 +67,9 @@ "page_index": 4 } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "signing_log": { From 2dc9e67a24df1a5cd1c23b75ad1873d7a6d15c41 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 1 Sep 2022 01:39:58 +0200 Subject: [PATCH 2/3] Update test --- test/commands/sign-requests.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/commands/sign-requests.test.js b/test/commands/sign-requests.test.js index e907745c..4806e8b8 100644 --- a/test/commands/sign-requests.test.js +++ b/test/commands/sign-requests.test.js @@ -67,6 +67,8 @@ describe('Sign requests', () => { role: 'approver', email: signerEmail, is_in_person: true, + redirect_url: signerRedirectUrl, + declined_redirect_url: signerDeclinedRedirectUrl }, ], source_files: [ @@ -89,6 +91,8 @@ describe('Sign requests', () => { checkbox_value: false, }, ], + redirect_url: redirectUrl, + declined_redirect_url: declinedRedirectUrl }) .reply(200, fixture) ) From 8a7d740a73246df3eb71562ec14d4809a0f97789 Mon Sep 17 00:00:00 2001 From: Kamil Berdychowski Date: Thu, 1 Sep 2022 16:38:46 +0200 Subject: [PATCH 3/3] chore: allow kebab and snake case in sign --- src/commands/sign-requests/create.js | 8 +++- test/commands/sign-requests.test.js | 56 +++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/commands/sign-requests/create.js b/src/commands/sign-requests/create.js index 459bbadb..6c219c73 100644 --- a/src/commands/sign-requests/create.js +++ b/src/commands/sign-requests/create.js @@ -47,7 +47,9 @@ SignRequestsCreateCommand.flags = { signer: flags.string({ required: true, description: - 'A signer for the sign request. 35 is the max number of signers permitted. Can be added multiple times. Allowed properties: email,role,is_in_person,order,embed_url_external_user_id,redirect_url,declined_redirect_url', + 'A signer for the sign request. 35 is the max number of signers permitted. Can be added multiple times. ' + + 'Allowed (recommended) properties: email,role,is-in-person,order,embed-url-external-user-id,redirect-url,declined-redirect-url ' + + 'but snake case is also supported for: is_in_person,order,embed_url_external_user_id,redirect_url,declined_redirect_url', multiple: true, parse(input) { const signer = { @@ -76,6 +78,7 @@ SignRequestsCreateCommand.flags = { signer.role = value; break; + case 'is-in-person': case 'is_in_person': if (value !== '0' && value !== '1') { throw new BoxCLIError( @@ -89,14 +92,17 @@ SignRequestsCreateCommand.flags = { signer.order = value; break; + case 'embed-url-external-user-id': case 'embed_url_external_user_id': signer.embed_url_external_user_id = value; break; case 'redirect_url': + case 'redirect-url': signer.redirect_url = value; break; + case 'declined-redirect-url': case 'declined_redirect_url': signer.declined_redirect_url = value; break; diff --git a/test/commands/sign-requests.test.js b/test/commands/sign-requests.test.js index 4806e8b8..37c89bfe 100644 --- a/test/commands/sign-requests.test.js +++ b/test/commands/sign-requests.test.js @@ -109,7 +109,61 @@ describe('Sign requests', () => { '--json', '--token=test', ]) - .it('should create a sign request', ctx => { + .it('should create a sign request with snake case', ctx => { + assert.equal(ctx.stdout, fixture); + }); + + test + .nock(TEST_API_ROOT, api => api + .post('/2.0/sign_requests', { + signers: [ + { + role: 'approver', + email: signerEmail, + is_in_person: true, + redirect_url: signerRedirectUrl, + declined_redirect_url: signerDeclinedRedirectUrl + }, + ], + source_files: [ + { + type: 'file', + id: fileId, + }, + ], + parent_folder: { + type: 'folder', + id: parentFolderId, + }, + prefill_tags: [ + { + document_tag_id: documentTag1Id, + text_value: documentTag1Value, + }, + { + document_tag_id: documentTag2Id, + checkbox_value: false, + }, + ], + redirect_url: redirectUrl, + declined_redirect_url: declinedRedirectUrl + }) + .reply(200, fixture) + ) + .stdout() + .command([ + 'sign-requests:create', + `--signer=email=${signerEmail},role=approver,is-in-person=1,redirect-url=${signerRedirectUrl},declined-redirect-url=${signerDeclinedRedirectUrl}`, + `--source-files=${fileId}`, + `--parent-folder=${parentFolderId}`, + `--prefill-tag=id=${documentTag1Id},text=${documentTag1Value}`, + `--prefill-tag=id=${documentTag2Id},checkbox=0`, + `--redirect-url=${redirectUrl}`, + `--declined-redirect-url=${declinedRedirectUrl}`, + '--json', + '--token=test', + ]) + .it('should create a sign request with kebab case', ctx => { assert.equal(ctx.stdout, fixture); }); });