api-cli/tests/lint.test.js
2021-07-07 22:20:14 +02:00

33 lines
1.8 KiB
JavaScript

const assert = require('assert').strict
const logging = require('../src/logging')
const expect = require('chai').expect
const linter = require('../src/linter')
logging.init(-1)
describe('linter validators', () => {
it('creates an error on required property', () => {
expect(linter.validators.required()('path', '')).to.not.be.empty
expect(linter.validators.required()('path', null)).to.not.be.empty
expect(linter.validators.required()('path', undefined)).to.not.be.empty
expect(linter.validators.required()('path', ' ')).to.not.be.empty
})
it('creates an error on to small strings for length validator', () => {
expect(linter.validators.length({ min: 4 })('path', '')).to.not.be.empty
expect(linter.validators.length({ min: 4 })('path', null)).to.not.be.empty
expect(linter.validators.length({ min: 4 })('path', undefined)).to.not.be.empty
expect(linter.validators.length({ min: 4 })('path', '123')).to.not.be.empty
})
it('creates an error on too large strings for length validator', () => {
expect(linter.validators.length({ max: 4 })('path', '')).to.be.undefined
expect(linter.validators.length({ max: 4 })('path', null)).to.be.undefined
expect(linter.validators.length({ max: 4 })('path', undefined)).to.be.undefined
expect(linter.validators.length({ max: 4 })('path', '12345')).to.not.be.empty
expect(linter.validators.length({ max: 4 })('path', ' 1 ')).to.be.undefined
})
it('creates an error when string does not match regex', () => {
expect(linter.validators.regex(/[0-9]+/)('path', 'abcdef')).to.not.be.empty
expect(linter.validators.regex(/[0-9]+/)('path', ' ')).to.not.be.empty
expect(linter.validators.regex(/.+/)('path', ' ')).to.not.be.empty
})
})