functional-models 1.0.27 → 1.1.2

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 (105) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +9 -15
  3. package/cucumber.js +10 -0
  4. package/dist/src/constants.d.ts +14 -0
  5. package/dist/src/constants.js +19 -0
  6. package/dist/src/constants.js.map +1 -0
  7. package/dist/src/errors.d.ts +9 -0
  8. package/dist/src/errors.js +15 -0
  9. package/dist/src/errors.js.map +1 -0
  10. package/dist/src/index.d.ts +9 -0
  11. package/dist/src/index.js +39 -0
  12. package/dist/src/index.js.map +1 -0
  13. package/dist/src/interfaces.d.ts +145 -0
  14. package/dist/src/interfaces.js +5 -0
  15. package/dist/src/interfaces.js.map +1 -0
  16. package/dist/src/lazy.d.ts +2 -0
  17. package/dist/src/lazy.js +37 -0
  18. package/dist/src/lazy.js.map +1 -0
  19. package/dist/src/methods.d.ts +4 -0
  20. package/dist/src/methods.js +18 -0
  21. package/dist/src/methods.js.map +1 -0
  22. package/dist/src/models.d.ts +3 -0
  23. package/dist/src/models.js +128 -0
  24. package/dist/src/models.js.map +1 -0
  25. package/dist/src/properties.d.ts +16 -0
  26. package/dist/src/properties.js +208 -0
  27. package/dist/src/properties.js.map +1 -0
  28. package/dist/src/serialization.d.ts +3 -0
  29. package/dist/src/serialization.js +49 -0
  30. package/dist/src/serialization.js.map +1 -0
  31. package/dist/src/utils.d.ts +4 -0
  32. package/dist/src/utils.js +44 -0
  33. package/dist/src/utils.js.map +1 -0
  34. package/dist/src/validation.d.ts +29 -0
  35. package/dist/src/validation.js +286 -0
  36. package/dist/src/validation.js.map +1 -0
  37. package/dist/stepDefinitions/oldSteps.d.ts +1 -0
  38. package/dist/stepDefinitions/oldSteps.js +191 -0
  39. package/dist/stepDefinitions/oldSteps.js.map +1 -0
  40. package/dist/stepDefinitions/tssteps.d.ts +1 -0
  41. package/dist/stepDefinitions/tssteps.js +96 -0
  42. package/dist/stepDefinitions/tssteps.js.map +1 -0
  43. package/dist/test/src/errors.test.d.ts +1 -0
  44. package/dist/test/src/errors.test.js +33 -0
  45. package/dist/test/src/errors.test.js.map +1 -0
  46. package/dist/test/src/lazy.test.d.ts +1 -0
  47. package/dist/test/src/lazy.test.js +28 -0
  48. package/dist/test/src/lazy.test.js.map +1 -0
  49. package/dist/test/src/methods.test.d.ts +1 -0
  50. package/dist/test/src/methods.test.js +48 -0
  51. package/dist/test/src/methods.test.js.map +1 -0
  52. package/dist/test/src/models.test.d.ts +1 -0
  53. package/dist/test/src/models.test.js +395 -0
  54. package/dist/test/src/models.test.js.map +1 -0
  55. package/dist/test/src/properties.test.d.ts +1 -0
  56. package/dist/test/src/properties.test.js +724 -0
  57. package/dist/test/src/properties.test.js.map +1 -0
  58. package/dist/test/src/serialization.test.d.ts +1 -0
  59. package/dist/test/src/serialization.test.js +91 -0
  60. package/dist/test/src/serialization.test.js.map +1 -0
  61. package/dist/test/src/utils.test.d.ts +1 -0
  62. package/dist/test/src/utils.test.js +81 -0
  63. package/dist/test/src/utils.test.js.map +1 -0
  64. package/dist/test/src/validation.test.d.ts +1 -0
  65. package/dist/test/src/validation.test.js +612 -0
  66. package/dist/test/src/validation.test.js.map +1 -0
  67. package/features/arrayFields.feature +7 -7
  68. package/features/basic-ts.feature +13 -0
  69. package/features/functions.feature +2 -3
  70. package/package.json +35 -10
  71. package/src/constants.ts +15 -0
  72. package/src/{errors.js → errors.ts} +6 -4
  73. package/src/index.ts +12 -0
  74. package/src/interfaces.ts +323 -0
  75. package/src/lazy.ts +24 -0
  76. package/src/methods.ts +30 -0
  77. package/src/models.ts +183 -0
  78. package/src/properties.ts +375 -0
  79. package/src/serialization.ts +39 -0
  80. package/src/{utils.js → utils.ts} +16 -26
  81. package/src/validation.ts +390 -0
  82. package/{features/stepDefinitions/steps.js → stepDefinitions/oldSteps.ts} +76 -53
  83. package/stepDefinitions/tssteps.ts +107 -0
  84. package/test/src/errors.test.ts +31 -0
  85. package/test/src/{lazy.test.js → lazy.test.ts} +4 -4
  86. package/test/src/methods.test.ts +45 -0
  87. package/test/src/models.test.ts +417 -0
  88. package/test/src/{properties.test.js → properties.test.ts} +251 -58
  89. package/test/src/serialization.test.ts +80 -0
  90. package/test/src/{utils.test.js → utils.test.ts} +29 -7
  91. package/test/src/{validation.test.js → validation.test.ts} +278 -210
  92. package/tsconfig.json +100 -0
  93. package/src/constants.js +0 -19
  94. package/src/functions.js +0 -7
  95. package/src/index.js +0 -10
  96. package/src/lazy.js +0 -19
  97. package/src/models.js +0 -152
  98. package/src/properties.js +0 -313
  99. package/src/serialization.js +0 -50
  100. package/src/validation.js +0 -285
  101. package/test/base/index.test.js +0 -5
  102. package/test/src/functions.test.js +0 -45
  103. package/test/src/index.test.js +0 -5
  104. package/test/src/models.test.js +0 -380
  105. package/test/src/serialization.test.js +0 -127
@@ -0,0 +1,80 @@
1
+ import { assert } from 'chai'
2
+ import { toJsonAble } from '../../src/serialization'
3
+
4
+ describe('/src/serialization.ts', () => {
5
+ describe('#toObj()', () => {
6
+ it('serialize a very basic input of key-value', async () => {
7
+ const actual = await toJsonAble({
8
+ key: () => 'value',
9
+ key2: () => 'value2',
10
+ })()
11
+ const expected = {
12
+ key: 'value',
13
+ key2: 'value2',
14
+ }
15
+ assert.deepEqual(actual, expected)
16
+ })
17
+ it('should call "toObj" on nested objects', async () => {
18
+ const actual = await toJsonAble({
19
+ key: () => 'value',
20
+ key2: () => ({
21
+ get: { complex: () => ({ func: 'func' }) },
22
+ toObj: () => ({ func: 'value' }),
23
+ }),
24
+ })()
25
+ const expected = {
26
+ key: 'value',
27
+ key2: {
28
+ func: 'value',
29
+ },
30
+ }
31
+ assert.deepEqual(actual, expected)
32
+ })
33
+ it('should call "toObj" on very nested objects', async () => {
34
+ const actual = await toJsonAble({
35
+ key: () => 'value',
36
+ key2: () => ({
37
+ toObj: () => ({ func: 'value' }),
38
+ }),
39
+ })()
40
+ const expected = {
41
+ key: 'value',
42
+ key2: {
43
+ func: 'value',
44
+ },
45
+ }
46
+ assert.deepEqual(actual, expected)
47
+ })
48
+ it('should set an undefined property to null', async () => {
49
+ const actual = await toJsonAble({
50
+ key: () => 'value',
51
+ key2: () => undefined,
52
+ })()
53
+ const expected = {
54
+ key: 'value',
55
+ key2: null,
56
+ }
57
+ assert.deepEqual(actual, expected)
58
+ })
59
+ it('should use the value null for null', async () => {
60
+ const actual = await toJsonAble({
61
+ key: () => 'value',
62
+ key2: () => null,
63
+ })()
64
+ const expected = {
65
+ key: 'value',
66
+ key2: null,
67
+ }
68
+ assert.deepEqual(actual, expected)
69
+ })
70
+ it('should return "2021-09-16T21:51:56.039Z" for the set date.', async () => {
71
+ const actual = await toJsonAble({
72
+ myDate: () => new Date('2021-09-16T21:51:56.039Z'),
73
+ })()
74
+ const expected = {
75
+ myDate: '2021-09-16T21:51:56.039Z',
76
+ }
77
+ assert.deepEqual(actual, expected)
78
+ })
79
+ })
80
+ })
@@ -1,9 +1,17 @@
1
- const assert = require('chai').assert
2
- const sinon = require('sinon')
3
- const proxyquire = require('proxyquire')
4
- const { loweredTitleCase, createUuid } = require('../../src/utils')
1
+ import { assert } from 'chai'
2
+ import sinon from 'sinon'
3
+ import proxyquire from 'proxyquire'
4
+ import { loweredTitleCase, createUuid, toTitleCase } from '../../src/utils'
5
5
 
6
- describe('/src/utils.js', () => {
6
+ describe('/src/utils.ts', () => {
7
+ describe('#toTitleCase()', () => {
8
+ it('should make camelCase into CamelCase', () => {
9
+ const input = 'camelCase'
10
+ const actual = toTitleCase(input)
11
+ const expected = 'CamelCase'
12
+ assert.equal(actual, expected)
13
+ })
14
+ })
7
15
  describe('#loweredTitleCase()', () => {
8
16
  it('should turn TitleCase into titleCase', () => {
9
17
  const actual = loweredTitleCase('TitleCase')
@@ -13,10 +21,12 @@ describe('/src/utils.js', () => {
13
21
  })
14
22
  describe('#createUuid()', () => {
15
23
  before(() => {
16
- window = undefined
24
+ // @ts-ignore
25
+ globalThis.global.window = undefined
17
26
  })
18
27
  after(() => {
19
- window = undefined
28
+ // @ts-ignore
29
+ globalThis.global.window = undefined
20
30
  })
21
31
  describe('when not having access to "window"', () => {
22
32
  it('should call get-random-values 31 times with hello-crypto', () => {
@@ -32,6 +42,7 @@ describe('/src/utils.js', () => {
32
42
  it('should call window.crypto when it exists 31 times with hello-crypto', () => {
33
43
  const getRandomValues = sinon.stub().returns('hello-crypto')
34
44
  window = {
45
+ // @ts-ignore
35
46
  crypto: {
36
47
  getRandomValues,
37
48
  },
@@ -42,6 +53,7 @@ describe('/src/utils.js', () => {
42
53
  it('should call window.myCrypto when it exists 31 times with hello-crypto', () => {
43
54
  const getRandomValues = sinon.stub().returns('hello-crypto')
44
55
  window = {
56
+ // @ts-ignore
45
57
  msCrypto: {
46
58
  getRandomValues,
47
59
  },
@@ -49,6 +61,16 @@ describe('/src/utils.js', () => {
49
61
  const actual = createUuid()
50
62
  sinon.assert.callCount(getRandomValues, 31)
51
63
  })
64
+ it('should call get-random-values 31 times with hello-crypto if crypto and msCrypto are not available', () => {
65
+ const getRandomValues = sinon.stub().returns('hello-crypto')
66
+ // @ts-ignore
67
+ window = {}
68
+ const utils = proxyquire('../../src/utils', {
69
+ 'get-random-values': getRandomValues,
70
+ })
71
+ const actual = utils.createUuid()
72
+ sinon.assert.callCount(getRandomValues, 31)
73
+ })
52
74
  })
53
75
  })
54
76
  })