maskdata 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,497 @@
1
1
  'use strict';
2
- const maskData = require('../index');
2
+
3
3
  const expect = require('chai').expect;
4
4
 
5
- describe('Masking JSON fields', function() {
5
+ const maskData = require('../index');
6
+ const Constants = require('../lib/helpers/Constants');
7
+
8
+ const jsonInput = {
9
+ 'credit': '1234-5678-8765-1234',
10
+ 'debit': '0000-1111-2222-3333',
11
+ 'primaryEmail': 'primary@Email.com',
12
+ 'secondaryEmail': 'secondary@Email.com',
13
+ 'password': 'dummyPassword',
14
+ 'homePhone': "+1 1234567890",
15
+ 'workPhone': "+1 9876543210",
16
+ 'addressLine1': "This is my addressline 1. This is my home",
17
+ 'addressLine2': "AddressLine 2",
18
+ 'uuid1': '123e4567-e89b-12d3-a456-426614174000'
19
+ };
20
+
21
+ describe('JSON mask1', function() {
22
+ describe('Mask json with default options', function() {
23
+ let testData = {
24
+ title: "Mask json with default options",
25
+ input: {
26
+ level1: {
27
+ field1: "field1Value",
28
+ level2: {
29
+ field2: "field2Value",
30
+ field3: [ { Hello: "Hello", Hi: "one" }, { Hello: "Hello again" } ],
31
+ level3: {
32
+ field4: "field4Value",
33
+ field5: "field5Value"
34
+ }
35
+ }
36
+ },
37
+ value1: "value"
38
+ }
39
+ }
40
+
41
+ it(`${testData.title}`, function() {
42
+ const jsonMaskConfig = {
43
+ fields : ['level1.level2.field3[*].Hello', 'level1.level2.level3.*', 'value1']
44
+ };
45
+ const masked = maskData.maskJSONFields(testData.input, jsonMaskConfig);
46
+ expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal("*****");
47
+ expect(masked['level1']['level2']['field3'][1]['Hello']).to.equal("***********");
48
+ expect(masked['level1']['level2']['level3']['field4']).to.equal("***********");
49
+ expect(masked['level1']['level2']['level3']['field5']).to.equal("***********");
50
+ expect(masked['value1']).to.equal("*****");
51
+ });
52
+
53
+ it('Mask json with maxMaskedCharactersStr', function() {
54
+ const jsonMaskConfig = {
55
+ fields : ['key1'],
56
+ maxMaskedCharactersStr: 10
57
+ };
58
+ const masked = maskData.maskJSONFields({key1: "value1WithTooManyCharacters"}, jsonMaskConfig);
59
+ expect(masked['key1']).to.equal("**********");
60
+ });
61
+ });
62
+
63
+ describe('Mask json without passing configs', function() {
64
+ let testData = {
65
+ title: "Mask json with default options",
66
+ input: {
67
+ level1: {
68
+ field1: "field1Value",
69
+ level2: {
70
+ field2: "field2Value",
71
+ field3: [ { Hello: "Hello", Hi: "one" }, { Hello: "Hello again" }, { NoHello: "No Hello"} ],
72
+ level3: {
73
+ field4: "field4Value",
74
+ field5: "field5Value"
75
+ }
76
+ }
77
+ },
78
+ value1: "value"
79
+ }
80
+ }
81
+
82
+ it(`${testData.title}`, function() {
83
+ const jsonMaskConfig = {
84
+ fields : ['level1.level2.field3[*].Hello', 'level1.level2.level3.*', 'value1', 'unknownField']
85
+ };
86
+ const masked = maskData.maskJSONFields(testData.input);
87
+ expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal(testData.input['level1']['level2']['field3'][0]['Hello']);
88
+ expect(masked['level1']['level2']['field3'][1]['Hello']).to.equal(testData.input['level1']['level2']['field3'][1]['Hello']);
89
+ expect(masked['level1']['level2']['level3']['field4']).to.equal(testData.input['level1']['level2']['level3']['field4']);
90
+ expect(masked['level1']['level2']['level3']['field5']).to.equal(testData.input['level1']['level2']['level3']['field5']);
91
+ expect(masked['value1']).to.equal(testData.input['value1']);
92
+ });
93
+ });
6
94
 
7
- // TODO - migrate all tests from test.js into mocha tests to fail on error
8
- // TODO - extend tests
9
95
  });
96
+
97
+ describe('JSON mask2', function() {
98
+
99
+ describe('Mask with default options and no fields', function() {
100
+ let testData = [
101
+ {
102
+ title: 'test json masking with default options and no fields',
103
+ input: JSON.parse(JSON.stringify(jsonInput)),
104
+ outputCredit: '1234-5678-8765-1234',
105
+ outputDebit: '0000-1111-2222-3333',
106
+ outputPrimaryEmail: 'primary@Email.com',
107
+ outputSecondaryEmail: 'secondary@Email.com',
108
+ outputPassword: 'dummyPassword',
109
+ outputHomePhone: "+1 1234567890",
110
+ outputWorkPhone: "+1 9876543210",
111
+ outputAddressLine1: "This is my addressline 1. This is my home",
112
+ outputAddressLine2: "AddressLine 2",
113
+ outputUuid: "123e4567-e89b-12d3-a456-426614174000"
114
+ },
115
+ ]
116
+
117
+ testData.forEach(({title, input, outputCredit, outputDebit, outputPrimaryEmail, outputSecondaryEmail,
118
+ outputPassword, outputHomePhone, outputWorkPhone, outputAddressLine1, outputAddressLine2, outputUuid}) => {
119
+ it(`${title}`, function() {
120
+ const masked = maskData.maskJSON2(input, Constants.defaultjsonMask2Configs);
121
+ expect(masked['credit']).to.equal(outputCredit);
122
+ expect(masked['debit']).to.equal(outputDebit);
123
+ expect(masked['primaryEmail']).to.equal(outputPrimaryEmail);
124
+ expect(masked['secondaryEmail']).to.equal(outputSecondaryEmail);
125
+ expect(masked['password']).to.equal(outputPassword);
126
+ expect(masked['homePhone']).to.equal(outputHomePhone);
127
+ expect(masked['workPhone']).to.equal(outputWorkPhone);
128
+ expect(masked['addressLine1']).to.equal(outputAddressLine1);
129
+ expect(masked['addressLine2']).to.equal(outputAddressLine2);
130
+ expect(masked['uuid1']).to.equal(outputUuid);
131
+ });
132
+ })
133
+ });
134
+
135
+ describe('Mask all fields with default options', function() {
136
+ let testData = [
137
+ {
138
+ title: 'test json masking with default options and all types of fields',
139
+ input: JSON.parse(JSON.stringify(jsonInput)),
140
+ outputCredit: '1234-****-****-***4',
141
+ outputDebit: '0000-****-****-***3',
142
+ outputPrimaryEmail: 'pri****@*******om',
143
+ outputSecondaryEmail: 'sec******@*******om',
144
+ outputPassword: '*************',
145
+ outputHomePhone: "+1 1********0",
146
+ outputWorkPhone: "+1 9********0",
147
+ outputAddressLine1: "This is my addressline 1. This is my home",
148
+ outputAddressLine2: "AddressLine 2",
149
+ outputUuid: "********-****-****-****-************"
150
+ },
151
+ ]
152
+
153
+ testData.forEach(({title, input, outputCredit, outputDebit, outputPrimaryEmail, outputSecondaryEmail,
154
+ outputPassword, outputHomePhone, outputWorkPhone, outputAddressLine1, outputAddressLine2, outputUuid}) => {
155
+
156
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
157
+ jsonMaskConfig['cardFields'] = ['credit', 'debit'];
158
+ jsonMaskConfig['emailFields'] = ['primaryEmail', 'secondaryEmail'];
159
+ jsonMaskConfig['passwordFields'] = ['password'];
160
+ jsonMaskConfig['phoneFields'] = ['homePhone', 'workPhone'];
161
+ jsonMaskConfig['stringFields'] = ['addressLine1', 'addressLine2'];
162
+ jsonMaskConfig['uuidFields'] = ['uuid1'];
163
+ it(`${title}`, function() {
164
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
165
+ expect(masked['credit']).to.equal(outputCredit);
166
+ expect(masked['debit']).to.equal(outputDebit);
167
+ expect(masked['primaryEmail']).to.equal(outputPrimaryEmail);
168
+ expect(masked['secondaryEmail']).to.equal(outputSecondaryEmail);
169
+ expect(masked['password']).to.equal(outputPassword);
170
+ expect(masked['homePhone']).to.equal(outputHomePhone);
171
+ expect(masked['workPhone']).to.equal(outputWorkPhone);
172
+ expect(masked['addressLine1']).to.equal(outputAddressLine1);
173
+ expect(masked['addressLine2']).to.equal(outputAddressLine2);
174
+ expect(masked['uuid1']).to.equal(outputUuid);
175
+ });
176
+ })
177
+ });
178
+
179
+ describe('Mask all nested fields with default options', function() {
180
+ const jsonInput2 = {
181
+ cards: {
182
+ creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'],
183
+ debitCards: ['0000-1111-2222-3333', '2222-1111-3333-4444']
184
+ },
185
+ emails: {
186
+ primaryEmail: 'primary@Email.com',
187
+ secondaryEmail: 'secondary@Email.com'
188
+ },
189
+ password: 'dummyPasswordANDdummyPassword',
190
+ phones: {
191
+ homePhone: "+1 1234567890",
192
+ workPhone: "+1 9876543210",
193
+ },
194
+ address: {
195
+ addressLine1: "This is my addressline 1. This is my home",
196
+ addressLine2: "AddressLine 2"
197
+ },
198
+ uuids: {
199
+ uuid1: '123e4567-e89b-12d3-a456-426614174000'
200
+ }
201
+ };
202
+
203
+ let testData = [
204
+ {
205
+ title: 'test json masking with default options and all types of fields',
206
+ input: jsonInput2,
207
+ outputCredit: '1234-****-****-***4',
208
+ outputDebit: '0000-****-****-***3',
209
+ outputPrimaryEmail: 'pri****@*******om',
210
+ outputSecondaryEmail: 'sec******@*******om',
211
+ outputPassword: '****************',
212
+ outputHomePhone: "+1 1********0",
213
+ outputWorkPhone: "+1 9********0",
214
+ outputAddressLine1: "This is my addressline 1. This is my home",
215
+ outputAddressLine2: "AddressLine 2",
216
+ outputUuid: "********-****-****-****-************"
217
+ },
218
+ ]
219
+
220
+ testData.forEach(({title, input, outputCredit, outputDebit, outputPrimaryEmail, outputSecondaryEmail,
221
+ outputPassword, outputHomePhone, outputWorkPhone, outputAddressLine1, outputAddressLine2, outputUuid}) => {
222
+
223
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
224
+ jsonMaskConfig['cardFields'] = ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'];
225
+ jsonMaskConfig['emailFields'] = ['emails.primaryEmail', 'emails.secondaryEmail'];
226
+ jsonMaskConfig['passwordFields'] = ['password'];
227
+ jsonMaskConfig['phoneFields'] = ['phones.homePhone', 'phones.workPhone'];
228
+ jsonMaskConfig['stringFields'] = ['address.addressLine1', 'address.addressLine2'];
229
+ jsonMaskConfig['uuidFields'] = ['uuids.uuid1'];
230
+ it(`${title}`, function() {
231
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
232
+ expect(masked['cards']['creditCards'][0]).to.equal(outputCredit);
233
+ expect(masked['cards']['creditCards'][1]).to.equal('1111-****-****-***2');
234
+ expect(masked['cards']['debitCards'][0]).to.equal(outputDebit);
235
+ expect(masked['cards']['debitCards'][1]).to.equal('2222-****-****-***4');
236
+
237
+ expect(masked['emails']['primaryEmail']).to.equal(outputPrimaryEmail);
238
+ expect(masked['emails']['secondaryEmail']).to.equal(outputSecondaryEmail);
239
+
240
+ expect(masked['password']).to.equal(outputPassword);
241
+
242
+ expect(masked['phones']['homePhone']).to.equal(outputHomePhone);
243
+ expect(masked['phones']['workPhone']).to.equal(outputWorkPhone);
244
+
245
+ expect(masked['address']['addressLine1']).to.equal(outputAddressLine1);
246
+ expect(masked['address']['addressLine2']).to.equal(outputAddressLine2);
247
+
248
+ expect(masked['uuids']['uuid1']).to.equal(outputUuid);
249
+ });
250
+ it('Test masking improper JSON', function() {
251
+ const notAJson = "Not a JSON. Just a String";
252
+ const masked = maskData.maskJSON2(notAJson, jsonMaskConfig);
253
+ expect(masked).to.equal(notAJson);
254
+ });
255
+ })
256
+ });
257
+
258
+ describe('Mask card fields with custom options', function() {
259
+ let testData = [
260
+ {
261
+ title: 'Mask card fields with custom options',
262
+ input: JSON.parse(JSON.stringify(jsonInput)),
263
+ outputCredit: 'XXXX-XXXX-XXXX-1234',
264
+ outputDebit: 'XXXX-XXXX-XXXX-3333'
265
+ }
266
+ ]
267
+
268
+ testData.forEach(({title, input, outputCredit, outputDebit}) => {
269
+
270
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
271
+ const cardMaskOptions = JSON.parse(JSON.stringify(Constants.defaultCardMaskOptions));
272
+ // const defaultCardMaskOptions = {
273
+ // maskWith: "*",
274
+ // unmaskedStartDigits: 4,
275
+ // unmaskedEndDigits: 1
276
+ // };
277
+ cardMaskOptions['maskWith'] = "X"
278
+ cardMaskOptions['unmaskedStartDigits'] = 0
279
+ cardMaskOptions['unmaskedEndDigits'] = 4
280
+ jsonMaskConfig['cardFields'] = ['credit', 'debit'];
281
+ jsonMaskConfig['cardMaskOptions'] = cardMaskOptions;
282
+ it(`${title}`, function() {
283
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
284
+ expect(masked['credit']).to.equal(outputCredit);
285
+ expect(masked['debit']).to.equal(outputDebit);
286
+ expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
287
+ expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
288
+ expect(masked['password']).to.equal(input['password']);
289
+ expect(masked['homePhone']).to.equal(input['homePhone']);
290
+ expect(masked['workPhone']).to.equal(input['workPhone']);
291
+ expect(masked['addressLine1']).to.equal(input['addressLine1']);
292
+ expect(masked['addressLine2']).to.equal(input['addressLine2']);
293
+ });
294
+ })
295
+ });
296
+
297
+ describe('Mask email fields with custom options', function() {
298
+ let testData = [
299
+ {
300
+ title: 'Mask email fields with custom options',
301
+ input: JSON.parse(JSON.stringify(jsonInput)),
302
+ outputPrimaryEmail: 'prim...@........m',
303
+ outputSecondaryEmail: 'seco.....@........m'
304
+ },
305
+ ]
306
+
307
+ testData.forEach(({title, input, outputPrimaryEmail, outputSecondaryEmail}) => {
308
+
309
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
310
+ const emailMaskOptions = JSON.parse(JSON.stringify(Constants.defaultEmailMask2Options));
311
+ // const defaultEmailMask2Options = {
312
+ // maskWith: "*",
313
+ // unmaskedStartCharactersBeforeAt: 3,
314
+ // unmaskedEndCharactersAfterAt: 2,
315
+ // maskAtTheRate: false
316
+ // };
317
+ emailMaskOptions['maskWith'] = "."
318
+ emailMaskOptions['unmaskedStartCharactersBeforeAt'] = 4
319
+ emailMaskOptions['unmaskedEndCharactersAfterAt'] = 1
320
+ jsonMaskConfig['emailFields'] = ['primaryEmail', 'secondaryEmail'];
321
+ jsonMaskConfig['emailMaskOptions'] = emailMaskOptions;
322
+
323
+ it(`${title}`, function() {
324
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
325
+ expect(masked['credit']).to.equal(input['credit']);
326
+ expect(masked['debit']).to.equal(input['debit']);
327
+ expect(masked['primaryEmail']).to.equal(outputPrimaryEmail);
328
+ expect(masked['secondaryEmail']).to.equal(outputSecondaryEmail);
329
+ expect(masked['password']).to.equal(input['password']);
330
+ expect(masked['homePhone']).to.equal(input['homePhone']);
331
+ expect(masked['workPhone']).to.equal(input['workPhone']);
332
+ expect(masked['addressLine1']).to.equal(input['addressLine1']);
333
+ expect(masked['addressLine2']).to.equal(input['addressLine2']);
334
+ });
335
+ })
336
+ });
337
+
338
+ describe('Mask password fields with custom options', function() {
339
+ let testData = [
340
+ {
341
+ title: 'Mask password fields with custom options',
342
+ input: JSON.parse(JSON.stringify(jsonInput)),
343
+ outputPassword: 'd????d'
344
+ },
345
+ ]
346
+
347
+ testData.forEach(({title, input, outputPassword}) => {
348
+
349
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
350
+ const passwordMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPasswordMaskOptions));
351
+ // const defaultPasswordMaskOptions = {
352
+ // maskWith: "*",
353
+ // maxMaskedCharacters: 16,
354
+ // unmaskedStartCharacters: 0,
355
+ // unmaskedEndCharacters: 0
356
+ // };
357
+ passwordMaskOptions['maskWith'] = "?"
358
+ passwordMaskOptions['maxMaskedCharacters'] = 6
359
+ passwordMaskOptions['unmaskedStartCharacters'] = 1
360
+ passwordMaskOptions['unmaskedEndCharacters'] = 1
361
+ jsonMaskConfig['passwordFields'] = ['password'];
362
+ jsonMaskConfig['passwordMaskOptions'] = passwordMaskOptions;
363
+ it(`${title}`, function() {
364
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
365
+ expect(masked['credit']).to.equal(input['credit']);
366
+ expect(masked['debit']).to.equal(input['debit']);
367
+ expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
368
+ expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
369
+ expect(masked['password']).to.equal(outputPassword);
370
+ expect(masked['homePhone']).to.equal(input['homePhone']);
371
+ expect(masked['workPhone']).to.equal(input['workPhone']);
372
+ expect(masked['addressLine1']).to.equal(input['addressLine1']);
373
+ expect(masked['addressLine2']).to.equal(input['addressLine2']);
374
+ });
375
+ })
376
+ });
377
+
378
+ describe('Mask phone fields with custom options', function() {
379
+ let testData = [
380
+ {
381
+ title: 'Mask phone fields with custom options',
382
+ input: JSON.parse(JSON.stringify(jsonInput)),
383
+ outputHomePhone: '+1 #######890',
384
+ outputWorkPhone: '+1 #######210'
385
+ },
386
+ ]
387
+
388
+ testData.forEach(({title, input, outputHomePhone, outputWorkPhone}) => {
389
+
390
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
391
+ const phoneMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPhoneMaskOptions));
392
+ // const defaultPhoneMaskOptions = {
393
+ // maskWith: "*",
394
+ // unmaskedStartDigits: 4,
395
+ // unmaskedEndDigits: 1
396
+ // };
397
+ phoneMaskOptions['maskWith'] = "#"
398
+ phoneMaskOptions['unmaskedStartDigits'] = 3
399
+ phoneMaskOptions['unmaskedEndDigits'] = 3
400
+ jsonMaskConfig['phoneFields'] = ['homePhone', 'workPhone'];
401
+ jsonMaskConfig['phoneMaskOptions'] = phoneMaskOptions;
402
+ it(`${title}`, function() {
403
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
404
+ expect(masked['credit']).to.equal(input['credit']);
405
+ expect(masked['debit']).to.equal(input['debit']);
406
+ expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
407
+ expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
408
+ expect(masked['password']).to.equal(input['password']);
409
+ expect(masked['homePhone']).to.equal(outputHomePhone);
410
+ expect(masked['workPhone']).to.equal(outputWorkPhone);
411
+ expect(masked['addressLine1']).to.equal(input['addressLine1']);
412
+ expect(masked['addressLine2']).to.equal(input['addressLine2']);
413
+ });
414
+ })
415
+ });
416
+
417
+ describe('Mask String fields with custom options', function() {
418
+ let testData = [
419
+ {
420
+ title: 'Mask String fields with custom options',
421
+ input: JSON.parse(JSON.stringify(jsonInput)),
422
+ outputAddressLine1: 'XXXX is my addressline 1. This is my home',
423
+ outputAddressLine2: 'AddressLine 2'
424
+ },
425
+ ]
426
+
427
+ testData.forEach(({title, input, outputAddressLine1, outputAddressLine2}) => {
428
+
429
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
430
+ const stringMaskOptions = JSON.parse(JSON.stringify(Constants.defaultStringMaskOptions));
431
+ // const defaultStringMaskOptions = {
432
+ // maskWith: "*",
433
+ // maskOnlyFirstOccurance: false,
434
+ // values: [],
435
+ // maskAll: false,
436
+ // maskSpace: true
437
+ // };
438
+ stringMaskOptions['maskWith'] = "X"
439
+ stringMaskOptions['maskOnlyFirstOccurance'] = true
440
+ stringMaskOptions['values'] = ['This']
441
+ jsonMaskConfig['stringFields'] = ['addressLine1', 'addressLine2'];
442
+ jsonMaskConfig['stringMaskOptions'] = stringMaskOptions;
443
+ it(`${title}`, function() {
444
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
445
+ expect(masked['credit']).to.equal(input['credit']);
446
+ expect(masked['debit']).to.equal(input['debit']);
447
+ expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
448
+ expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
449
+ expect(masked['password']).to.equal(input['password']);
450
+ expect(masked['homePhone']).to.equal(input['homePhone']);
451
+ expect(masked['workPhone']).to.equal(input['workPhone']);
452
+ expect(masked['addressLine1']).to.equal(outputAddressLine1);
453
+ expect(masked['addressLine2']).to.equal(outputAddressLine2);
454
+ });
455
+ })
456
+ });
457
+
458
+ describe('Mask UUID fields with custom options', function() {
459
+ let testData = [
460
+ {
461
+ title: 'Mask UUID fields with custom options',
462
+ input: JSON.parse(JSON.stringify(jsonInput)),
463
+ outputUuid: "123e4567-XXXX-XXXX-XXXX-426614174000"
464
+ },
465
+ ]
466
+
467
+ testData.forEach(({title, input, outputUuid}) => {
468
+
469
+ const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
470
+ const uuidMaskOptions = JSON.parse(JSON.stringify(Constants.defaultUuidMaskOptions));
471
+ // const defaultUuidMaskOptions = {
472
+ // maskWith: "*",
473
+ // unmaskedStartCharacters: 0,
474
+ // unmaskedEndCharacters: 0
475
+ // };
476
+ uuidMaskOptions['maskWith'] = "X"
477
+ uuidMaskOptions['unmaskedStartCharacters'] = 8
478
+ uuidMaskOptions['unmaskedEndCharacters'] = 12
479
+ jsonMaskConfig['uuidFields'] = ['uuid1'];
480
+ jsonMaskConfig['uuidMaskOptions'] = uuidMaskOptions;
481
+ it(`${title}`, function() {
482
+ const masked = maskData.maskJSON2(input, jsonMaskConfig);
483
+ expect(masked['credit']).to.equal(input['credit']);
484
+ expect(masked['debit']).to.equal(input['debit']);
485
+ expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
486
+ expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
487
+ expect(masked['password']).to.equal(input['password']);
488
+ expect(masked['homePhone']).to.equal(input['homePhone']);
489
+ expect(masked['workPhone']).to.equal(input['workPhone']);
490
+ expect(masked['addressLine1']).to.equal(input['addressLine1']);
491
+ expect(masked['addressLine2']).to.equal(input['addressLine2']);
492
+ expect(masked['uuid1']).to.equal(outputUuid);
493
+ });
494
+ })
495
+ });
496
+
497
+ });
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+ const maskData = require('../index');
3
+ const expect = require('chai').expect;
4
+
5
+ describe('Test getValue', function() {
6
+ describe('Test get JSON field values', function() {
7
+
8
+ let testData = [
9
+ {
10
+ title: 'test getting a string field from json',
11
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
12
+ fieldToGet: 'stringField',
13
+ output: 'StringValue'
14
+ },
15
+ {
16
+ title: 'test getting a boolean field from json',
17
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
18
+ fieldToGet: 'booleanField',
19
+ output: true
20
+ },
21
+ {
22
+ title: 'test getting a number field from json',
23
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
24
+ fieldToGet: 'numberField',
25
+ output: 1000
26
+ }
27
+ ]
28
+
29
+ testData.forEach(({title, input, fieldToGet, output}) => {
30
+ it(`default mask - ${title}`, function() {
31
+ const jsonFieldValue = maskData.getInnerProperty(input, fieldToGet);
32
+ expect(jsonFieldValue).to.equal(output, 'Expected json property found');
33
+ });
34
+ })
35
+ });
36
+ });
37
+
38
+ describe('Test replaceValue', function() {
39
+ describe('Test replace json field Value', function() {
40
+
41
+ let testData = [
42
+ {
43
+ title: 'test replacing a string field value from json',
44
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
45
+ fieldToReplace: 'stringField',
46
+ output: 'NewStringValue'
47
+ },
48
+ {
49
+ title: 'test replacing a boolean field value from json',
50
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
51
+ fieldToReplace: 'booleanField',
52
+ output: false
53
+ },
54
+ {
55
+ title: 'test replacing a number field value from json',
56
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
57
+ fieldToReplace: 'numberField',
58
+ output: 1111
59
+ },
60
+ {
61
+ title: 'test replacing a object field value from json',
62
+ input: {'stringField': "StringValue", "booleanField": true, "numberField": 1000, "objectField" : [1, 2, 3, 4]},
63
+ fieldToReplace: 'objectField',
64
+ output: false
65
+ }
66
+ ]
67
+
68
+ testData.forEach(({title, input, fieldToReplace, output}) => {
69
+ it(`default mask - ${title}`, function() {
70
+ const jsonAfterReplacing = maskData.replaceValue(input, fieldToReplace, output);
71
+ expect(jsonAfterReplacing[fieldToReplace]).to.equal(output, 'Expected json property found');
72
+ });
73
+ })
74
+ });
75
+ });