Skip to content

Commit

Permalink
feat: Add redirect_url and declined_redirect_url to Sign Request (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 committed Jan 31, 2024
1 parent b603ee5 commit 38ee58d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 8 deletions.
24 changes: 23 additions & 1 deletion src/commands/sign-requests/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'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 = {
Expand Down Expand Up @@ -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(
Expand All @@ -89,10 +92,21 @@ 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;

default:
throw new BoxCLIError(`Unknown property for signer: ${key}`);
}
Expand Down Expand Up @@ -192,6 +206,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;
70 changes: 67 additions & 3 deletions test/commands/sign-requests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,6 +67,8 @@ describe('Sign requests', () => {
role: 'approver',
email: signerEmail,
is_in_person: true,
redirect_url: signerRedirectUrl,
declined_redirect_url: signerDeclinedRedirectUrl
},
],
source_files: [
Expand All @@ -85,21 +91,79 @@ describe('Sign requests', () => {
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`,
`--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', 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);
});
});
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/sign-requests/get_sign_request_by_id.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/sign-requests/get_sign_requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/sign-requests/post_sign_requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 38ee58d

Please sign in to comment.