functional-models 1.1.23 → 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.
Files changed (65) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +186 -0
  3. package/.github/workflows/feature.yml +26 -0
  4. package/.github/workflows/ut.yml +32 -0
  5. package/.prettierignore +7 -0
  6. package/.prettierrc.json +14 -0
  7. package/LICENSE +674 -0
  8. package/features/arrayFields.feature +52 -0
  9. package/features/functions.feature +11 -0
  10. package/features/model.feature +7 -0
  11. package/features/stepDefinitions/steps.js +193 -0
  12. package/features/validation.feature +12 -0
  13. package/index.js +1 -41
  14. package/package.json +10 -35
  15. package/src/constants.js +19 -0
  16. package/src/errors.js +16 -0
  17. package/src/functions.js +7 -0
  18. package/src/index.js +10 -0
  19. package/src/lazy.js +26 -0
  20. package/src/models.js +152 -0
  21. package/src/properties.js +313 -0
  22. package/src/serialization.js +50 -0
  23. package/src/utils.js +52 -0
  24. package/src/validation.js +285 -0
  25. package/test/base/index.test.js +5 -0
  26. package/test/src/functions.test.js +45 -0
  27. package/test/src/index.test.js +5 -0
  28. package/test/src/lazy.test.js +15 -0
  29. package/test/src/models.test.js +380 -0
  30. package/test/src/properties.test.js +554 -0
  31. package/test/src/serialization.test.js +127 -0
  32. package/test/src/utils.test.js +54 -0
  33. package/test/src/validation.test.js +614 -0
  34. package/constants.d.ts +0 -14
  35. package/constants.js +0 -19
  36. package/constants.js.map +0 -1
  37. package/errors.d.ts +0 -9
  38. package/errors.js +0 -15
  39. package/errors.js.map +0 -1
  40. package/index.d.ts +0 -10
  41. package/index.js.map +0 -1
  42. package/interfaces.d.ts +0 -163
  43. package/interfaces.js +0 -4
  44. package/interfaces.js.map +0 -1
  45. package/lazy.d.ts +0 -2
  46. package/lazy.js +0 -37
  47. package/lazy.js.map +0 -1
  48. package/methods.d.ts +0 -4
  49. package/methods.js +0 -18
  50. package/methods.js.map +0 -1
  51. package/models.d.ts +0 -3
  52. package/models.js +0 -129
  53. package/models.js.map +0 -1
  54. package/properties.d.ts +0 -16
  55. package/properties.js +0 -214
  56. package/properties.js.map +0 -1
  57. package/serialization.d.ts +0 -3
  58. package/serialization.js +0 -49
  59. package/serialization.js.map +0 -1
  60. package/utils.d.ts +0 -5
  61. package/utils.js +0 -51
  62. package/utils.js.map +0 -1
  63. package/validation.d.ts +0 -29
  64. package/validation.js +0 -292
  65. package/validation.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ const assert = require('chai').assert
2
+ const sinon = require('sinon')
3
+ const proxyquire = require('proxyquire')
4
+ const { loweredTitleCase, createUuid } = require('../../src/utils')
5
+
6
+ describe('/src/utils.js', () => {
7
+ describe('#loweredTitleCase()', () => {
8
+ it('should turn TitleCase into titleCase', () => {
9
+ const actual = loweredTitleCase('TitleCase')
10
+ const expected = 'titleCase'
11
+ assert.equal(actual, expected)
12
+ })
13
+ })
14
+ describe('#createUuid()', () => {
15
+ before(() => {
16
+ window = undefined
17
+ })
18
+ after(() => {
19
+ window = undefined
20
+ })
21
+ describe('when not having access to "window"', () => {
22
+ it('should call get-random-values 31 times with hello-crypto', () => {
23
+ const getRandomValues = sinon.stub().returns('hello-crypto')
24
+ const utils = proxyquire('../../src/utils', {
25
+ 'get-random-values': getRandomValues,
26
+ })
27
+ const actual = utils.createUuid()
28
+ sinon.assert.callCount(getRandomValues, 31)
29
+ })
30
+ })
31
+ describe('when in a browser with "window"', () => {
32
+ it('should call window.crypto when it exists 31 times with hello-crypto', () => {
33
+ const getRandomValues = sinon.stub().returns('hello-crypto')
34
+ window = {
35
+ crypto: {
36
+ getRandomValues,
37
+ },
38
+ }
39
+ const actual = createUuid()
40
+ sinon.assert.callCount(getRandomValues, 31)
41
+ })
42
+ it('should call window.myCrypto when it exists 31 times with hello-crypto', () => {
43
+ const getRandomValues = sinon.stub().returns('hello-crypto')
44
+ window = {
45
+ msCrypto: {
46
+ getRandomValues,
47
+ },
48
+ }
49
+ const actual = createUuid()
50
+ sinon.assert.callCount(getRandomValues, 31)
51
+ })
52
+ })
53
+ })
54
+ })
@@ -0,0 +1,614 @@
1
+ const chai = require('chai')
2
+ const assert = chai.assert
3
+ const chaiAsPromised = require('chai-as-promised')
4
+ chai.use(chaiAsPromised)
5
+ const sinon = require('sinon')
6
+ const { Model } = require('../../src/models')
7
+ const { UniqueId, TextProperty } = require('../../src/properties')
8
+ const {
9
+ isNumber,
10
+ isBoolean,
11
+ isInteger,
12
+ isString,
13
+ isArray,
14
+ isDate,
15
+ arrayType,
16
+ isRequired,
17
+ maxNumber,
18
+ minNumber,
19
+ choices,
20
+ maxTextLength,
21
+ minTextLength,
22
+ meetsRegex,
23
+ aggregateValidator,
24
+ referenceTypeMatch,
25
+ emptyValidator,
26
+ createModelValidator,
27
+ createPropertyValidator,
28
+ TYPE_PRIMATIVES,
29
+ } = require('../../src/validation')
30
+
31
+ const TestModel1 = Model('TestModel1', {
32
+ id: UniqueId(),
33
+ })
34
+
35
+ const TestModel2 = Model('TestModel2', {
36
+ id: UniqueId(),
37
+ })
38
+
39
+ const createTestModel3 = modelValidators =>
40
+ Model(
41
+ 'TestModel3',
42
+ {
43
+ id: UniqueId(),
44
+ name: TextProperty(),
45
+ },
46
+ {
47
+ modelValidators,
48
+ }
49
+ )
50
+
51
+ describe('/src/validation.js', () => {
52
+ describe('#isDate()', () => {
53
+ it('should return an error if value is null', () => {
54
+ const actual = isDate(null)
55
+ assert.isOk(actual)
56
+ })
57
+ it('should return an error if value is undefined', () => {
58
+ const actual = isDate(undefined)
59
+ assert.isOk(actual)
60
+ })
61
+ it('should return an error object does not have toISOString', () => {
62
+ const actual = isDate({})
63
+ assert.isOk(actual)
64
+ })
65
+ it('should return undefined if a date', () => {
66
+ const actual = isDate(new Date())
67
+ assert.isUndefined(actual)
68
+ })
69
+ })
70
+ describe('#referenceTypeMatch()', () => {
71
+ it('should allow a function for a model', () => {
72
+ const myModel = TestModel1.create()
73
+ const actual = referenceTypeMatch(() => TestModel1)(myModel)
74
+ const expected = undefined
75
+ assert.equal(actual, expected)
76
+ })
77
+ it('should validate when the correct object matches the model', () => {
78
+ const myModel = TestModel1.create()
79
+ const actual = referenceTypeMatch(TestModel1)(myModel)
80
+ const expected = undefined
81
+ assert.equal(actual, expected)
82
+ })
83
+ it('should return an error when the input does not match the model', () => {
84
+ const myModel = TestModel2.create()
85
+ const actual = referenceTypeMatch(TestModel1)(myModel)
86
+ assert.isOk(actual)
87
+ })
88
+ })
89
+ describe('#isNumber()', () => {
90
+ it('should return an error when empty is passed', () => {
91
+ const actual = isNumber(null)
92
+ assert.isOk(actual)
93
+ })
94
+ it('should return an error when "asdf" is passed', () => {
95
+ const actual = isNumber('asdf')
96
+ assert.isOk(actual)
97
+ })
98
+ it('should return undefined when 1 is passed', () => {
99
+ const actual = isNumber(1)
100
+ assert.isUndefined(actual)
101
+ })
102
+ it('should return error when "1" is passed', () => {
103
+ const actual = isNumber('1')
104
+ assert.isOk(actual)
105
+ })
106
+ })
107
+ describe('#isString()', () => {
108
+ it('should return undefined when "1" is passed', () => {
109
+ const actual = isString('1')
110
+ assert.isUndefined(actual)
111
+ })
112
+ it('should return error when 1 is passed', () => {
113
+ const actual = isString(1)
114
+ assert.isOk(actual)
115
+ })
116
+ })
117
+ describe('#isRequired()', () => {
118
+ it('should return undefined when 1 is passed', () => {
119
+ const actual = isRequired(1)
120
+ assert.isUndefined(actual)
121
+ })
122
+ it('should return undefined when a date is passed', () => {
123
+ const actual = isRequired(new Date())
124
+ assert.isUndefined(actual)
125
+ })
126
+ it('should return undefined when 0 is passed', () => {
127
+ const actual = isRequired(0)
128
+ assert.isUndefined(actual)
129
+ })
130
+ it('should return undefined when "something" is passed', () => {
131
+ const actual = isRequired('something')
132
+ assert.isUndefined(actual)
133
+ })
134
+ it('should return error when null is passed', () => {
135
+ const actual = isRequired(null)
136
+ assert.isOk(actual)
137
+ })
138
+ it('should return error when undefined is passed', () => {
139
+ const actual = isRequired(undefined)
140
+ assert.isOk(actual)
141
+ })
142
+ it('should return undefined when false is passed', () => {
143
+ const actual = isRequired(false)
144
+ assert.isUndefined(actual)
145
+ })
146
+ it('should return undefined when true is passed', () => {
147
+ const actual = isRequired(true)
148
+ assert.isUndefined(actual)
149
+ })
150
+ })
151
+ describe('#isBoolean()', () => {
152
+ it('should return error when "true" is passed"', () => {
153
+ const actual = isBoolean('true')
154
+ assert.isOk(actual)
155
+ })
156
+ it('should return an error when "false" is passed', () => {
157
+ const actual = isBoolean('false')
158
+ assert.isOk(actual)
159
+ })
160
+ it('should return undefined when true is passed"', () => {
161
+ const actual = isBoolean(true)
162
+ assert.isUndefined(actual)
163
+ })
164
+ it('should return undefined when false is passed', () => {
165
+ const actual = isBoolean(false)
166
+ assert.isUndefined(actual)
167
+ })
168
+ })
169
+ describe('#maxNumber()', () => {
170
+ it('should return error if max=5 and value="hello world"', () => {
171
+ const actual = maxNumber(5)('hello world')
172
+ assert.isOk(actual)
173
+ })
174
+ it('should return error if max=5 and value=6', () => {
175
+ const actual = maxNumber(5)(6)
176
+ assert.isOk(actual)
177
+ })
178
+ it('should return undefined if max=5 and value=5', () => {
179
+ const actual = maxNumber(5)(5)
180
+ assert.isUndefined(actual)
181
+ })
182
+ it('should return undefined if max=5 and value=4', () => {
183
+ const actual = maxNumber(5)(4)
184
+ assert.isUndefined(actual)
185
+ })
186
+ })
187
+ describe('#minNumber()', () => {
188
+ it('should return error if min=5 and value="hello world"', () => {
189
+ const actual = minNumber(5)('hello world')
190
+ assert.isOk(actual)
191
+ })
192
+ it('should return error if min=5 and value=4', () => {
193
+ const actual = minNumber(5)(4)
194
+ assert.isOk(actual)
195
+ })
196
+ it('should return undefined if min=5 and value=4', () => {
197
+ const actual = minNumber(5)(5)
198
+ assert.isUndefined(actual)
199
+ })
200
+ it('should return undefined if min=5 and value=6', () => {
201
+ const actual = minNumber(5)(6)
202
+ assert.isUndefined(actual)
203
+ })
204
+ })
205
+ describe('#choices()', () => {
206
+ it('should return an error if choices are [1,2,3] and value is 4', () => {
207
+ const actual = choices([1, 2, 3])(4)
208
+ assert.isOk(actual)
209
+ })
210
+ it('should return undefined if choices are [1,2,3] and value is 1', () => {
211
+ const actual = choices([1, 2, 3])(1)
212
+ assert.isUndefined(actual)
213
+ })
214
+ })
215
+ describe('#minTextLength()', () => {
216
+ it('should return error if min=5 and value=5', () => {
217
+ const actual = minTextLength(5)(5)
218
+ assert.isOk(actual)
219
+ })
220
+ it('should return error if length=5 and value="asdf"', () => {
221
+ const actual = minTextLength(5)('asdf')
222
+ assert.isOk(actual)
223
+ })
224
+ it('should return undefined if length=5 and value="hello"', () => {
225
+ const actual = minTextLength(5)('hello')
226
+ assert.isUndefined(actual)
227
+ })
228
+ it('should return undefined if length=5 and value="hello world"', () => {
229
+ const actual = minTextLength(5)('hello world')
230
+ assert.isUndefined(actual)
231
+ })
232
+ })
233
+ describe('#maxTextLength()', () => {
234
+ it('should return error if max=5 and value=5', () => {
235
+ const actual = maxTextLength(5)(5)
236
+ assert.isOk(actual)
237
+ })
238
+ it('should return error if length=5 and value="hello world"', () => {
239
+ const actual = maxTextLength(5)('hello world')
240
+ assert.isOk(actual)
241
+ })
242
+ it('should return undefined if length=5 and value="hello"', () => {
243
+ const actual = maxTextLength(5)('hello')
244
+ assert.isUndefined(actual)
245
+ })
246
+ it('should return undefined if length=5 and value="asdf"', () => {
247
+ const actual = maxTextLength(5)('asdf')
248
+ assert.isUndefined(actual)
249
+ })
250
+ })
251
+ describe('#meetsRegex()', () => {
252
+ it('should return an error with regex=/asdf/ flags="g" and value="hello world"', () => {
253
+ const actual = meetsRegex(/asdf/, 'g')('hello world')
254
+ assert.isOk(actual)
255
+ })
256
+ it('should return undefined with regex=/asdf/ flags="g" and value="hello asdf world"', () => {
257
+ const actual = meetsRegex(/asdf/, 'g')('asdf')
258
+ assert.isUndefined(actual)
259
+ })
260
+ })
261
+ describe('#aggregateValidator()', () => {
262
+ it('should return two errors when two validators are passed, and the value fails both', async () => {
263
+ const validators = [minTextLength(10), isNumber]
264
+ const value = 'asdf'
265
+ const actual = (await aggregateValidator(validators)('asdf')).length
266
+ const expected = 2
267
+ assert.equal(actual, expected)
268
+ })
269
+ it('should return one error when one validator is passed, and the value fails', async () => {
270
+ const validators = minTextLength(10)
271
+ const value = 'asdf'
272
+ const actual = (await aggregateValidator(validators)('asdf')).length
273
+ const expected = 1
274
+ assert.equal(actual, expected)
275
+ })
276
+ })
277
+ describe('#emptyValidator()', () => {
278
+ it('should return an empty array with a value of 1', () => {
279
+ const actual = emptyValidator(1).length
280
+ const expected = 0
281
+ assert.equal(actual, expected)
282
+ })
283
+ it('should return an empty array with a value of "1"', () => {
284
+ const actual = emptyValidator('1').length
285
+ const expected = 0
286
+ assert.equal(actual, expected)
287
+ })
288
+ it('should return an empty array with a value of true', () => {
289
+ const actual = emptyValidator(true).length
290
+ const expected = 0
291
+ assert.equal(actual, expected)
292
+ })
293
+ it('should return an empty array with a value of false', () => {
294
+ const actual = emptyValidator(false).length
295
+ const expected = 0
296
+ assert.equal(actual, expected)
297
+ })
298
+ it('should return an empty array with a value of undefined', () => {
299
+ const actual = emptyValidator(undefined).length
300
+ const expected = 0
301
+ assert.equal(actual, expected)
302
+ })
303
+ })
304
+ describe('#isInteger()', () => {
305
+ it('should return an error with a value of "1"', () => {
306
+ const actual = isInteger('1')
307
+ assert.isOk(actual)
308
+ })
309
+ it('should return undefined with a value of 1', () => {
310
+ const actual = isInteger(1)
311
+ assert.isUndefined(actual)
312
+ })
313
+ })
314
+ describe('#createModelValidator()', () => {
315
+ it('should throw an exception if instance is null', () => {
316
+ const modelValidator = sinon.stub().returns(undefined)
317
+ const properties = {
318
+ functions: {
319
+ validators: {
320
+ id: sinon.stub().returns(undefined),
321
+ name: sinon.stub().returns(undefined),
322
+ },
323
+ },
324
+ }
325
+ const validator = createModelValidator(properties, [modelValidator])
326
+ assert.isRejected(validator())
327
+ })
328
+ it('should call the model validator passed in', async () => {
329
+ const modelValidator = sinon.stub().returns(undefined)
330
+ const testModel3 = createTestModel3([modelValidator])
331
+ const properties = {
332
+ functions: {
333
+ validators: {
334
+ id: sinon.stub().returns(undefined),
335
+ name: sinon.stub().returns(undefined),
336
+ },
337
+ },
338
+ }
339
+ const validator = createModelValidator(properties, [modelValidator])
340
+ await validator(
341
+ testModel3.create({
342
+ id: 'test-id',
343
+ name: 'my-name',
344
+ })
345
+ )
346
+ sinon.assert.calledOnce(modelValidator)
347
+ })
348
+ it('should pass the instance into the validator as the first argument', async () => {
349
+ const modelValidator = sinon.stub().returns(undefined)
350
+ const testModel3 = createTestModel3([modelValidator])
351
+ const properties = {
352
+ functions: {
353
+ validators: {
354
+ id: sinon.stub().returns(undefined),
355
+ name: sinon.stub().returns(undefined),
356
+ },
357
+ },
358
+ }
359
+ const validator = createModelValidator(properties, [modelValidator])
360
+ const instance = testModel3.create({
361
+ id: 'test-id',
362
+ name: 'my-name',
363
+ })
364
+ await validator(instance)
365
+
366
+ const actual = modelValidator.getCall(0).args[0]
367
+ const expected = instance
368
+ assert.deepEqual(actual, expected)
369
+ })
370
+ it('should pass the instance data into the validator as the second argument', async () => {
371
+ const modelValidator = sinon.stub().returns(undefined)
372
+ const testModel3 = createTestModel3([modelValidator])
373
+ const properties = {
374
+ functions: {
375
+ validators: {
376
+ id: sinon.stub().returns(undefined),
377
+ name: sinon.stub().returns(undefined),
378
+ },
379
+ },
380
+ }
381
+ const validator = createModelValidator(properties, [modelValidator])
382
+ const instance = testModel3.create({
383
+ id: 'test-id',
384
+ name: 'my-name',
385
+ })
386
+ const expected = await instance.functions.toObj()
387
+ await validator(instance)
388
+
389
+ const actual = modelValidator.getCall(0).args[1]
390
+ assert.deepEqual(actual, expected)
391
+ })
392
+ it('should return a overall: ["my-validation-error"] when the model validator returns "my-validation-error"', async () => {
393
+ const modelValidator = sinon.stub().returns('my-validation-error')
394
+ const testModel3 = createTestModel3([modelValidator])
395
+ const properties = {
396
+ functions: {
397
+ validators: {
398
+ id: sinon.stub().returns(undefined),
399
+ name: sinon.stub().returns(undefined),
400
+ },
401
+ },
402
+ }
403
+ const validator = createModelValidator(properties, [modelValidator])
404
+ const instance = testModel3.create({
405
+ id: 'test-id',
406
+ name: 'my-name',
407
+ })
408
+ const actual = await validator(instance)
409
+ const expected = {
410
+ overall: ['my-validation-error'],
411
+ }
412
+ assert.deepEqual(actual, expected)
413
+ })
414
+ it('should return no errors when two model validators return undefined', async () => {
415
+ const modelValidator1 = sinon.stub().resolves(undefined)
416
+ const modelValidator2 = sinon.stub().resolves(undefined)
417
+ const testModel3 = createTestModel3([modelValidator1, modelValidator2])
418
+ const properties = {
419
+ functions: {
420
+ validators: {
421
+ id: sinon.stub().returns(undefined),
422
+ name: sinon.stub().returns(undefined),
423
+ },
424
+ },
425
+ }
426
+ const validator = createModelValidator(properties, [
427
+ modelValidator1,
428
+ modelValidator2,
429
+ ])
430
+ const instance = testModel3.create({
431
+ id: 'test-id',
432
+ name: 'my-name',
433
+ })
434
+ const actual = await validator(instance)
435
+ const expected = {}
436
+ assert.deepEqual(actual, expected)
437
+ })
438
+ it('should use both functions.validate for two objects', async () => {
439
+ const propertys = {
440
+ functions: {
441
+ validators: {
442
+ id: sinon.stub().returns(undefined),
443
+ type: sinon.stub().returns(undefined),
444
+ },
445
+ },
446
+ }
447
+ const validator = createModelValidator(propertys)
448
+ const testModel3 = Model('Model', {})
449
+ const instance = testModel3.create({
450
+ id: 'test-id',
451
+ name: 'my-name',
452
+ })
453
+ await validator(instance)
454
+ sinon.assert.calledOnce(propertys.functions.validators.id)
455
+ sinon.assert.calledOnce(propertys.functions.validators.type)
456
+ })
457
+ it('should run a validators.model() function', async () => {
458
+ const propertys = {
459
+ functions: {
460
+ validators: {
461
+ id: sinon.stub().returns(undefined),
462
+ type: sinon.stub().returns(undefined),
463
+ model: sinon.stub().returns(undefined),
464
+ },
465
+ },
466
+ }
467
+ const validator = createModelValidator(propertys)
468
+ const testModel3 = Model('Model', {})
469
+ const instance = testModel3.create({
470
+ id: 'test-id',
471
+ name: 'my-name',
472
+ })
473
+ await validator(instance)
474
+ sinon.assert.called(propertys.functions.validators.model)
475
+ })
476
+ it('should combine results for both functions.validators for two objects that error', async () => {
477
+ const propertys = {
478
+ functions: {
479
+ validators: {
480
+ id: sinon.stub().returns('error1'),
481
+ type: sinon.stub().returns('error2'),
482
+ },
483
+ },
484
+ }
485
+ const validator = createModelValidator(propertys)
486
+ const testModel3 = Model('Model', {})
487
+ const instance = testModel3.create({
488
+ id: 'test-id',
489
+ type: 'my-name',
490
+ })
491
+ const actual = await validator(instance)
492
+ const expected = {
493
+ id: 'error1',
494
+ type: 'error2',
495
+ }
496
+ assert.deepEqual(actual, expected)
497
+ })
498
+ it('should take the error of the one of two functions', async () => {
499
+ const propertys = {
500
+ functions: {
501
+ validators: {
502
+ id: sinon.stub().returns(undefined),
503
+ type: sinon.stub().returns('error2'),
504
+ },
505
+ },
506
+ }
507
+ const validator = createModelValidator(propertys)
508
+ const testModel3 = Model('Model', {})
509
+ const instance = testModel3.create({
510
+ id: 'test-id',
511
+ type: 'my-name',
512
+ })
513
+ const actual = await validator(instance)
514
+ const expected = {
515
+ type: 'error2',
516
+ }
517
+ assert.deepEqual(actual, expected)
518
+ })
519
+ })
520
+ describe('#createPropertyValidator()', () => {
521
+ it('should not include isRequired if required=false, returning []', async () => {
522
+ const validator = createPropertyValidator({ required: false })
523
+ const actual = await validator(null)
524
+ const expected = []
525
+ assert.deepEqual(actual, expected)
526
+ })
527
+ it('should return [] if no configs are provided', async () => {
528
+ const validator = createPropertyValidator({})
529
+ const actual = await validator(null)
530
+ const expected = []
531
+ assert.deepEqual(actual, expected)
532
+ })
533
+ it('should use isRequired if required=false, returning one error', async () => {
534
+ const validator = createPropertyValidator({ required: true })
535
+ const actual = await validator(null)
536
+ const expected = 1
537
+ assert.equal(actual.length, expected)
538
+ })
539
+ it('should use validators.isRequired returning one error', async () => {
540
+ const validator = createPropertyValidator({ validators: [isRequired] })
541
+ const actual = await validator(null)
542
+ const expected = 1
543
+ assert.equal(actual.length, expected)
544
+ })
545
+ })
546
+ describe('#isArray()', () => {
547
+ it('should return an error for null', () => {
548
+ const actual = isArray(null)
549
+ assert.isOk(actual)
550
+ })
551
+ it('should return an error for undefined', () => {
552
+ const actual = isArray(undefined)
553
+ assert.isOk(actual)
554
+ })
555
+ it('should return an error for 1', () => {
556
+ const actual = isArray(1)
557
+ assert.isOk(actual)
558
+ })
559
+ it('should return an error for "1"', () => {
560
+ const actual = isArray('1')
561
+ assert.isOk(actual)
562
+ })
563
+ it('should return undefined for [1,2,3]', () => {
564
+ const actual = isArray([1, 2, 3])
565
+ assert.isUndefined(actual)
566
+ })
567
+ it('should return undefined for []', () => {
568
+ const actual = isArray([])
569
+ assert.isUndefined(actual)
570
+ })
571
+ })
572
+ describe('#arrayType()', () => {
573
+ describe('#(object)()', () => {
574
+ it('should return an error for null, even though its an object, its not an array', () => {
575
+ const actual = arrayType('object')(null)
576
+ assert.isOk(actual)
577
+ })
578
+ it('should return an error for 1', () => {
579
+ const actual = arrayType('object')(1)
580
+ assert.isOk(actual)
581
+ })
582
+ it('should return undefined for [{}]', () => {
583
+ const actual = arrayType('object')([{}])
584
+ assert.isUndefined(actual)
585
+ })
586
+ })
587
+ describe('#(integer)()', () => {
588
+ it('should return an error for null', () => {
589
+ const actual = arrayType(TYPE_PRIMATIVES.integer)(null)
590
+ assert.isOk(actual)
591
+ })
592
+ it('should return an error for undefined', () => {
593
+ const actual = arrayType(TYPE_PRIMATIVES.integer)(undefined)
594
+ assert.isOk(actual)
595
+ })
596
+ it('should return an error for 1', () => {
597
+ const actual = arrayType(TYPE_PRIMATIVES.integer)(1)
598
+ assert.isOk(actual)
599
+ })
600
+ it('should return an error for "1"', () => {
601
+ const actual = arrayType(TYPE_PRIMATIVES.integer)('1')
602
+ assert.isOk(actual)
603
+ })
604
+ it('should return undefined for [1,2,3]', () => {
605
+ const actual = arrayType(TYPE_PRIMATIVES.integer)([1, 2, 3])
606
+ assert.isUndefined(actual)
607
+ })
608
+ it('should return an error for [1,"2",3]', () => {
609
+ const actual = arrayType(TYPE_PRIMATIVES.integer)([1, '2', 3])
610
+ assert.isOk(actual)
611
+ })
612
+ })
613
+ })
614
+ })
package/constants.d.ts DELETED
@@ -1,14 +0,0 @@
1
- declare enum PROPERTY_TYPES {
2
- UniqueId = "UniqueId",
3
- DateProperty = "DateProperty",
4
- ArrayProperty = "ArrayProperty",
5
- ReferenceProperty = "ReferenceProperty",
6
- IntegerProperty = "IntegerProperty",
7
- TextProperty = "TextProperty",
8
- ConstantValueProperty = "ConstantValueProperty",
9
- NumberProperty = "NumberProperty",
10
- ObjectProperty = "ObjectProperty",
11
- EmailProperty = "EmailProperty",
12
- BooleanProperty = "BooleanProperty"
13
- }
14
- export { PROPERTY_TYPES };
package/constants.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROPERTY_TYPES = void 0;
4
- var PROPERTY_TYPES;
5
- (function (PROPERTY_TYPES) {
6
- PROPERTY_TYPES["UniqueId"] = "UniqueId";
7
- PROPERTY_TYPES["DateProperty"] = "DateProperty";
8
- PROPERTY_TYPES["ArrayProperty"] = "ArrayProperty";
9
- PROPERTY_TYPES["ReferenceProperty"] = "ReferenceProperty";
10
- PROPERTY_TYPES["IntegerProperty"] = "IntegerProperty";
11
- PROPERTY_TYPES["TextProperty"] = "TextProperty";
12
- PROPERTY_TYPES["ConstantValueProperty"] = "ConstantValueProperty";
13
- PROPERTY_TYPES["NumberProperty"] = "NumberProperty";
14
- PROPERTY_TYPES["ObjectProperty"] = "ObjectProperty";
15
- PROPERTY_TYPES["EmailProperty"] = "EmailProperty";
16
- PROPERTY_TYPES["BooleanProperty"] = "BooleanProperty";
17
- })(PROPERTY_TYPES || (PROPERTY_TYPES = {}));
18
- exports.PROPERTY_TYPES = PROPERTY_TYPES;
19
- //# sourceMappingURL=constants.js.map