functional-models 1.1.3 → 1.1.4
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.
- package/package.json +5 -4
- package/{dist/src → src}/constants.d.ts +0 -0
- package/{dist/src → src}/constants.js +0 -0
- package/{dist/src → src}/constants.js.map +0 -0
- package/{dist/src → src}/errors.d.ts +0 -0
- package/{dist/src → src}/errors.js +0 -0
- package/{dist/src → src}/errors.js.map +0 -0
- package/{dist/src → src}/index.d.ts +0 -0
- package/{dist/src → src}/index.js +0 -0
- package/{dist/src → src}/index.js.map +0 -0
- package/{dist/src → src}/interfaces.d.ts +0 -0
- package/{dist/src → src}/interfaces.js +0 -0
- package/{dist/src → src}/interfaces.js.map +0 -0
- package/{dist/src → src}/lazy.d.ts +0 -0
- package/{dist/src → src}/lazy.js +0 -0
- package/{dist/src → src}/lazy.js.map +0 -0
- package/{dist/src → src}/methods.d.ts +0 -0
- package/{dist/src → src}/methods.js +0 -0
- package/{dist/src → src}/methods.js.map +0 -0
- package/{dist/src → src}/models.d.ts +0 -0
- package/{dist/src → src}/models.js +0 -0
- package/{dist/src → src}/models.js.map +0 -0
- package/{dist/src → src}/properties.d.ts +0 -0
- package/{dist/src → src}/properties.js +0 -0
- package/{dist/src → src}/properties.js.map +0 -0
- package/{dist/src → src}/serialization.d.ts +0 -0
- package/{dist/src → src}/serialization.js +0 -0
- package/{dist/src → src}/serialization.js.map +0 -0
- package/{dist/src → src}/utils.d.ts +0 -0
- package/{dist/src → src}/utils.js +0 -0
- package/{dist/src → src}/utils.js.map +0 -0
- package/{dist/src → src}/validation.d.ts +0 -0
- package/{dist/src → src}/validation.js +0 -0
- package/{dist/src → src}/validation.js.map +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/oldSteps.d.ts +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/oldSteps.js +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/oldSteps.js.map +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/tssteps.d.ts +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/tssteps.js +0 -0
- package/{dist/stepDefinitions → stepDefinitions}/tssteps.js.map +0 -0
- package/{dist/test → test}/src/errors.test.d.ts +0 -0
- package/{dist/test → test}/src/errors.test.js +0 -0
- package/{dist/test → test}/src/errors.test.js.map +0 -0
- package/{dist/test/src/lazy.test.d.ts → test/src/index.test.d.ts} +0 -0
- package/test/src/index.test.js +3 -0
- package/test/src/index.test.js.map +1 -0
- package/{dist/test/src/methods.test.d.ts → test/src/lazy.test.d.ts} +0 -0
- package/{dist/test → test}/src/lazy.test.js +0 -0
- package/{dist/test → test}/src/lazy.test.js.map +0 -0
- package/{dist/test/src/models.test.d.ts → test/src/methods.test.d.ts} +0 -0
- package/{dist/test → test}/src/methods.test.js +0 -0
- package/{dist/test → test}/src/methods.test.js.map +0 -0
- package/{dist/test/src/properties.test.d.ts → test/src/models.test.d.ts} +0 -0
- package/{dist/test → test}/src/models.test.js +0 -0
- package/{dist/test → test}/src/models.test.js.map +0 -0
- package/{dist/test/src/serialization.test.d.ts → test/src/properties.test.d.ts} +0 -0
- package/{dist/test → test}/src/properties.test.js +0 -0
- package/{dist/test → test}/src/properties.test.js.map +0 -0
- package/{dist/test/src/utils.test.d.ts → test/src/serialization.test.d.ts} +0 -0
- package/{dist/test → test}/src/serialization.test.js +0 -0
- package/{dist/test → test}/src/serialization.test.js.map +0 -0
- package/{dist/test/src/validation.test.d.ts → test/src/utils.test.d.ts} +0 -0
- package/{dist/test → test}/src/utils.test.js +0 -0
- package/{dist/test → test}/src/utils.test.js.map +0 -0
- package/test/src/validation.test.d.ts +1 -0
- package/{dist/test → test}/src/validation.test.js +0 -0
- package/{dist/test → test}/src/validation.test.js.map +0 -0
- package/.eslintignore +0 -5
- package/.eslintrc +0 -180
- package/.github/workflows/feature.yml +0 -26
- package/.github/workflows/ut.yml +0 -32
- package/.prettierignore +0 -7
- package/.prettierrc.json +0 -14
- package/LICENSE +0 -674
- package/cucumber.js +0 -10
- package/features/arrayFields.feature +0 -52
- package/features/basic-ts.feature +0 -13
- package/features/functions.feature +0 -10
- package/features/model.feature +0 -7
- package/features/validation.feature +0 -12
- package/index.js +0 -1
- package/src/constants.ts +0 -15
- package/src/errors.ts +0 -18
- package/src/index.ts +0 -12
- package/src/interfaces.ts +0 -323
- package/src/lazy.ts +0 -24
- package/src/methods.ts +0 -30
- package/src/models.ts +0 -183
- package/src/properties.ts +0 -375
- package/src/serialization.ts +0 -39
- package/src/utils.ts +0 -42
- package/src/validation.ts +0 -390
- package/stepDefinitions/oldSteps.ts +0 -216
- package/stepDefinitions/tssteps.ts +0 -107
- package/test/src/errors.test.ts +0 -31
- package/test/src/lazy.test.ts +0 -15
- package/test/src/methods.test.ts +0 -45
- package/test/src/models.test.ts +0 -417
- package/test/src/properties.test.ts +0 -747
- package/test/src/serialization.test.ts +0 -80
- package/test/src/utils.test.ts +0 -76
- package/test/src/validation.test.ts +0 -682
- package/tsconfig.json +0 -100
|
@@ -1,747 +0,0 @@
|
|
|
1
|
-
import { assert } from 'chai'
|
|
2
|
-
import sinon from 'sinon'
|
|
3
|
-
import {
|
|
4
|
-
UniqueId,
|
|
5
|
-
Property,
|
|
6
|
-
DateProperty,
|
|
7
|
-
BooleanProperty,
|
|
8
|
-
ReferenceProperty,
|
|
9
|
-
ArrayProperty,
|
|
10
|
-
ConstantValueProperty,
|
|
11
|
-
ObjectProperty,
|
|
12
|
-
NumberProperty,
|
|
13
|
-
TextProperty,
|
|
14
|
-
IntegerProperty,
|
|
15
|
-
EmailProperty,
|
|
16
|
-
} from '../../src/properties'
|
|
17
|
-
import { TYPE_PRIMITIVES, arrayType } from '../../src/validation'
|
|
18
|
-
import { BaseModel } from '../../src/models'
|
|
19
|
-
import { ModelInstance } from '../../src/interfaces'
|
|
20
|
-
|
|
21
|
-
type TestModelType = { name: string }
|
|
22
|
-
const TestModel1 = BaseModel<TestModelType>('TestModel1', {
|
|
23
|
-
properties: {
|
|
24
|
-
name: TextProperty(),
|
|
25
|
-
},
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('/src/properties.ts', () => {
|
|
29
|
-
describe('#EmailProperty()', () => {
|
|
30
|
-
describe('#createGetter()', () => {
|
|
31
|
-
it('should be able to create without a config', () => {
|
|
32
|
-
assert.doesNotThrow(() => {
|
|
33
|
-
EmailProperty()
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
it('should always have the value passed in', async () => {
|
|
37
|
-
const PropertyInstance = EmailProperty({})
|
|
38
|
-
const getter = PropertyInstance.createGetter('testme@email.com')
|
|
39
|
-
const actual = await getter()
|
|
40
|
-
const expected = 'testme@email.com'
|
|
41
|
-
assert.deepEqual(actual, expected)
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
describe('#getValidator()', () => {
|
|
45
|
-
it('should return and validate successful with basic input', async () => {
|
|
46
|
-
const PropertyInstance = EmailProperty({})
|
|
47
|
-
const getter = PropertyInstance.createGetter('testme@email.com')
|
|
48
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
const actual = await validator(null, {})
|
|
51
|
-
const expected = 0
|
|
52
|
-
assert.equal(actual.length, expected)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
describe('#BooleanProperty()', () => {
|
|
57
|
-
it('should be able to create without a config', () => {
|
|
58
|
-
assert.doesNotThrow(() => {
|
|
59
|
-
BooleanProperty()
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
describe('#getValidator()', () => {
|
|
63
|
-
it('should return and validate successful with basic input', async () => {
|
|
64
|
-
const PropertyInstance = BooleanProperty({})
|
|
65
|
-
const getter = PropertyInstance.createGetter(true)
|
|
66
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
const actual = await validator(null, {})
|
|
69
|
-
const expected = 0
|
|
70
|
-
assert.equal(actual.length, expected)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
describe('#ConstantValueProperty()', () => {
|
|
75
|
-
describe('#createGetter()', () => {
|
|
76
|
-
it('should always have the value passed in', async () => {
|
|
77
|
-
const PropertyInstance = ConstantValueProperty('constant')
|
|
78
|
-
const getter = PropertyInstance.createGetter('changed')
|
|
79
|
-
const actual = await getter()
|
|
80
|
-
const expected = 'constant'
|
|
81
|
-
assert.deepEqual(actual, expected)
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
describe('#getValidator()', () => {
|
|
85
|
-
it('should return and validate successful with basic input', async () => {
|
|
86
|
-
const PropertyInstance = ConstantValueProperty('constant')
|
|
87
|
-
const getter = PropertyInstance.createGetter('changed')
|
|
88
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
const actual = await validator(null, {})
|
|
91
|
-
const expected = 0
|
|
92
|
-
assert.equal(actual.length, expected)
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
describe('#ObjectProperty()', () => {
|
|
97
|
-
describe('#createGetter()', () => {
|
|
98
|
-
it('should be able to create without a config', () => {
|
|
99
|
-
assert.doesNotThrow(() => {
|
|
100
|
-
ObjectProperty()
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
it('should be able to get the object passed in', async () => {
|
|
104
|
-
const PropertyInstance = ObjectProperty({})
|
|
105
|
-
const getter = PropertyInstance.createGetter({
|
|
106
|
-
my: 'object',
|
|
107
|
-
complex: { it: 'is' },
|
|
108
|
-
})
|
|
109
|
-
const actual = await getter()
|
|
110
|
-
const expected = { my: 'object', complex: { it: 'is' } }
|
|
111
|
-
assert.deepEqual(actual, expected)
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
describe('#getValidator()', () => {
|
|
115
|
-
it('should return and validate successful with basic input', async () => {
|
|
116
|
-
const PropertyInstance = ObjectProperty({})
|
|
117
|
-
const getter = PropertyInstance.createGetter({
|
|
118
|
-
my: 'object',
|
|
119
|
-
complex: { it: 'is' },
|
|
120
|
-
})
|
|
121
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
const actual = await validator(null, {})
|
|
124
|
-
const expected = 0
|
|
125
|
-
assert.equal(actual.length, expected)
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
describe('#NumberProperty()', () => {
|
|
131
|
-
describe('#createGetter()', () => {
|
|
132
|
-
it('should be able to create without a config', () => {
|
|
133
|
-
assert.doesNotThrow(() => {
|
|
134
|
-
NumberProperty()
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
it('should be able to create even with a null config', () => {
|
|
138
|
-
assert.doesNotThrow(() => {
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
NumberProperty(null)
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
it('should be able to get the number passed in', async () => {
|
|
144
|
-
const PropertyInstance = NumberProperty({})
|
|
145
|
-
const getter = PropertyInstance.createGetter(5)
|
|
146
|
-
const actual = await getter()
|
|
147
|
-
const expected = 5
|
|
148
|
-
assert.equal(actual, expected)
|
|
149
|
-
})
|
|
150
|
-
it('should be able to get float passed in', async () => {
|
|
151
|
-
const PropertyInstance = NumberProperty({})
|
|
152
|
-
const getter = PropertyInstance.createGetter(5.123)
|
|
153
|
-
const actual = await getter()
|
|
154
|
-
const expected = 5.123
|
|
155
|
-
assert.equal(actual, expected)
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
describe('#getValidator()', () => {
|
|
159
|
-
it('should return and validate successful with basic input', async () => {
|
|
160
|
-
const PropertyInstance = NumberProperty({})
|
|
161
|
-
const getter = PropertyInstance.createGetter(5)
|
|
162
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
const actual = await validator(null, {})
|
|
165
|
-
const expected = 0
|
|
166
|
-
assert.equal(actual.length, expected)
|
|
167
|
-
})
|
|
168
|
-
it('should return and validate successful with a basic float', async () => {
|
|
169
|
-
const PropertyInstance = NumberProperty({})
|
|
170
|
-
const getter = PropertyInstance.createGetter(5.123)
|
|
171
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
const actual = await validator(null, {})
|
|
174
|
-
const expected = 0
|
|
175
|
-
assert.equal(actual.length, expected)
|
|
176
|
-
})
|
|
177
|
-
it('should return with errors with a non integer input', async () => {
|
|
178
|
-
const PropertyInstance = NumberProperty({})
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
const getter = PropertyInstance.createGetter('string')
|
|
181
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
const actual = await validator(null, {})
|
|
184
|
-
const expected = 1
|
|
185
|
-
assert.equal(actual.length, expected)
|
|
186
|
-
})
|
|
187
|
-
it('should return with errors with a value=5 and maxValue=3', async () => {
|
|
188
|
-
const PropertyInstance = NumberProperty({ maxValue: 3 })
|
|
189
|
-
const getter = PropertyInstance.createGetter(5)
|
|
190
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
const actual = await validator()
|
|
193
|
-
const expected = 1
|
|
194
|
-
assert.equal(actual.length, expected)
|
|
195
|
-
})
|
|
196
|
-
it('should return with errors with a value=2 and minValue=3', async () => {
|
|
197
|
-
const PropertyInstance = NumberProperty({ minValue: 3 })
|
|
198
|
-
const getter = PropertyInstance.createGetter(2)
|
|
199
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
200
|
-
// @ts-ignore
|
|
201
|
-
const actual = await validator()
|
|
202
|
-
const expected = 1
|
|
203
|
-
assert.equal(actual.length, expected)
|
|
204
|
-
})
|
|
205
|
-
it('should return with no errors with a value=3 and minValue=3 and maxValue=3', async () => {
|
|
206
|
-
const PropertyInstance = NumberProperty({ minValue: 3, maxValue: 3 })
|
|
207
|
-
const getter = PropertyInstance.createGetter(3)
|
|
208
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
209
|
-
// @ts-ignore
|
|
210
|
-
const actual = await validator()
|
|
211
|
-
const expected = 0
|
|
212
|
-
assert.equal(actual.length, expected)
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
describe('#IntegerProperty()', () => {
|
|
218
|
-
it('should be able to create even with a null config', () => {
|
|
219
|
-
assert.doesNotThrow(() => {
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
IntegerProperty(null)
|
|
222
|
-
})
|
|
223
|
-
})
|
|
224
|
-
describe('#createGetter()', () => {
|
|
225
|
-
it('should be able to create without a config', () => {
|
|
226
|
-
assert.doesNotThrow(() => {
|
|
227
|
-
IntegerProperty()
|
|
228
|
-
})
|
|
229
|
-
})
|
|
230
|
-
it('should be able to get the number passed in', async () => {
|
|
231
|
-
const PropertyInstance = IntegerProperty({})
|
|
232
|
-
const getter = PropertyInstance.createGetter(5)
|
|
233
|
-
const actual = await getter()
|
|
234
|
-
const expected = 5
|
|
235
|
-
assert.equal(actual, expected)
|
|
236
|
-
})
|
|
237
|
-
})
|
|
238
|
-
describe('#getValidator()', () => {
|
|
239
|
-
it('should return and validate successful with basic input', async () => {
|
|
240
|
-
const PropertyInstance = IntegerProperty({})
|
|
241
|
-
const getter = PropertyInstance.createGetter(5)
|
|
242
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
const actual = await validator()
|
|
245
|
-
const expected = 0
|
|
246
|
-
assert.equal(actual.length, expected)
|
|
247
|
-
})
|
|
248
|
-
it('should return errors with a basic float', async () => {
|
|
249
|
-
const PropertyInstance = IntegerProperty({})
|
|
250
|
-
const getter = PropertyInstance.createGetter(5.123)
|
|
251
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
const actual = await validator()
|
|
254
|
-
const expected = 1
|
|
255
|
-
assert.equal(actual.length, expected)
|
|
256
|
-
})
|
|
257
|
-
it('should return with errors with a non integer input', async () => {
|
|
258
|
-
const PropertyInstance = IntegerProperty({})
|
|
259
|
-
// @ts-ignore
|
|
260
|
-
const getter = PropertyInstance.createGetter('string')
|
|
261
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
262
|
-
// @ts-ignore
|
|
263
|
-
const actual = await validator()
|
|
264
|
-
const expected = 1
|
|
265
|
-
assert.equal(actual.length, expected)
|
|
266
|
-
})
|
|
267
|
-
it('should return with errors with a value=5 and maxValue=3', async () => {
|
|
268
|
-
const PropertyInstance = IntegerProperty({ maxValue: 3 })
|
|
269
|
-
const getter = PropertyInstance.createGetter(5)
|
|
270
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
271
|
-
// @ts-ignore
|
|
272
|
-
const actual = await validator()
|
|
273
|
-
const expected = 1
|
|
274
|
-
assert.equal(actual.length, expected)
|
|
275
|
-
})
|
|
276
|
-
it('should return with errors with a value=2 and minValue=3', async () => {
|
|
277
|
-
const PropertyInstance = IntegerProperty({ minValue: 3 })
|
|
278
|
-
const getter = PropertyInstance.createGetter(2)
|
|
279
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
280
|
-
// @ts-ignore
|
|
281
|
-
const actual = await validator()
|
|
282
|
-
const expected = 1
|
|
283
|
-
assert.equal(actual.length, expected)
|
|
284
|
-
})
|
|
285
|
-
it('should return with no errors with a value=3 and minValue=3 and maxValue=3', async () => {
|
|
286
|
-
const PropertyInstance = IntegerProperty({ minValue: 3, maxValue: 3 })
|
|
287
|
-
const getter = PropertyInstance.createGetter(3)
|
|
288
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
289
|
-
// @ts-ignore
|
|
290
|
-
const actual = await validator()
|
|
291
|
-
const expected = 0
|
|
292
|
-
assert.equal(actual.length, expected)
|
|
293
|
-
})
|
|
294
|
-
})
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
describe('#TextProperty()', () => {
|
|
298
|
-
it('should be able to create even with a null config', () => {
|
|
299
|
-
assert.doesNotThrow(() => {
|
|
300
|
-
// @ts-ignore
|
|
301
|
-
TextProperty(null)
|
|
302
|
-
})
|
|
303
|
-
})
|
|
304
|
-
describe('#createGetter()', () => {
|
|
305
|
-
it('should be able to create without a config', () => {
|
|
306
|
-
assert.doesNotThrow(() => {
|
|
307
|
-
TextProperty()
|
|
308
|
-
})
|
|
309
|
-
})
|
|
310
|
-
it('should be able to get the value passed in', async () => {
|
|
311
|
-
const PropertyInstance = TextProperty({})
|
|
312
|
-
const getter = PropertyInstance.createGetter('basic input')
|
|
313
|
-
const actual = await getter()
|
|
314
|
-
const expected = 'basic input'
|
|
315
|
-
assert.equal(actual, expected)
|
|
316
|
-
})
|
|
317
|
-
})
|
|
318
|
-
describe('#getValidator()', () => {
|
|
319
|
-
it('should return and validate successful with basic input', async () => {
|
|
320
|
-
const PropertyInstance = TextProperty({})
|
|
321
|
-
const getter = PropertyInstance.createGetter('basic input')
|
|
322
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
323
|
-
// @ts-ignore
|
|
324
|
-
const actual = await validator()
|
|
325
|
-
const expected = 0
|
|
326
|
-
assert.equal(actual.length, expected)
|
|
327
|
-
})
|
|
328
|
-
it('should return with errors with a value=5', async () => {
|
|
329
|
-
const PropertyInstance = TextProperty({})
|
|
330
|
-
// @ts-ignore
|
|
331
|
-
const getter = PropertyInstance.createGetter(5)
|
|
332
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
333
|
-
// @ts-ignore
|
|
334
|
-
const actual = await validator()
|
|
335
|
-
const expected = 1
|
|
336
|
-
assert.equal(actual.length, expected)
|
|
337
|
-
})
|
|
338
|
-
it('should return with errors with a value="hello" and maxLength=3', async () => {
|
|
339
|
-
const PropertyInstance = TextProperty({ maxLength: 3 })
|
|
340
|
-
const getter = PropertyInstance.createGetter('hello')
|
|
341
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
342
|
-
// @ts-ignore
|
|
343
|
-
const actual = await validator()
|
|
344
|
-
const expected = 1
|
|
345
|
-
assert.equal(actual.length, expected)
|
|
346
|
-
})
|
|
347
|
-
it('should return with errors with a value="hello" and minLength=10', async () => {
|
|
348
|
-
const PropertyInstance = TextProperty({ minLength: 10 })
|
|
349
|
-
const getter = PropertyInstance.createGetter('hello')
|
|
350
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
351
|
-
// @ts-ignore
|
|
352
|
-
const actual = await validator()
|
|
353
|
-
const expected = 1
|
|
354
|
-
assert.equal(actual.length, expected)
|
|
355
|
-
})
|
|
356
|
-
it('should return with no errors with a value="hello" and minLength=5 and maxLength=5', async () => {
|
|
357
|
-
const PropertyInstance = TextProperty({ minLength: 5, maxLength: 5 })
|
|
358
|
-
const getter = PropertyInstance.createGetter('hello')
|
|
359
|
-
const validator = PropertyInstance.getValidator(getter)
|
|
360
|
-
// @ts-ignore
|
|
361
|
-
const actual = await validator()
|
|
362
|
-
const expected = 0
|
|
363
|
-
assert.equal(actual.length, expected)
|
|
364
|
-
})
|
|
365
|
-
})
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
describe('#ArrayProperty()', () => {
|
|
369
|
-
describe('#createGetter()', () => {
|
|
370
|
-
it('should return an array passed in without issue', async () => {
|
|
371
|
-
const theProperty = ArrayProperty({})
|
|
372
|
-
const getter = theProperty.createGetter([1, 2, 3])
|
|
373
|
-
const actual = await getter()
|
|
374
|
-
const expected = [1, 2, 3]
|
|
375
|
-
assert.deepEqual(actual, expected)
|
|
376
|
-
})
|
|
377
|
-
it('should return an array passed in without issue, even if no config is passed', async () => {
|
|
378
|
-
const theProperty = ArrayProperty()
|
|
379
|
-
const getter = theProperty.createGetter([1, 2, 3])
|
|
380
|
-
const actual = await getter()
|
|
381
|
-
const expected = [1, 2, 3]
|
|
382
|
-
assert.deepEqual(actual, expected)
|
|
383
|
-
})
|
|
384
|
-
it('should return an empty array if defaultValue is not changed in config and null is passed', async () => {
|
|
385
|
-
const theProperty = ArrayProperty()
|
|
386
|
-
// @ts-ignore
|
|
387
|
-
const getter = theProperty.createGetter(null)
|
|
388
|
-
const actual = await getter()
|
|
389
|
-
const expected: any[] = []
|
|
390
|
-
assert.deepEqual(actual, expected)
|
|
391
|
-
})
|
|
392
|
-
it('should return the passed in defaultValue if set in config and null is passed', async () => {
|
|
393
|
-
const theProperty = ArrayProperty({ defaultValue: [1, 2, 3] })
|
|
394
|
-
// @ts-ignore
|
|
395
|
-
const getter = theProperty.createGetter(null)
|
|
396
|
-
const actual = await getter()
|
|
397
|
-
const expected = [1, 2, 3]
|
|
398
|
-
assert.deepEqual(actual, expected)
|
|
399
|
-
})
|
|
400
|
-
})
|
|
401
|
-
describe('#getValidator()', () => {
|
|
402
|
-
it('should validate an array passed in without issue', async () => {
|
|
403
|
-
const theProperty = ArrayProperty({})
|
|
404
|
-
const getter = theProperty.createGetter([1, 2, 3])
|
|
405
|
-
const validator = theProperty.getValidator(getter)
|
|
406
|
-
// @ts-ignore
|
|
407
|
-
const actual = await validator()
|
|
408
|
-
const expected: any[] = []
|
|
409
|
-
assert.deepEqual(actual, expected)
|
|
410
|
-
})
|
|
411
|
-
it('should error an array passed in when it doesnt have the right types', async () => {
|
|
412
|
-
const theProperty = ArrayProperty({
|
|
413
|
-
validators: [arrayType(TYPE_PRIMITIVES.integer)],
|
|
414
|
-
})
|
|
415
|
-
const getter = theProperty.createGetter([1, 'string', 3])
|
|
416
|
-
const validator = theProperty.getValidator(getter)
|
|
417
|
-
// @ts-ignore
|
|
418
|
-
const actual = await validator()
|
|
419
|
-
const expected = 1
|
|
420
|
-
assert.deepEqual(actual.length, expected)
|
|
421
|
-
})
|
|
422
|
-
it('should validate an array with [4,4,5,5,6,6] when choices are [4,5,6]', async () => {
|
|
423
|
-
const theProperty = ArrayProperty({ choices: [4, 5, 6] })
|
|
424
|
-
const getter = theProperty.createGetter([4, 4, 5, 5, 6, 6])
|
|
425
|
-
const validator = theProperty.getValidator(getter)
|
|
426
|
-
// @ts-ignore
|
|
427
|
-
const actual = await validator()
|
|
428
|
-
const expected: any[] = []
|
|
429
|
-
assert.deepEqual(actual, expected)
|
|
430
|
-
})
|
|
431
|
-
it('should return errors when an array with [4,4,3,5,5,6,6] when choices are [4,5,6]', async () => {
|
|
432
|
-
const theProperty = ArrayProperty({ choices: [4, 5, 6] })
|
|
433
|
-
const getter = theProperty.createGetter([4, 4, 3, 5, 5, 6, 6])
|
|
434
|
-
const validator = theProperty.getValidator(getter)
|
|
435
|
-
// @ts-ignore
|
|
436
|
-
const actual = await validator()
|
|
437
|
-
const expected = 1
|
|
438
|
-
assert.equal(actual.length, expected)
|
|
439
|
-
})
|
|
440
|
-
})
|
|
441
|
-
})
|
|
442
|
-
describe('#Property()', () => {
|
|
443
|
-
it('should throw an exception if a type is not provided', () => {
|
|
444
|
-
assert.throws(() => {
|
|
445
|
-
// @ts-ignore
|
|
446
|
-
Property(undefined, {})
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
it('should throw an exception if a type is not provided, and config is null', () => {
|
|
450
|
-
assert.throws(() => {
|
|
451
|
-
// @ts-ignore
|
|
452
|
-
Property(undefined, null)
|
|
453
|
-
})
|
|
454
|
-
})
|
|
455
|
-
it('should throw an exception if config.valueSelector is not a function but is set', () => {
|
|
456
|
-
assert.throws(() => {
|
|
457
|
-
// @ts-ignore
|
|
458
|
-
Property('MyProperty', { valueSelector: 'blah' })
|
|
459
|
-
})
|
|
460
|
-
})
|
|
461
|
-
it('should not throw an exception if config.valueSelector is a function', () => {
|
|
462
|
-
assert.doesNotThrow(() => {
|
|
463
|
-
Property('MyProperty', { valueSelector: () => ({}) })
|
|
464
|
-
})
|
|
465
|
-
})
|
|
466
|
-
it('should not throw an exception if config is null', () => {
|
|
467
|
-
assert.doesNotThrow(() => {
|
|
468
|
-
// @ts-ignore
|
|
469
|
-
Property('MyProperty', null)
|
|
470
|
-
})
|
|
471
|
-
})
|
|
472
|
-
describe('#getConstantValue()', () => {
|
|
473
|
-
it('should provide undefined if no config', () => {
|
|
474
|
-
// @ts-ignore
|
|
475
|
-
const instance = Property('MyTYpe', null)
|
|
476
|
-
const actual = instance.getConstantValue()
|
|
477
|
-
const expected = undefined
|
|
478
|
-
assert.deepEqual(actual, expected)
|
|
479
|
-
})
|
|
480
|
-
})
|
|
481
|
-
describe('#getPropertyType()', () => {
|
|
482
|
-
it('should use the type that is passed in via config', () => {
|
|
483
|
-
const instance = Property('OverrideMe', { type: 'ExtendedType' })
|
|
484
|
-
const actual = instance.getPropertyType()
|
|
485
|
-
const expected = 'ExtendedType'
|
|
486
|
-
assert.equal(actual, expected)
|
|
487
|
-
})
|
|
488
|
-
})
|
|
489
|
-
describe('#getConfig()', () => {
|
|
490
|
-
it('should provide the config that is passed in ', () => {
|
|
491
|
-
// @ts-ignore
|
|
492
|
-
const instance = Property('MyTYpe', { custom: 'value' })
|
|
493
|
-
const actual = instance.getConfig()
|
|
494
|
-
const expected = { custom: 'value' }
|
|
495
|
-
assert.deepEqual(actual, expected)
|
|
496
|
-
})
|
|
497
|
-
it('should provide {} if no config', () => {
|
|
498
|
-
// @ts-ignore
|
|
499
|
-
const instance = Property('MyTYpe', null)
|
|
500
|
-
const actual = instance.getConfig()
|
|
501
|
-
const expected = {}
|
|
502
|
-
assert.deepEqual(actual, expected)
|
|
503
|
-
})
|
|
504
|
-
})
|
|
505
|
-
describe('#getDefaultValue()', () => {
|
|
506
|
-
it('should provide undefined if no config', () => {
|
|
507
|
-
// @ts-ignore
|
|
508
|
-
const instance = Property('MyTYpe', null)
|
|
509
|
-
const actual = instance.getDefaultValue()
|
|
510
|
-
const expected = undefined
|
|
511
|
-
assert.deepEqual(actual, expected)
|
|
512
|
-
})
|
|
513
|
-
it('should provide the defaultValue that is passed in if no value', () => {
|
|
514
|
-
// @ts-ignore
|
|
515
|
-
const instance = Property('MyTYpe', { defaultValue: 'test-me' })
|
|
516
|
-
const actual = instance.getDefaultValue()
|
|
517
|
-
const expected = 'test-me'
|
|
518
|
-
assert.deepEqual(actual, expected)
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
describe('#getChoices()', () => {
|
|
522
|
-
it('should provide [] if no config', () => {
|
|
523
|
-
// @ts-ignore
|
|
524
|
-
const instance = Property('MyTYpe', null)
|
|
525
|
-
const actual = instance.getChoices()
|
|
526
|
-
const expected: any[] = []
|
|
527
|
-
assert.deepEqual(actual, expected)
|
|
528
|
-
})
|
|
529
|
-
it('should provide the choices that are passed in ', () => {
|
|
530
|
-
// @ts-ignore
|
|
531
|
-
const instance = Property('MyTYpe', { choices: [1, 2, 3] })
|
|
532
|
-
const actual = instance.getChoices()
|
|
533
|
-
const expected = [1, 2, 3]
|
|
534
|
-
assert.deepEqual(actual, expected)
|
|
535
|
-
})
|
|
536
|
-
})
|
|
537
|
-
describe('#createGetter()', () => {
|
|
538
|
-
it('should return a function even if config.value is set to a value', () => {
|
|
539
|
-
const instance = Property('MyProperty', { value: 'my-value' })
|
|
540
|
-
const actual = instance.createGetter('not-my-value')
|
|
541
|
-
assert.isFunction(actual)
|
|
542
|
-
})
|
|
543
|
-
it('should return the value passed into config.value regardless of what is passed into the createGetter', async () => {
|
|
544
|
-
const instance = Property('MyProperty', { value: 'my-value' })
|
|
545
|
-
const actual = await instance.createGetter('not-my-value')()
|
|
546
|
-
const expected = 'my-value'
|
|
547
|
-
assert.deepEqual(actual, expected)
|
|
548
|
-
})
|
|
549
|
-
it('should return the value passed into createGetter when config.value is not set', async () => {
|
|
550
|
-
const instance = Property('MyProperty')
|
|
551
|
-
const actual = await instance.createGetter('my-value')()
|
|
552
|
-
const expected = 'my-value'
|
|
553
|
-
assert.deepEqual(actual, expected)
|
|
554
|
-
})
|
|
555
|
-
it('should return the value of the function passed into createGetter when config.value is not set', async () => {
|
|
556
|
-
const instance = Property('MyProperty')
|
|
557
|
-
const actual = await instance.createGetter(() => 'my-value')()
|
|
558
|
-
const expected = 'my-value'
|
|
559
|
-
assert.deepEqual(actual, expected)
|
|
560
|
-
})
|
|
561
|
-
})
|
|
562
|
-
})
|
|
563
|
-
describe('#UniqueId()', () => {
|
|
564
|
-
describe('#createGetter()', () => {
|
|
565
|
-
it('should call createUuid only once even if called twice', async () => {
|
|
566
|
-
const uniqueProperty = UniqueId({})
|
|
567
|
-
// @ts-ignore
|
|
568
|
-
const getter = uniqueProperty.createGetter(undefined)
|
|
569
|
-
const first = await getter()
|
|
570
|
-
const second = await getter()
|
|
571
|
-
assert.deepEqual(first, second)
|
|
572
|
-
})
|
|
573
|
-
it('should use the uuid passed in', async () => {
|
|
574
|
-
const uniqueProperty = UniqueId({})
|
|
575
|
-
const getter = uniqueProperty.createGetter('my-uuid')
|
|
576
|
-
const actual = await getter()
|
|
577
|
-
const expected = 'my-uuid'
|
|
578
|
-
assert.deepEqual(actual, expected)
|
|
579
|
-
})
|
|
580
|
-
})
|
|
581
|
-
})
|
|
582
|
-
describe('#DateProperty()', () => {
|
|
583
|
-
it('should allow creation without a config', async () => {
|
|
584
|
-
const proto = DateProperty()
|
|
585
|
-
const instance = proto.createGetter(new Date())
|
|
586
|
-
assert.isOk(await instance())
|
|
587
|
-
})
|
|
588
|
-
it('should create a new date once when config.autoNow=true and called multiple times', async () => {
|
|
589
|
-
const proto = DateProperty({ autoNow: true })
|
|
590
|
-
const instance = proto.createGetter(undefined)
|
|
591
|
-
const first = await instance()
|
|
592
|
-
const second = await instance()
|
|
593
|
-
const third = await instance()
|
|
594
|
-
assert.deepEqual(first, second)
|
|
595
|
-
assert.deepEqual(first, third)
|
|
596
|
-
})
|
|
597
|
-
it('should use the date passed in', async () => {
|
|
598
|
-
const proto = DateProperty({ autoNow: true })
|
|
599
|
-
const date = new Date()
|
|
600
|
-
const instance = proto.createGetter(date)
|
|
601
|
-
const actual = await instance()
|
|
602
|
-
const expected = date
|
|
603
|
-
assert.deepEqual(actual, expected)
|
|
604
|
-
})
|
|
605
|
-
it('should return null, if null config is passed and no value created.', async () => {
|
|
606
|
-
// @ts-ignore
|
|
607
|
-
const proto = DateProperty(null)
|
|
608
|
-
const date = null
|
|
609
|
-
const instance = proto.createGetter(date)
|
|
610
|
-
const actual = await instance()
|
|
611
|
-
const expected = null
|
|
612
|
-
assert.deepEqual(actual, expected)
|
|
613
|
-
})
|
|
614
|
-
})
|
|
615
|
-
|
|
616
|
-
describe('#ReferenceProperty()', () => {
|
|
617
|
-
it('should throw an exception if a model value is not passed in', () => {
|
|
618
|
-
assert.throws(() => {
|
|
619
|
-
const input = ['obj-id']
|
|
620
|
-
// @ts-ignore
|
|
621
|
-
const actual = ReferenceProperty(null, {})
|
|
622
|
-
})
|
|
623
|
-
})
|
|
624
|
-
describe('#meta.getReferencedModel()', () => {
|
|
625
|
-
it('should return the same value passed in as the model', async () => {
|
|
626
|
-
const property = ReferenceProperty(TestModel1)
|
|
627
|
-
const actual = property.getReferencedModel()
|
|
628
|
-
const expected = TestModel1
|
|
629
|
-
assert.deepEqual(actual, expected)
|
|
630
|
-
})
|
|
631
|
-
it('should allow a function input for model to allow delayed creation', async () => {
|
|
632
|
-
const property = ReferenceProperty(() => TestModel1)
|
|
633
|
-
const actual = property.getReferencedModel()
|
|
634
|
-
const expected = TestModel1
|
|
635
|
-
assert.deepEqual(actual, expected)
|
|
636
|
-
})
|
|
637
|
-
})
|
|
638
|
-
describe('#createGetter()', () => {
|
|
639
|
-
it('should return "obj-id" when no fetcher is used', async () => {
|
|
640
|
-
const actual = await ReferenceProperty(TestModel1, {}).createGetter(
|
|
641
|
-
'obj-id'
|
|
642
|
-
)()
|
|
643
|
-
const expected = 'obj-id'
|
|
644
|
-
assert.equal(actual, expected)
|
|
645
|
-
})
|
|
646
|
-
it('should allow null as the input', async () => {
|
|
647
|
-
const actual = await ReferenceProperty(TestModel1, {}).createGetter(
|
|
648
|
-
null
|
|
649
|
-
)()
|
|
650
|
-
const expected = null
|
|
651
|
-
assert.equal(actual, expected)
|
|
652
|
-
})
|
|
653
|
-
it('should return "obj-id" from {}.id when no fetcher is used', async () => {
|
|
654
|
-
const actual = await ReferenceProperty(TestModel1, {}).createGetter(
|
|
655
|
-
// @ts-ignore
|
|
656
|
-
{ id: 'obj-id' }
|
|
657
|
-
)()
|
|
658
|
-
const expected = 'obj-id'
|
|
659
|
-
assert.equal(actual, expected)
|
|
660
|
-
})
|
|
661
|
-
it('should return 123 from {}.id when no fetcher is used', async () => {
|
|
662
|
-
const actual = await ReferenceProperty(TestModel1, {}).createGetter(
|
|
663
|
-
123
|
|
664
|
-
)()
|
|
665
|
-
const expected = 123
|
|
666
|
-
assert.equal(actual, expected)
|
|
667
|
-
})
|
|
668
|
-
it('should return name:"switch-a-roo" when switch-a-roo fetcher is used', async () => {
|
|
669
|
-
const actual = (await ReferenceProperty(TestModel1, {
|
|
670
|
-
fetcher: async () => ({ id: 'obj-id', name: 'switch-a-roo' }),
|
|
671
|
-
}).createGetter('obj-id')()) as ModelInstance<TestModelType>
|
|
672
|
-
const expected = 'switch-a-roo'
|
|
673
|
-
assert.deepEqual(actual.get.name(), expected)
|
|
674
|
-
})
|
|
675
|
-
it('should return "obj-id" if no config passed', async () => {
|
|
676
|
-
// @ts-ignore
|
|
677
|
-
const actual = (await ReferenceProperty(TestModel1, null).createGetter(
|
|
678
|
-
'obj-id'
|
|
679
|
-
)()) as string
|
|
680
|
-
const expected = 'obj-id'
|
|
681
|
-
assert.deepEqual(actual, expected)
|
|
682
|
-
})
|
|
683
|
-
it('should return null when fetcher is used, but the instance value passed in is empty', async () => {
|
|
684
|
-
const actual = (await ReferenceProperty(TestModel1, {
|
|
685
|
-
fetcher: async () => ({ id: 'obj-id', name: 'switch-a-roo' }),
|
|
686
|
-
}).createGetter(null)()) as ModelInstance<TestModelType>
|
|
687
|
-
const expected = null
|
|
688
|
-
assert.deepEqual(actual, expected)
|
|
689
|
-
})
|
|
690
|
-
it('should provide the passed in model and the instance values when switch-a-roo fetcher is used', async () => {
|
|
691
|
-
const input = 'obj-id'
|
|
692
|
-
const fetcher = sinon.stub().callsFake((modelName, id) => ({ id }))
|
|
693
|
-
await ReferenceProperty(TestModel1, {
|
|
694
|
-
fetcher,
|
|
695
|
-
}).createGetter(input)()
|
|
696
|
-
const actual = fetcher.getCall(0).args[0]
|
|
697
|
-
const expected = TestModel1
|
|
698
|
-
assert.deepEqual(actual, expected)
|
|
699
|
-
})
|
|
700
|
-
it('should take the smartObject as a value', async () => {
|
|
701
|
-
const id = 'obj-id'
|
|
702
|
-
const proto = BaseModel<TestModelType>('name', {
|
|
703
|
-
properties: {
|
|
704
|
-
id: UniqueId({ value: id }),
|
|
705
|
-
name: TextProperty({}),
|
|
706
|
-
},
|
|
707
|
-
})
|
|
708
|
-
const input = proto.create({ id, name: 'name' })
|
|
709
|
-
const instance = (await ReferenceProperty<TestModelType>(
|
|
710
|
-
TestModel1,
|
|
711
|
-
{}
|
|
712
|
-
).createGetter(input)()) as ModelInstance<TestModelType>
|
|
713
|
-
const actual = await instance.get.id()
|
|
714
|
-
const expected = 'obj-id'
|
|
715
|
-
assert.deepEqual(actual, expected)
|
|
716
|
-
})
|
|
717
|
-
describe('#toObj()', () => {
|
|
718
|
-
it('should use the getId of the smartObject passed in when toObj is called', async () => {
|
|
719
|
-
const proto = BaseModel<TestModelType>('name', {
|
|
720
|
-
properties: {
|
|
721
|
-
id: UniqueId({ value: 'obj-id' }),
|
|
722
|
-
name: TextProperty({}),
|
|
723
|
-
},
|
|
724
|
-
})
|
|
725
|
-
const input = proto.create({ id: 'obj-id', name: 'name' })
|
|
726
|
-
const instance = (await ReferenceProperty<TestModelType>(
|
|
727
|
-
TestModel1,
|
|
728
|
-
{}
|
|
729
|
-
).createGetter(input)()) as ModelInstance<{}>
|
|
730
|
-
const actual = await instance.toObj()
|
|
731
|
-
const expected = 'obj-id'
|
|
732
|
-
assert.deepEqual(actual, expected)
|
|
733
|
-
})
|
|
734
|
-
it('should return "obj-id" when switch-a-roo fetcher is used and toObj is called', async () => {
|
|
735
|
-
const input = 'obj-id'
|
|
736
|
-
const instance = (await ReferenceProperty(TestModel1, {
|
|
737
|
-
fetcher: () =>
|
|
738
|
-
Promise.resolve({ id: 'obj-id', prop: 'switch-a-roo' }),
|
|
739
|
-
}).createGetter(input)()) as ModelInstance<{}>
|
|
740
|
-
const actual = await instance.toObj()
|
|
741
|
-
const expected = 'obj-id'
|
|
742
|
-
assert.deepEqual(actual, expected)
|
|
743
|
-
})
|
|
744
|
-
})
|
|
745
|
-
})
|
|
746
|
-
})
|
|
747
|
-
})
|