Skip to content

Commit

Permalink
Merge pull request #6 from amio-io/5-different-file-structure
Browse files Browse the repository at this point in the history
feat: Different file structure #5
  • Loading branch information
javiertrancoso authored Dec 18, 2019
2 parents 87ea833 + b30e2be commit aafb6fc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.SchemaValidatorError = require('./src/errors/schema-validator-error')
module.exports.AsyncValidator = require('./src/async-validator')
module.exports.SchemaValidator = require('./src/schema-validator')
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-validations-lib",
"version": "1.0.0",
"version": "1.1.0",
"scripts": {
"test-units": "cross-env BUILD_ENV=test DEBUG=amio* mocha test/test_unit/**/*.test.js --reporter mocha-multi-reporters --reporter-options configFile=test/mocha-reporters-config.json",
"can-publish-nix": "npm info $npm_package_name version | npm-version-bump-checker",
Expand Down
3 changes: 2 additions & 1 deletion src/async-validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const convertValidationError = require("./utils/validation-errors-converter");
const {convertValidationError} = require("./utils/validation-errors-converter");

class AsyncValidator {

// noinspection JSUnusedLocalSymbols
async validate(data) {
throw Error('validate() must be implemented in children')
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validation-errors-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function convertValidationError(error) {
return new SchemaValidatorError(`Property '${params.additionalProperty}' is not supported.`,
errorObject.dataPath + '.' + params.additionalProperty)
case 'required': {
const fieldPath = (errorObject.dataPath) ? errorObject.dataPath : '.'
const fieldPath = errorObject.dataPath || '.'
return new SchemaValidatorError(`Missing property '${params.missingProperty}'.`, fieldPath)
}
case 'const':
Expand Down
4 changes: 2 additions & 2 deletions test/test_unit/async-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('async-validator test', async () => {
})

it('Validation failed', async () => {
const result = asyncValidatorTest.validate({valid: false})
await expect(result).to.be.rejectedWith('expected "valid" to be true').eventually.include({
const validateFn = asyncValidatorTest.validate({valid: false})
await expect(validateFn).to.be.rejectedWith('expected "valid" to be true').eventually.include({
message: 'expected "valid" to be true',
field: 'valid',
rejected_value: false
Expand Down

0 comments on commit aafb6fc

Please sign in to comment.