|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const chai = require('chai'); |
| 4 | +const chaiExclude = require('chai-exclude'); |
| 5 | +const expect = chai.expect; |
| 6 | +const should = chai.should(); |
| 7 | + |
| 8 | +const settings = require('../config/appsettings.json'); |
| 9 | +const { createBrand } = require('../lib/eSignature/examples/createBrand'); |
| 10 | +const { |
| 11 | + applyBrandToEnvelope, |
| 12 | + makeEnvelope: makeEnvelopeForApplyingBrand, |
| 13 | + document1: makeHtmlDocForApplyingBrand, |
| 14 | + getBrands |
| 15 | +} = require('../lib/eSignature/examples/applyBrandToEnvelope'); |
| 16 | +const { createPermission } = require('../lib/eSignature/examples/createPermission'); |
| 17 | +const { TEST_TIMEOUT_MS, authenticate } = require('./testHelpers'); |
| 18 | + |
| 19 | +const { |
| 20 | + TEST_PDF_FILE, |
| 21 | + TEST_DOCX_FILE, |
| 22 | + BASE_PATH, |
| 23 | + BRAND_NAME, |
| 24 | + DEFAULT_BRAND_LANGUAGE, |
| 25 | + PERMISSION_PROFILE_NAME, |
| 26 | +} = require('./constants') |
| 27 | + |
| 28 | +chai.use(chaiExclude); |
| 29 | + |
| 30 | +let ACCOUNT_ID; |
| 31 | +let ACCESS_TOKEN; |
| 32 | +let BRAND_ID; |
| 33 | + |
| 34 | +describe ('AccountsApi tests:', function() { |
| 35 | + before(async function() { |
| 36 | + this.timeout(TEST_TIMEOUT_MS); |
| 37 | + |
| 38 | + const { accountId, accessToken } = await authenticate(); |
| 39 | + |
| 40 | + should.exist(accountId); |
| 41 | + should.exist(accessToken); |
| 42 | + |
| 43 | + ACCOUNT_ID = accountId; |
| 44 | + ACCESS_TOKEN = accessToken; |
| 45 | + }); |
| 46 | + |
| 47 | + it('createBrand method should create a brand if correct data is provided', async function() { |
| 48 | + this.timeout(TEST_TIMEOUT_MS); |
| 49 | + |
| 50 | + const args = { |
| 51 | + accessToken: ACCESS_TOKEN, |
| 52 | + basePath: BASE_PATH, |
| 53 | + accountId: ACCOUNT_ID, |
| 54 | + brandName: `${BRAND_NAME}_${Date.now()}`, |
| 55 | + defaultBrandLanguage: DEFAULT_BRAND_LANGUAGE |
| 56 | + }; |
| 57 | + |
| 58 | + const brand = await createBrand(args); |
| 59 | + |
| 60 | + should.exist(brand); |
| 61 | + should.exist(brand.brands); |
| 62 | + should.exist(brand.brands[0]); |
| 63 | + should.exist(brand.brands[0].brandId); |
| 64 | + |
| 65 | + BRAND_ID = brand.brands[0].brandId; |
| 66 | + }); |
| 67 | + |
| 68 | + it('applyBrandToEnvelope method should create the correct envelope and apply brand to it if correct data is provided', async function() { |
| 69 | + this.timeout(TEST_TIMEOUT_MS); |
| 70 | + |
| 71 | + const envelopeArgs = { |
| 72 | + signerEmail: settings.signerEmail, |
| 73 | + signerName: settings.signerName, |
| 74 | + brandId: BRAND_ID, |
| 75 | + status: "sent", |
| 76 | + doc2File: path.resolve(TEST_DOCX_FILE), |
| 77 | + doc3File: path.resolve(TEST_PDF_FILE), |
| 78 | + }; |
| 79 | + const args = { |
| 80 | + accessToken: ACCESS_TOKEN, |
| 81 | + basePath: BASE_PATH, |
| 82 | + accountId: ACCOUNT_ID, |
| 83 | + envelopeArgs: envelopeArgs |
| 84 | + }; |
| 85 | + |
| 86 | + const { envelopeId } = await applyBrandToEnvelope(args); |
| 87 | + |
| 88 | + should.exist(envelopeId); |
| 89 | + }); |
| 90 | + |
| 91 | + it('makeEnvelope method of applyBrandToEnvelope example should create the correct envelope definition if correct data is provided', async function() { |
| 92 | + this.timeout(TEST_TIMEOUT_MS); |
| 93 | + |
| 94 | + const envelopeArgs = { |
| 95 | + signerEmail: settings.signerEmail, |
| 96 | + signerName: settings.signerName, |
| 97 | + brandId: BRAND_ID, |
| 98 | + status: "sent", |
| 99 | + doc2File: path.resolve(TEST_DOCX_FILE), |
| 100 | + doc3File: path.resolve(TEST_PDF_FILE), |
| 101 | + }; |
| 102 | + |
| 103 | + const document1Text = ` |
| 104 | + <!DOCTYPE html> |
| 105 | + <html> |
| 106 | + <head> |
| 107 | + <meta charset="UTF-8"> |
| 108 | + </head> |
| 109 | + <body style="font-family:sans-serif;margin-left:2em;"> |
| 110 | + <h1 style="font-family: 'Trebuchet MS', Helvetica, sans-serif; |
| 111 | + color: darkblue;margin-bottom: 0;">World Wide Corp</h1> |
| 112 | + <h2 style="font-family: 'Trebuchet MS', Helvetica, sans-serif; |
| 113 | + margin-top: 0px;margin-bottom: 3.5em;font-size: 1em; |
| 114 | + color: darkblue;">Order Processing Division</h2> |
| 115 | + <h4>Ordered by ${settings.signerName}</h4> |
| 116 | + <p style="margin-top:0em; margin-bottom:0em;">Email: ${settings.signerEmail}</p> |
| 117 | + <p style="margin-top:3em;"> |
| 118 | + 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. |
| 119 | + </p> |
| 120 | + <!-- Note the anchor tag for the signature field is in white. --> |
| 121 | + <h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3> |
| 122 | + </body> |
| 123 | + </html> |
| 124 | + `; |
| 125 | + |
| 126 | + const expected = { |
| 127 | + emailSubject: "Please sign this document set", |
| 128 | + documents: [ |
| 129 | + { |
| 130 | + documentBase64: Buffer.from(document1Text).toString("base64"), |
| 131 | + name: 'Order acknowledgement', |
| 132 | + fileExtension: 'html', |
| 133 | + documentId: '1', |
| 134 | + }, |
| 135 | + { |
| 136 | + documentBase64: Buffer.from(fs.readFileSync(path.resolve(TEST_DOCX_FILE))).toString("base64"), |
| 137 | + name: "Battle Plan", |
| 138 | + fileExtension: "docx", |
| 139 | + documentId: "2", |
| 140 | + }, |
| 141 | + { |
| 142 | + documentBase64: Buffer.from(fs.readFileSync(path.resolve(TEST_PDF_FILE))).toString("base64"), |
| 143 | + name: "Lorem Ipsum", |
| 144 | + fileExtension: "pdf", |
| 145 | + documentId: "3", |
| 146 | + } |
| 147 | + ], |
| 148 | + recipients: { |
| 149 | + signers: [ |
| 150 | + { |
| 151 | + email: settings.signerEmail, |
| 152 | + name: settings.signerName, |
| 153 | + recipientId: '1', |
| 154 | + routingOrder: '1', |
| 155 | + tabs: { |
| 156 | + signHereTabs: [ |
| 157 | + { |
| 158 | + anchorString: "**signature_1**", |
| 159 | + anchorYOffset: "10", |
| 160 | + anchorUnits: "pixels", |
| 161 | + anchorXOffset: "20", |
| 162 | + }, |
| 163 | + { |
| 164 | + anchorString: "/sn1/", |
| 165 | + anchorYOffset: "10", |
| 166 | + anchorUnits: "pixels", |
| 167 | + anchorXOffset: "20", |
| 168 | + } |
| 169 | + ] |
| 170 | + } |
| 171 | + } |
| 172 | + ], |
| 173 | + }, |
| 174 | + status: 'sent', |
| 175 | + brandId: BRAND_ID |
| 176 | + }; |
| 177 | + |
| 178 | + const envelope = await makeEnvelopeForApplyingBrand(envelopeArgs); |
| 179 | + |
| 180 | + should.exist(envelope); |
| 181 | + expect(envelope).excluding(['']).to.deep.equal(expected); |
| 182 | + }); |
| 183 | + |
| 184 | + it('document1 method of applyBrandToEnvelope example should return correct HTML document if correct data is provided', async function() { |
| 185 | + this.timeout(TEST_TIMEOUT_MS); |
| 186 | + |
| 187 | + const args = { |
| 188 | + signerEmail: settings.signerEmail, |
| 189 | + signerName: settings.signerName, |
| 190 | + brandId: BRAND_ID, |
| 191 | + status: "sent", |
| 192 | + doc2File: path.resolve(TEST_DOCX_FILE), |
| 193 | + doc3File: path.resolve(TEST_PDF_FILE), |
| 194 | + }; |
| 195 | + |
| 196 | + const expected = ` |
| 197 | + <!DOCTYPE html> |
| 198 | + <html> |
| 199 | + <head> |
| 200 | + <meta charset="UTF-8"> |
| 201 | + </head> |
| 202 | + <body style="font-family:sans-serif;margin-left:2em;"> |
| 203 | + <h1 style="font-family: 'Trebuchet MS', Helvetica, sans-serif; |
| 204 | + color: darkblue;margin-bottom: 0;">World Wide Corp</h1> |
| 205 | + <h2 style="font-family: 'Trebuchet MS', Helvetica, sans-serif; |
| 206 | + margin-top: 0px;margin-bottom: 3.5em;font-size: 1em; |
| 207 | + color: darkblue;">Order Processing Division</h2> |
| 208 | + <h4>Ordered by ${settings.signerName}</h4> |
| 209 | + <p style="margin-top:0em; margin-bottom:0em;">Email: ${settings.signerEmail}</p> |
| 210 | + <p style="margin-top:3em;"> |
| 211 | + 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. |
| 212 | + </p> |
| 213 | + <!-- Note the anchor tag for the signature field is in white. --> |
| 214 | + <h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3> |
| 215 | + </body> |
| 216 | + </html> |
| 217 | + `; |
| 218 | + |
| 219 | + const html_doc = await makeHtmlDocForApplyingBrand(args); |
| 220 | + |
| 221 | + should.exist(html_doc); |
| 222 | + expect(html_doc).to.be.equal(expected); |
| 223 | + }); |
| 224 | + |
| 225 | + it('getBrands method of applyBrandToEnvelope example should return the list of brands if correct data is provided', async function() { |
| 226 | + this.timeout(TEST_TIMEOUT_MS); |
| 227 | + |
| 228 | + const args = { |
| 229 | + accessToken: ACCESS_TOKEN, |
| 230 | + basePath: BASE_PATH, |
| 231 | + accountId: ACCOUNT_ID, |
| 232 | + }; |
| 233 | + |
| 234 | + const brands = await getBrands(args); |
| 235 | + |
| 236 | + should.exist(brands); |
| 237 | + }); |
| 238 | + |
| 239 | + it('createPermission should create correct permission profile if correct data is provided', async function() { |
| 240 | + this.timeout(TEST_TIMEOUT_MS); |
| 241 | + |
| 242 | + const args = { |
| 243 | + accessToken: ACCESS_TOKEN, |
| 244 | + basePath: BASE_PATH, |
| 245 | + accountId: ACCOUNT_ID, |
| 246 | + profileName: `${PERMISSION_PROFILE_NAME}_${Date.now()}`, |
| 247 | + }; |
| 248 | + |
| 249 | + const profile = await createPermission(args); |
| 250 | + |
| 251 | + should.exist(profile); |
| 252 | + }); |
| 253 | +}) |
0 commit comments