functional-models 1.0.4 → 1.0.5
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.
|
@@ -2,15 +2,14 @@ const assert = require('chai').assert
|
|
|
2
2
|
const flatMap = require('lodash/flatMap')
|
|
3
3
|
const { Given, When, Then } = require('@cucumber/cucumber')
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { createModel, field } = require('../../index')
|
|
6
6
|
|
|
7
7
|
const MODEL_DEFINITIONS = {
|
|
8
|
-
TestModel1: ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]),
|
|
8
|
+
TestModel1: createModel({
|
|
9
|
+
name: field({ required: true }),
|
|
10
|
+
type: field({ required: true, isString: true }),
|
|
11
|
+
flag: field({ required: true, isNumber: true }),
|
|
12
|
+
}),
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
const MODEL_INPUT_VALUES = {
|
|
@@ -26,7 +25,7 @@ const MODEL_INPUT_VALUES = {
|
|
|
26
25
|
},
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
const
|
|
28
|
+
const EXPECTED_FIELDS = {
|
|
30
29
|
TestModel1b: ['getName', 'getType', 'getFlag', 'meta', 'functions'],
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -46,7 +45,7 @@ Given(
|
|
|
46
45
|
)
|
|
47
46
|
|
|
48
47
|
When('functions.validate is called', function () {
|
|
49
|
-
return this.instance.functions.validate.
|
|
48
|
+
return this.instance.functions.validate.model().then(x => {
|
|
50
49
|
this.errors = x
|
|
51
50
|
})
|
|
52
51
|
})
|
|
@@ -75,10 +74,10 @@ When('{word} data is inserted', function (modelInputValues) {
|
|
|
75
74
|
this.instance = this.modelDefinition(input)
|
|
76
75
|
})
|
|
77
76
|
|
|
78
|
-
Then('{word} expected
|
|
79
|
-
const propertyArray =
|
|
77
|
+
Then('{word} expected fields are found', function (fields) {
|
|
78
|
+
const propertyArray = EXPECTED_FIELDS[fields]
|
|
80
79
|
if (!propertyArray) {
|
|
81
|
-
throw new Error(`${
|
|
80
|
+
throw new Error(`${fields} did not result in fields`)
|
|
82
81
|
}
|
|
83
82
|
propertyArray.forEach(key => {
|
|
84
83
|
if (!(key in this.instance)) {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/validation.js
CHANGED
|
@@ -31,14 +31,12 @@ const isInteger = _trueOrError(v => {
|
|
|
31
31
|
const isBoolean = isType('boolean')
|
|
32
32
|
const isString = isType('string')
|
|
33
33
|
|
|
34
|
-
const meetsRegex =
|
|
35
|
-
regex,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return _trueOrError(v => reg.test(v), errorMessage)(value)
|
|
41
|
-
}
|
|
34
|
+
const meetsRegex =
|
|
35
|
+
(regex, flags, errorMessage = 'Format was invalid') =>
|
|
36
|
+
value => {
|
|
37
|
+
const reg = new RegExp(regex, flags)
|
|
38
|
+
return _trueOrError(v => reg.test(v), errorMessage)(value)
|
|
39
|
+
}
|
|
42
40
|
|
|
43
41
|
const choices = choiceArray => value => {
|
|
44
42
|
if (choiceArray.includes(value) === false) {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Feature: Smart Object Prototypes
|
|
2
|
-
|
|
3
|
-
Scenario: An example smart object prototype is created and checked for expected properties and is validated.
|
|
4
|
-
Given the prototype TestPrototype1 is used
|
|
5
|
-
When the prototype data TestPrototype1a is used to create an instance
|
|
6
|
-
Then the prototype instance has the expected properties for TestPrototype1a
|
|
7
|
-
And the prototype has the expected toJson response for TestPrototype1a
|
|
8
|
-
And the prototype has 0 errors expected
|