@@ -4,9 +4,9 @@ const expect = chai.expect;
4
4
const should = chai . should ( ) ;
5
5
const helpers = require ( './testHelpers' ) ;
6
6
const { createTemplate, makeTemplate } = require ( '../lib/eSignature/examples/createTemplate' ) ;
7
- const { sendEnvelopeFromTemplate, makeEnvelope } = require ( '../lib/eSignature/examples/useTemplate' ) ;
8
- const { addDocToTemplate } = require ( '../lib/eSignature/examples/addDocToTemplate' )
9
- const { setTabValues } = require ( '../lib/eSignature/examples/setTabValues' )
7
+ const { sendEnvelopeFromTemplate, makeEnvelope : makeEnvelopeForUsingTemplate } = require ( '../lib/eSignature/examples/useTemplate' ) ;
8
+ const { addDocToTemplate, makeEnvelope : makeEnvelopeForAddingDoc , document1 : document1ForAddingDoc , makeRecipientViewRequest : makeRecipientViewRequestForAddingDoc } = require ( '../lib/eSignature/examples/addDocToTemplate' )
9
+ const { setTabValues, makeEnvelope : makeEnvelopeForSetTabValues } = require ( '../lib/eSignature/examples/setTabValues' )
10
10
const path = require ( 'path' ) ;
11
11
const { authenticate, areEqual } = require ( './testHelpers' ) ;
12
12
const { TEST_TEMPLATE_PDF_FILE , TEST_TEMPLATE_DOCX_FILE , TEMPLATE_NAME , BASE_PATH , signerClientId, returnUrl, pingUrl } = require ( './constants' )
@@ -16,23 +16,24 @@ let ACCESS_TOKEN;
16
16
let TEMPLATE_ID = "12345678-1234-1234-1234-123456789123" ;
17
17
18
18
describe ( 'templateTests' , function ( ) {
19
- // before(async function() {
20
- // this.timeout(0);
19
+ before ( async function ( ) {
20
+ this . timeout ( 0 ) ;
21
21
22
- // const { accountId, accessToken } = await authenticate();
22
+ const { accountId, accessToken } = await authenticate ( ) ;
23
23
24
- // ACCOUNT_ID = accountId;
25
- // ACCESS_TOKEN = accessToken;
26
- // });
24
+ ACCOUNT_ID = accountId ;
25
+ ACCESS_TOKEN = accessToken ;
26
+ } ) ;
27
27
28
28
it ( 'createTemplate' , async function ( ) {
29
29
this . timeout ( 0 ) ;
30
30
31
+ const newTemplateName = `${ TEMPLATE_NAME } _${ Date . now ( ) } ` ;
31
32
const args = {
32
33
accessToken : ACCESS_TOKEN ,
33
34
basePath : BASE_PATH ,
34
35
accountId : ACCOUNT_ID ,
35
- templateName : TEMPLATE_NAME ,
36
+ templateName : newTemplateName ,
36
37
docFile : TEST_TEMPLATE_PDF_FILE
37
38
} ;
38
39
@@ -42,6 +43,7 @@ describe ('templateTests', function() {
42
43
43
44
should . exist ( templateId ) ;
44
45
should . exist ( templateName ) ;
46
+ should . equal ( templateName , newTemplateName ) ;
45
47
should . equal ( createdNewTemplate , true ) ;
46
48
} ) ;
47
49
@@ -56,7 +58,7 @@ describe ('templateTests', function() {
56
58
const expected = {
57
59
emailSubject : "Please sign this document" ,
58
60
description : "Example template created via the API" ,
59
- name : "Example Signer and CC template" ,
61
+ name : TEMPLATE_NAME ,
60
62
shared : "false" ,
61
63
recipients : {
62
64
signers : [
@@ -276,10 +278,10 @@ describe ('templateTests', function() {
276
278
status : 'sent'
277
279
} ;
278
280
279
- const envelope = await makeEnvelope ( envelopeArgs ) ;
281
+ const envelope = await makeEnvelopeForUsingTemplate ( envelopeArgs ) ;
280
282
281
283
should . exist ( envelope ) ;
282
- // expect(areEqual(envelope, expected)).to.be.true;
284
+ expect ( areEqual ( envelope , expected ) ) . to . be . true ;
283
285
} ) ;
284
286
285
287
it ( 'addDocToTemplate' , async function ( ) {
@@ -310,6 +312,176 @@ describe ('templateTests', function() {
310
312
should . exist ( redirectUrl ) ;
311
313
} ) ;
312
314
315
+ it ( 'addDocToTemplate_makeEnvelope' , async function ( ) {
316
+ this . timeout ( 0 ) ;
317
+
318
+ const envelopeArgs = {
319
+ templateId : TEMPLATE_ID ,
320
+ signerEmail : settings . signerEmail ,
321
+ signerName : settings . signerName ,
322
+ signerClientId : signerClientId ,
323
+
324
+ ccName : 'Test Name' ,
325
+ item : 'Item' ,
326
+ quantity : '5' ,
327
+ dsReturnUrl : returnUrl ,
328
+ dsPingUrl : pingUrl
329
+ } ;
330
+
331
+ const expected = {
332
+ compositeTemplates : [
333
+ {
334
+ compositeTemplateId : "1" ,
335
+ serverTemplates : [
336
+ {
337
+ sequence : "1" ,
338
+ templateId : TEMPLATE_ID ,
339
+ } ,
340
+ ] ,
341
+ inlineTemplates : [
342
+ {
343
+ sequence : "2" ,
344
+ recipients : {
345
+ carbonCopies : [
346
+ {
347
+
348
+ name : 'Test Name' ,
349
+ roleName : "cc" ,
350
+ recipientId : "2" ,
351
+ }
352
+ ] ,
353
+ signers : [
354
+ {
355
+ email : settings . signerEmail ,
356
+ name : settings . signerName ,
357
+ roleName : "signer" ,
358
+ recipientId : "1" ,
359
+ clientUserId : signerClientId ,
360
+ }
361
+ ] ,
362
+ } ,
363
+ } ,
364
+ ] ,
365
+ } ,
366
+ {
367
+ compositeTemplateId : "2" ,
368
+ inlineTemplates : [
369
+ {
370
+ sequence : "1" ,
371
+ recipients : {
372
+ carbonCopies : [
373
+ {
374
+
375
+ name : 'Test Name' ,
376
+ roleName : "cc" ,
377
+ recipientId : "2" ,
378
+ }
379
+ ] ,
380
+ signers : [
381
+ {
382
+ email : settings . signerEmail ,
383
+ name : settings . signerName ,
384
+ roleName : "signer" ,
385
+ recipientId : "1" ,
386
+ tabs : {
387
+ signHereTabs : [
388
+ {
389
+ anchorString : "**signature_1**" ,
390
+ anchorYOffset : "10" ,
391
+ anchorUnits : "pixels" ,
392
+ anchorXOffset : "20" ,
393
+ }
394
+ ]
395
+ } ,
396
+ }
397
+ ] ,
398
+ } ,
399
+ } ,
400
+ ] ,
401
+ }
402
+ ] ,
403
+ status : 'sent'
404
+ } ;
405
+
406
+ const envelope = await makeEnvelopeForAddingDoc ( envelopeArgs ) ;
407
+
408
+ should . exist ( envelope ) ;
409
+ expect ( envelope ) . excludingEvery ( 'document' ) . to . deep . equal ( expected ) ;
410
+ } ) ;
411
+
412
+ it ( 'addDocToTemplate_document1' , async function ( ) {
413
+ this . timeout ( 0 ) ;
414
+
415
+ const item = 'Item' ;
416
+ const quantity = '5' ;
417
+ const envelopeArgs = {
418
+ templateId : TEMPLATE_ID ,
419
+ signerEmail : settings . signerEmail ,
420
+ signerName : settings . signerName ,
421
+
422
+ ccName : 'Test Name' ,
423
+ item : item ,
424
+ quantity : quantity ,
425
+ } ;
426
+
427
+ const expected = `
428
+ <!DOCTYPE html>
429
+ <html>
430
+ <head>
431
+ <meta charset="UTF-8">
432
+ </head>
433
+ <body style="font-family:sans-serif;margin-left:2em;">
434
+ <h1 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
435
+ color: darkblue;margin-bottom: 0;">World Wide Corp</h1>
436
+ <h2 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
437
+ margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;
438
+ color: darkblue;">Order Processing Division</h2>
439
+ <h4>Ordered by ${ settings . signerName } </h4>
440
+ <p style="margin-top:0em; margin-bottom:0em;">Email: ${ settings . signerEmail } </p>
441
+ <p style="margin-top:0em; margin-bottom:0em;">Copy to: ${ 'Test Name' } , ${ '[email protected] ' } </p>
442
+ <p style="margin-top:3em; margin-bottom:0em;">Item: <b>${ item } </b>, quantity: <b>${ quantity } </b> at market price.</p>
443
+ <p style="margin-top:3em;">
444
+ Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.
445
+ </p>
446
+ <!-- Note the anchor tag for the signature field is in white. -->
447
+ <h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3>
448
+ </body>
449
+ </html>
450
+ `
451
+
452
+ const document = await document1ForAddingDoc ( envelopeArgs ) ;
453
+
454
+ should . exist ( document ) ;
455
+ expect ( document ) . to . be . equal ( expected ) ;
456
+ } ) ;
457
+
458
+ it ( 'addDocToTemplate_makeRecipientView' , async function ( ) {
459
+ this . timeout ( 0 ) ;
460
+
461
+ const envelopeArgs = {
462
+ signerEmail : settings . signerEmail ,
463
+ signerName : settings . signerName ,
464
+ signerClientId : signerClientId ,
465
+ dsReturnUrl : returnUrl ,
466
+ dsPingUrl : pingUrl ,
467
+ } ;
468
+
469
+ const expected = {
470
+ returnUrl : returnUrl ,
471
+ authenticationMethod : 'none' ,
472
+ email : settings . signerEmail ,
473
+ userName : settings . signerName ,
474
+ clientUserId : signerClientId ,
475
+ pingFrequency : 600 ,
476
+ pingUrl : pingUrl
477
+ } ;
478
+
479
+ const viewRequest = await makeRecipientViewRequestForAddingDoc ( envelopeArgs ) ;
480
+
481
+ should . exist ( viewRequest ) ;
482
+ expect ( { ...viewRequest } ) . to . deep . equal ( { ...expected } ) ;
483
+ } ) ;
484
+
313
485
it ( 'setTabValues' , async function ( ) {
314
486
this . timeout ( 0 ) ;
315
487
@@ -332,4 +504,97 @@ describe ('templateTests', function() {
332
504
should . exist ( envelopeId ) ;
333
505
should . exist ( redirectUrl ) ;
334
506
} ) ;
507
+
508
+ it ( 'setTabValues_makeEnvelope' , async function ( ) {
509
+ this . timeout ( 0 ) ;
510
+
511
+ const envelopeArgs = {
512
+ signerEmail : settings . signerEmail ,
513
+ signerName : settings . signerName ,
514
+ signerClientId : signerClientId ,
515
+ dsReturnUrl : returnUrl ,
516
+ docFile : TEST_TEMPLATE_DOCX_FILE
517
+ } ;
518
+
519
+ const expected = {
520
+ emailSubject : "Please sign this salary document" ,
521
+ recipients : {
522
+ signers : [
523
+ {
524
+ email : settings . signerEmail ,
525
+ name : settings . signerName ,
526
+ clientUserId : signerClientId ,
527
+ recipientId : '1' ,
528
+ tabs : {
529
+ signHereTabs : [
530
+ {
531
+ anchorString : "/sn1/" ,
532
+ anchorUnits : "pixels" ,
533
+ anchorYOffset : "10" ,
534
+ anchorXOffset : "20" ,
535
+ }
536
+ ] ,
537
+ textTabs : [
538
+ {
539
+ anchorString : "/legal/" ,
540
+ anchorUnits : "pixels" ,
541
+ anchorYOffset : "-9" ,
542
+ anchorXOffset : "5" ,
543
+ font : "helvetica" ,
544
+ fontSize : "size11" ,
545
+ bold : "true" ,
546
+ value : settings . signerName ,
547
+ locked : "false" ,
548
+ tabId : "legal_name" ,
549
+ tabLabel : "Legal name" ,
550
+ } ,
551
+ {
552
+ anchorString : "/familiar/" ,
553
+ anchorUnits : "pixels" ,
554
+ anchorYOffset : "-9" ,
555
+ anchorXOffset : "5" ,
556
+ font : "helvetica" ,
557
+ fontSize : "size11" ,
558
+ bold : "true" ,
559
+ value : settings . signerName ,
560
+ locked : "false" ,
561
+ tabId : "familiar_name" ,
562
+ tabLabel : "Familiar name" ,
563
+ } ,
564
+ {
565
+ anchorString : "/salary/" ,
566
+ anchorUnits : "pixels" ,
567
+ anchorYOffset : "-9" ,
568
+ anchorXOffset : "5" ,
569
+ font : "helvetica" ,
570
+ fontSize : "size11" ,
571
+ bold : "true" ,
572
+ value : '$123,000' ,
573
+ locked : "true" ,
574
+ tabId : "salary" ,
575
+ tabLabel : "Salary" ,
576
+ }
577
+ ] ,
578
+ }
579
+ }
580
+ ]
581
+ } ,
582
+ status : "sent" ,
583
+ customFields : {
584
+ textCustomFields : [
585
+ {
586
+ name : "salary" ,
587
+ required : "false" ,
588
+ show : "true" ,
589
+ value : '123000' ,
590
+ }
591
+ ]
592
+ } ,
593
+ }
594
+
595
+ const envelope = await makeEnvelopeForSetTabValues ( envelopeArgs ) ;
596
+
597
+ should . exist ( envelope ) ;
598
+ expect ( envelope ) . excluding ( 'documents' ) . to . deep . equal ( expected ) ;
599
+ } ) ;
335
600
} ) ;
0 commit comments