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.
@@ -0,0 +1,7 @@
1
+ Feature: Models
2
+
3
+ Scenario: A Model With a 4 fields
4
+ Given TestModel1 is used
5
+ When TestModel1b data is inserted
6
+ Then TestModel1b expected fields are found
7
+
@@ -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 { smartObject, property, named, typed } = require('../../index')
5
+ const { createModel, field } = require('../../index')
6
6
 
7
7
  const MODEL_DEFINITIONS = {
8
- TestModel1: ({ name, type, flag }) =>
9
- smartObject([
10
- named({ required: true })(name),
11
- typed({ required: true, isString: 'true' })(type),
12
- property('flag', { required: true, isNumber: true })(flag),
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 EXPECTED_PROPERTIES = {
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.object().then(x => {
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 properties are found', function (properties) {
79
- const propertyArray = EXPECTED_PROPERTIES[properties]
77
+ Then('{word} expected fields are found', function (fields) {
78
+ const propertyArray = EXPECTED_FIELDS[fields]
80
79
  if (!propertyArray) {
81
- throw new Error(`${properties} did not result in properties`)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functional-models",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A library for creating JavaScript function based models.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  ...require('./fields'),
3
+ ...require('./models'),
3
4
  validation: require('./validation'),
4
5
  serialization: require('./serialization'),
5
6
  }
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
- flags,
37
- errorMessage = 'Format was invalid'
38
- ) => value => {
39
- const reg = new RegExp(regex, flags)
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,7 +0,0 @@
1
- Feature: Smart Objects
2
-
3
- Scenario: A Smart Object With a 4 properties
4
- Given TestModel1 is used
5
- When TestModel1b data is inserted
6
- Then TestModel1b expected properties are found
7
-
@@ -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