ac-sanitizer 4.1.0 → 4.1.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,45 @@
1
+
2
+ ## [4.1.3](https://github.com/mmpro/ac-sanitizer/compare/v4.1.2..v4.1.3) (2025-03-18 08:54:37)
3
+
4
+
5
+ ### Bug Fix
6
+
7
+ * **App:** Package updates | MP | [44220372ad7190e78cc750d8bc08b6388b15ab6a](https://github.com/mmpro/ac-sanitizer/commit/44220372ad7190e78cc750d8bc08b6388b15ab6a)
8
+ Package updates
9
+ Related issues:
10
+
11
+ ## [4.1.2](https://github.com/mmpro/ac-sanitizer/compare/v4.1.1..v4.1.2) (2025-01-25 13:17:56)
12
+
13
+
14
+ ### Bug Fix
15
+
16
+ * **App:** Minor adjustments | MP | [3c24752c112d8e92e66f2fd6c262005c616edc3c](https://github.com/mmpro/ac-sanitizer/commit/3c24752c112d8e92e66f2fd6c262005c616edc3c)
17
+ Make sure to remove undefined properties
18
+ Related issues:
19
+ ### Tests
20
+
21
+ * **App:** Refactored tests | MP | [fcaf656fbeccfd8228038e64b4e520514faf31a8](https://github.com/mmpro/ac-sanitizer/commit/fcaf656fbeccfd8228038e64b4e520514faf31a8)
22
+ Use a generic test helper to reduce duplications
23
+ Related issues:
24
+ ### Chores
25
+
26
+ * **App:** Improved ESLint | MP | [79b6879917027c07e9df6d6a44b51c199780a289](https://github.com/mmpro/ac-sanitizer/commit/79b6879917027c07e9df6d6a44b51c199780a289)
27
+ Improved ESLint
28
+ Related issues:
29
+
30
+ ## [4.1.1](https://github.com/mmpro/ac-sanitizer/compare/v4.1.0..v4.1.1) (2025-01-25 10:27:26)
31
+
32
+
33
+ ### Bug Fix
34
+
35
+ * **App:** Improved ignoreCase function | MP | [eff1e68bb1b5e32fa448e4c58645a4f06c0b0d15](https://github.com/mmpro/ac-sanitizer/commit/eff1e68bb1b5e32fa448e4c58645a4f06c0b0d15)
36
+ Improved ignoreCase function
37
+ Related issues:
38
+ ### Tests
39
+
40
+ * **App:** Added test | MP | [7674a680a189868b6d20a2307a5f73b66b62b2f6](https://github.com/mmpro/ac-sanitizer/commit/7674a680a189868b6d20a2307a5f73b66b62b2f6)
41
+ Added test for arrays with ignoreCase
42
+ Related issues:
1
43
 
2
44
  # [4.1.0](https://github.com/mmpro/ac-sanitizer/compare/v4.0.16..v4.1.0) (2025-01-25 10:01:18)
3
45
 
package/Makefile CHANGED
@@ -2,10 +2,10 @@ MOCHA_OPTS= --slow 0 -A
2
2
  REPORTER = spec
3
3
 
4
4
  lint-fix:
5
- ./node_modules/.bin/eslint --fix index.js test/test.js
5
+ ./node_modules/.bin/eslint --fix index.js test/test.js test/tests/**.js
6
6
 
7
7
  lint-check:
8
- ./node_modules/.bin/eslint index.js test/test.js
8
+ ./node_modules/.bin/eslint index.js test/test.js test/tests/**.js
9
9
 
10
10
  commit:
11
11
  @node ./node_modules/ac-semantic-release/lib/commit.js
package/eslint.config.js CHANGED
@@ -22,7 +22,8 @@ module.exports = [
22
22
  'no-useless-escape': 'off',
23
23
  'standard/no-callback-literal': 'off',
24
24
  'new-cap': 'off',
25
- 'no-console': ['error', { allow: ['error'] }]
25
+ 'no-console': ['error', { allow: ['error'] }],
26
+ "no-multiple-empty-lines": ["error", { "max": 1 }]
26
27
  },
27
28
  ignores: ['temp.js', 'config/*']
28
29
  }
package/index.js CHANGED
@@ -56,7 +56,7 @@ const sanitizer = function() {
56
56
  */
57
57
 
58
58
  const checkAndSanitizeValues = (params) => {
59
- const paramsToCheck = params.params
59
+ let paramsToCheck = _.omitBy(params.params, _.isUndefined)
60
60
  if (!_.isObject(paramsToCheck)) return { error: { message: 'params_required' } }
61
61
  let fields = params.fields
62
62
  if (!_.isArray(fields) || !_.size(fields)) return { error: { message: 'fields_required' } }
@@ -107,7 +107,7 @@ const sanitizer = function() {
107
107
  else {
108
108
  if (_.get(field, 'required')) {
109
109
  fieldIsRequired = true
110
- if (!_.has(paramsToCheck, fieldName)) {
110
+ if (!_.has(paramsToCheck, fieldName) || _.isUndefined(_.get(paramsToCheck, fieldName))) {
111
111
  error = { message: 'field_' + fieldName + '_required' }
112
112
  }
113
113
  }
@@ -212,7 +212,6 @@ const sanitizer = function() {
212
212
  if (field.type === 'number') console.error('SANITIZER - number should not be used, be more precise')
213
213
  if (field.type === 'number') field.type = 'integer'
214
214
 
215
-
216
215
  if (field.type !== 'float' && _.get(field, 'convert')) {
217
216
  // make sure the value is integer
218
217
  value = parseInt(value)
@@ -497,27 +496,24 @@ const sanitizer = function() {
497
496
  }
498
497
 
499
498
  if (!error && allowedValues && value) {
500
- let orgValue
501
- if (field.ignoreCase && _.isString(value)) {
502
- // convert value and allowesValues to lowercase
503
- orgValue = _.clone(orgValue)
504
- value = _.toLower(value)
505
- allowedValues = _.map(allowedValues, _.toLower)
499
+
500
+ const compareIgnoreCase = (a, b) => {
501
+ return a.toLowerCase() === b.toLowerCase()
506
502
  }
503
+ const compareFn = field.ignoreCase ? compareIgnoreCase : _.isEqual
507
504
 
508
505
  if (_.isArray(value)) {
509
- if (_.size(value) && !_.size(_.intersectionWith(value, allowedValues, _.isEqual))) {
506
+ if (_.size(value) && !_.size(_.intersectionWith(value, allowedValues, compareFn))) {
510
507
  error = { message: fieldName + '_notAnAllowedValue', additionalInfo: { value } }
511
508
  }
512
509
  // remove non-matching entries, but do not fail/return error
513
- value = _.intersectionWith(value, allowedValues, _.isEqual)
510
+ value = _.intersectionWith(value, allowedValues, compareFn)
514
511
  _.set(paramsToCheck, fieldName, value)
515
512
  }
516
- else if (_.indexOf(allowedValues, value) < 0) {
513
+ else if (_.findIndex(allowedValues, val => compareFn(val, value)) < 0) {
517
514
  error = { message: fieldName + '_notAnAllowedValue', additionalInfo: { value } }
518
515
  }
519
516
 
520
- if (orgValue) value = orgValue
521
517
  }
522
518
 
523
519
  if (error && field.customErrorMessage) _.set(error, 'message', field.customErrorMessage)
@@ -548,8 +544,6 @@ const sanitizer = function() {
548
544
  else params = _.get(check, 'params')
549
545
  */
550
546
 
551
-
552
-
553
547
  /**
554
548
  * Return a random value for a given type
555
549
  */
package/package.json CHANGED
@@ -4,12 +4,12 @@
4
4
  "author": "Mark Poepping (https://www.admiralcloud.com)",
5
5
  "license": "MIT",
6
6
  "repository": "admiralcloud/ac-sanitizer",
7
- "version": "4.1.0",
7
+ "version": "4.1.3",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
10
  "ac-countrylist": "^1.0.12",
11
11
  "ac-file-extensions": "^2.0.10",
12
- "ac-ip": "^4.1.2",
12
+ "ac-ip": "^4.1.3",
13
13
  "chai": "^4.5.0",
14
14
  "date-and-time": "^3.6.0",
15
15
  "hashids": "^2.3.0",
@@ -19,7 +19,7 @@
19
19
  "devDependencies": {
20
20
  "ac-semantic-release": "^0.4.5",
21
21
  "c8": "^10.1.3",
22
- "eslint": "^9.19.0",
22
+ "eslint": "^9.22.0",
23
23
  "mocha": "^11.1.0"
24
24
  },
25
25
  "scripts": {
package/test/tests/any.js CHANGED
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -18,32 +17,6 @@ module.exports = {
18
17
  { name: 'Any - with null and nullAllowed', type: 'any', value: null, nullAllowed: true, expected: null },
19
18
  ]
20
19
 
21
- _.forEach(baseTests, (test) => {
22
- it(test.name, (done) => {
23
- let fieldsToCheck = {
24
- params: {
25
- any: _.get(test, 'value')
26
- },
27
- fields: [
28
- { field: 'any', type: _.get(test, 'type'), nullAllowed: _.get(test, 'nullAllowed') }
29
- ]
30
- }
31
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
32
- if (_.get(r, 'error')) {
33
- expect(_.get(r, 'error.message')).to.equal(test.error)
34
- if (_.get(test, 'additionalInfo')) {
35
- expect(_.get(r, 'error.additionalInfo')).to.eql(_.get(test, 'additionalInfo'))
36
- }
37
- }
38
- else {
39
- expect(_.get(r, 'params.any')).to.eql(_.get(test, 'expected'))
40
- }
41
- return done()
42
- })
43
-
44
- })
45
-
46
-
47
-
20
+ runValidationTests(baseTests, 'any', { equalityCheck: 'eql' })
48
21
  }
49
22
  }
@@ -1,4 +1,4 @@
1
- const _ = require('lodash')
1
+ const { runValidationTests } = require('./helper')
2
2
  const sanitizer = require('../../index')
3
3
 
4
4
  module.exports = {
@@ -8,7 +8,7 @@ module.exports = {
8
8
  const randomValueString = sanitizer.randomValue({ type: 'array' })
9
9
 
10
10
  const baseTests = [
11
- { name: 'Valid array of numbers', type: 'array', value: randomValueInt, expected: randomValueInt},
11
+ { name: 'Valid array of numbers', type: 'array', value: randomValueInt, expected: randomValueInt },
12
12
  { name: 'Valid array of strings', type: 'array', value: randomValueString, expected: randomValueString },
13
13
  { name: 'Invalid array', type: 'array', value: 'a', error: 'array_notAnArray' },
14
14
  { name: 'Array with enum match', type: 'array', value: ['video'], enum: ['audio', 'video'], expected: ['video'] },
@@ -36,43 +36,11 @@ module.exports = {
36
36
  properties: [{ field: 'p1', type: 'string' }],
37
37
  value: [{ p1: 'isAString', p2: 'shouldBeRemoved' }, { p1: 'isAString2', p2: 'shouldBeRemoved2' }],
38
38
  expected: [{ p1: 'isAString' }, { p1: 'isAString2' }]
39
- }
39
+ },
40
+ { name: 'Array of strings with enum - uppercase vs lowercase', type: 'array', valueType: 'string', value: ['ABC'], enum: ['abc'], error: 'array_notAnAllowedValue' },
41
+ { name: 'Array of strings with enum - uppercase vs lowercase - with ignoreCase', type: 'array', valueType: 'string', ignoreCase: true, value: ['ABC', 'DEF'], enum: ['abc'], expected: ['ABC'] },
40
42
  ]
41
43
 
42
-
43
- _.forEach(baseTests, (test) => {
44
- it(test.name, (done) => {
45
- let fieldsToCheck = {
46
- params: {
47
- array: _.get(test, 'value')
48
- },
49
- fields: [
50
- { field: 'array', type: _.get(test, 'type'), required: _.get(test, 'required'), valueType: _.get(test, 'valueType'), minSize: _.get(test, 'minSize'), maxSize: _.get(test, 'maxSize'), properties: _.get(test, "properties")}
51
- ]
52
- }
53
- if (test.enum) {
54
- _.set(fieldsToCheck, 'fields[0].enum', test.enum)
55
- }
56
- if (test.wildcardAllowed) {
57
- _.set(fieldsToCheck, 'fields[0].wildcardAllowed', test.wildcardAllowed)
58
- }
59
-
60
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
61
- if (_.get(r, 'error')) {
62
- expect(_.get(r, 'error.message')).to.equal(test.error)
63
- if (_.get(test, 'additionalInfo')) {
64
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
65
- }
66
- }
67
- else {
68
- expect(_.get(r, 'params.array')).to.eql(_.get(test, 'expected'))
69
- }
70
- return done()
71
- })
72
-
73
- })
74
-
75
-
76
-
44
+ runValidationTests(baseTests, 'array', { equalityCheck: 'eql' })
77
45
  }
78
46
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -21,33 +20,6 @@ module.exports = {
21
20
  { name: 'Base64 string with enum - fail', type: 'base64', value: 'bXlzdHJpbmc=', convert: true, error: 'base64_notAnAllowedValue', enum: ['otherstring'] }
22
21
  ]
23
22
 
24
- _.forEach(baseTests, (test) => {
25
- it(test.name, (done) => {
26
- let fieldsToCheck = {
27
- params: {
28
- base64: _.get(test, 'value')
29
- },
30
- fields: [
31
- { field: 'base64', type: _.get(test, 'type'), convert: _.get(test, 'convert'), enum: _.get(test, 'enum') }
32
- ]
33
- }
34
-
35
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
36
- if (_.get(r, 'error')) {
37
- expect(_.get(r, 'error.message')).to.equal(test.error)
38
- if (_.get(test, 'additionalInfo')) {
39
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
40
- }
41
- }
42
- else {
43
- expect(_.get(r, 'params.base64')).to.eql(_.get(test, 'expected'))
44
- }
45
- return done()
46
- })
47
-
48
- })
49
-
50
-
51
-
23
+ runValidationTests(baseTests, 'base64', { equalityCheck: 'eql' })
52
24
  }
53
25
  }
@@ -1,4 +1,4 @@
1
- const _ = require('lodash')
1
+ const { runValidationTests } = require('./helper')
2
2
  const sanitizer = require('../../index')
3
3
 
4
4
  module.exports = {
@@ -14,34 +14,6 @@ module.exports = {
14
14
  { name: 'Invalid - value is integer', type: 'boolean', value: 123, error: 'bool_notBoolean' },
15
15
  ]
16
16
 
17
-
18
- _.forEach(baseTests, (test) => {
19
- it(test.name, (done) => {
20
- let fieldsToCheck = {
21
- params: {
22
- bool: _.get(test, 'value')
23
- },
24
- fields: [
25
- { field: 'bool', type: _.get(test, 'type'), required: _.get(test, 'required') }
26
- ]
27
- }
28
-
29
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
30
- if (_.get(r, 'error')) {
31
- expect(_.get(r, 'error.message')).to.equal(test.error)
32
- if (_.get(test, 'additionalInfo')) {
33
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
34
- }
35
- }
36
- else {
37
- expect(_.get(r, 'params.bool')).to.equal(_.get(test, 'expected'))
38
- }
39
- return done()
40
- })
41
-
42
- })
43
-
44
-
45
-
17
+ runValidationTests(baseTests, 'bool')
46
18
  }
47
19
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -11,29 +10,6 @@ module.exports = {
11
10
  { name: 'Invalid - neither bool nor integer', type: 'integer | boolean', value: 'abc', error: 'boolOrInteger_neitherBooleanNorInteger' },
12
11
  ]
13
12
 
14
- _.forEach(baseTests, (test) => {
15
- it(test.name, (done) => {
16
- let fieldsToCheck = {
17
- params: {
18
- boolOrInteger: _.get(test, 'value')
19
- },
20
- fields: [
21
- { field: 'boolOrInteger', type: _.get(test, 'type'), required: _.get(test, 'required') }
22
- ]
23
- }
24
-
25
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
26
- if (_.get(r, 'error')) {
27
- expect(_.get(r, 'error.message')).to.equal(test.error)
28
- if (_.get(test, 'additionalInfo')) {
29
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
30
- }
31
- }
32
- else {
33
- expect(_.get(r, 'params.boolOrInteger')).to.equal(_.get(test, 'expected'))
34
- }
35
- return done()
36
- })
37
- })
13
+ runValidationTests(baseTests, 'boolOrInteger')
38
14
  }
39
15
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -15,33 +14,6 @@ module.exports = {
15
14
  { name: 'Invalid CIDR array', type: 'cidr', valueType: 'cidr', value: [{ cidr: '::ffff:127.0.0.1' }], error: 'cidr_notAValidCIDR' },
16
15
  ]
17
16
 
18
-
19
- _.forEach(baseTests, (test) => {
20
- it(test.name, (done) => {
21
- let fieldsToCheck = {
22
- params: {
23
- cidr: _.get(test, 'value')
24
- },
25
- fields: [
26
- { field: 'cidr', type: _.get(test, 'type'), version: _.get(test, 'version'), required: _.get(test, 'required') }
27
- ]
28
- }
29
-
30
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
31
- if (_.get(r, 'error')) {
32
- expect(_.get(r, 'error.message')).to.equal(test.error)
33
- if (_.get(test, 'additionalInfo')) {
34
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
35
- }
36
- }
37
- else {
38
- expect(_.get(r, 'params.cidr')).to.eql(_.get(test, 'expected'))
39
- }
40
- return done()
41
- })
42
- })
43
-
44
-
45
-
17
+ runValidationTests(baseTests, 'cidr', { equalityCheck: 'eql' })
46
18
  }
47
19
  }
@@ -1,4 +1,4 @@
1
- const _ = require('lodash')
1
+ const { runValidationTests } = require('./helper')
2
2
  const sanitizer = require('../../index')
3
3
 
4
4
  module.exports = {
@@ -11,34 +11,6 @@ module.exports = {
11
11
  { name: 'Invalid countryCode', type: 'countryCode', value: 'germany', error: 'countryCode_notAValidCountryCode' },
12
12
  ]
13
13
 
14
-
15
- _.forEach(baseTests, (test) => {
16
- it(test.name, (done) => {
17
- let fieldsToCheck = {
18
- params: {
19
- countryCode: _.get(test, 'value')
20
- },
21
- fields: [
22
- { field: 'countryCode', type: _.get(test, 'type'), required: _.get(test, 'required') }
23
- ]
24
- }
25
-
26
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
27
- if (_.get(r, 'error')) {
28
- expect(_.get(r, 'error.message')).to.equal(test.error)
29
- if (_.get(test, 'additionalInfo')) {
30
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
31
- }
32
- }
33
- else {
34
- expect(_.get(r, 'params.countryCode')).to.equal(_.get(test, 'expected'))
35
- }
36
- return done()
37
- })
38
-
39
- })
40
-
41
-
42
-
14
+ runValidationTests(baseTests, 'countryCode')
43
15
  }
44
16
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -15,36 +14,8 @@ module.exports = {
15
14
  { name: 'Invalid date', type: 'date', value: '2020-13-30', error: 'date_notaDate' },
16
15
  { name: 'Valid DateTime ISO8601', type: 'date', value: '2020-10-17T16:34:50+02:00', expected: '2020-10-17T16:34:50+02:00' },
17
16
  { name: 'Invalid date with custom date format', type: 'date', dateFormat: 'mmm-xyt', value: '2020-13-30', error: 'date_notaDate' },
18
-
19
-
20
17
  ]
21
- _.forEach(baseTests, (test) => {
22
- it(test.name, (done) => {
23
- let fieldsToCheck = {
24
- params: {
25
- date: _.get(test, 'value')
26
- },
27
- fields: [
28
- { field: 'date', type: _.get(test, 'type'), required: _.get(test, 'required'), dateFormat: _.get(test, 'dateFormat') }
29
- ]
30
- }
31
-
32
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
33
- if (_.get(r, 'error')) {
34
- expect(_.get(r, 'error.message')).to.equal(test.error)
35
- if (_.get(test, 'additionalInfo')) {
36
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
37
- }
38
- }
39
- else {
40
- expect(_.get(r, 'params.date')).to.equal(_.get(test, 'expected'))
41
- }
42
- return done()
43
- })
44
-
45
- })
46
-
47
-
48
18
 
19
+ runValidationTests(baseTests, 'date')
49
20
  }
50
21
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -12,34 +11,6 @@ module.exports = {
12
11
  { name: 'Valid email', type: 'email', value: 'jane.doe+mediahub002@admiralcloud.com', expected: 'jane.doe+mediahub002@admiralcloud.com' },
13
12
  ]
14
13
 
15
-
16
- _.forEach(baseTests, (test) => {
17
- it(test.name, (done) => {
18
- let fieldsToCheck = {
19
- params: {
20
- email: _.get(test, 'value')
21
- },
22
- fields: [
23
- { field: 'email', type: _.get(test, 'type'), required: _.get(test, 'required') }
24
- ]
25
- }
26
-
27
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
28
- if (_.get(r, 'error')) {
29
- expect(_.get(r, 'error.message')).to.equal(test.error)
30
- if (_.get(test, 'additionalInfo')) {
31
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
32
- }
33
- }
34
- else {
35
- expect(_.get(r, 'params.email')).to.equal(_.get(test, 'expected'))
36
- }
37
- return done()
38
- })
39
-
40
- })
41
-
42
-
43
-
14
+ runValidationTests(baseTests, 'email')
44
15
  }
45
16
  }
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -11,36 +10,7 @@ module.exports = {
11
10
  { name: 'AdminLevel not sufficient, omit fields', omitFields: true, type: 'string', value: 'abc', adminLevel: 10, expected: undefined }
12
11
  ]
13
12
 
14
-
15
- _.forEach(baseTests, (test) => {
16
- it(test.name, (done) => {
17
- let fieldsToCheck = {
18
- adminLevel: 4,
19
- omitFields: _.get(test, 'omitFields'),
20
- params: {
21
- errorField: _.get(test, 'value'),
22
- },
23
- fields: [
24
- { field: 'errorField', type: _.get(test, 'type'), required: _.get(test, 'required'), adminLevel: _.get(test, 'adminLevel') }
25
- ]
26
- }
27
-
28
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
29
- if (_.get(r, 'error')) {
30
- expect(_.get(r, 'error.message')).to.equal(test.error)
31
- if (_.get(test, 'additionalInfo')) {
32
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
33
- }
34
- }
35
- else {
36
- expect(_.get(r, 'params.email')).to.equal(_.get(test, 'expected'))
37
- }
38
- return done()
39
- })
40
-
41
- })
42
-
43
-
44
-
13
+ runValidationTests(baseTests, 'errorField', { adminLevel: 4 })
45
14
  }
46
15
  }
16
+
@@ -1,5 +1,4 @@
1
- const _ = require('lodash')
2
- const sanitizer = require('../../index')
1
+ const { runValidationTests } = require('./helper')
3
2
 
4
3
  module.exports = {
5
4
 
@@ -11,34 +10,6 @@ module.exports = {
11
10
  { name: 'Invalid fileExtension', type: 'fileExtension', value: 'xxx', error: 'fileExtension_notAValidFileExtension' },
12
11
  ]
13
12
 
14
-
15
- _.forEach(baseTests, (test) => {
16
- it(test.name, (done) => {
17
- let fieldsToCheck = {
18
- params: {
19
- fileExtension: _.get(test, 'value')
20
- },
21
- fields: [
22
- { field: 'fileExtension', type: _.get(test, 'type'), required: _.get(test, 'required') }
23
- ]
24
- }
25
-
26
- let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
27
- if (_.get(r, 'error')) {
28
- expect(_.get(r, 'error.message')).to.equal(test.error)
29
- if (_.get(test, 'additionalInfo')) {
30
- expect(_.get(r, 'error.additionalInfo')).to.equal(_.get(test, 'additionalInfo'))
31
- }
32
- }
33
- else {
34
- expect(_.get(r, 'params.fileExtension')).to.equal(_.get(test, 'expected'))
35
- }
36
- return done()
37
- })
38
-
39
- })
40
-
41
-
42
-
13
+ runValidationTests(baseTests, 'fileExtension')
43
14
  }
44
15
  }