mirror of
https://github.com/Cameri/nostream.git
synced 2025-04-02 08:58:20 +02:00
33 lines
1001 B
TypeScript
33 lines
1001 B
TypeScript
import { expect } from 'chai'
|
|
import Joi from 'joi'
|
|
|
|
import { attemptValidation, validateSchema } from '../../../src/utils/validation'
|
|
|
|
describe('attemptValidation', () => {
|
|
it('returns value if given value matches schema', () => {
|
|
const schema = Joi.string()
|
|
|
|
expect(attemptValidation(schema)('string')).to.equal('string')
|
|
})
|
|
|
|
it('throws error if given value does not match schema', () => {
|
|
const schema = Joi.string()
|
|
|
|
expect(() => attemptValidation(schema)(1)).to.throw(Joi.ValidationError)
|
|
})
|
|
})
|
|
|
|
describe('validateSchema', () => {
|
|
it('returns value property with given value if it matches schema', () => {
|
|
const schema = Joi.string()
|
|
|
|
expect(validateSchema(schema)('string')).to.have.property('value', 'string')
|
|
})
|
|
|
|
it('returns error property with ValidationError if given value does not match schema', () => {
|
|
const schema = Joi.string()
|
|
|
|
expect(validateSchema(schema)(1)).to.have.property('error').and.be.an.instanceOf(Joi.ValidationError)
|
|
})
|
|
})
|