Browse Source

test cases for simplified joi

modified-method-api
ojizero 4 years ago
parent
commit
c0bf238d1c
No known key found for this signature in database
GPG Key ID: FEBB7097845B0C7E
  1. 4
      README.md
  2. 78
      test/simplified-joi.spec.ts
  3. 12
      test/validation.spec.ts

4
README.md

@ -348,11 +348,11 @@ This is still a work in progress :D any help is appreciated @@ -348,11 +348,11 @@ This is still a work in progress :D any help is appreciated
- [x] More on external API
- [ ] Support non JSON payload
- [ ] Get `onError: resolve` to work
- [ ] Support simplified form for validation
- [x] Support simplified form for validation
- [x] Finalize behvaiour of genreator method functions
- [x] What to do with their arguments (ambiguity of options/payload/querystring in args)
- [x] Document RouteFunction behvaiour
- [ ] ...
- [ ] Browser support through Ky ?
## License

78
test/simplified-joi.spec.ts

@ -1,19 +1,49 @@ @@ -1,19 +1,49 @@
/// <reference path='typings/globals.d.ts' />
import Joi from 'joi'
import transformSchema from '../src/simplified-joi'
import Joi from 'joi';
describe('Transform simplified validation schema to Joi schemas', () => {
it.skip('should pass on `string` type', () => {
//
it('passes on `string` type', () => {
const joiString = Joi.string().required()
expect(transformSchema('string'))
.to.deep.equal(joiString)
})
it('passes on `string|notrequired` type', () => {
const joiString = Joi.string()
expect(transformSchema('string|notrequired'))
.to.deep.equal(joiString)
})
it('passes on `number` type', () => {
const joiNumber = Joi.number().required()
expect(transformSchema('number'))
.to.deep.equal(joiNumber)
})
it.skip('should pass on `number` type', () => {
//
it('passes on `number|notrequired` type', () => {
const joiNumber = Joi.number()
expect(transformSchema('number|notrequired'))
.to.deep.equal(joiNumber)
})
it.skip('should pass on `symbol` type', () => {
//
it('passes on `symbol` type', () => {
const joiSymbol = Joi.symbol().required()
expect(transformSchema('symbol'))
.to.deep.equal(joiSymbol)
})
it('passes on `symbol|notrequired` type', () => {
const joiSymbol = Joi.symbol()
expect(transformSchema('symbol|notrequired'))
.to.deep.equal(joiSymbol)
})
it('fails on undefined types', () => {
@ -21,16 +51,36 @@ describe('Transform simplified validation schema to Joi schemas', () => { @@ -21,16 +51,36 @@ describe('Transform simplified validation schema to Joi schemas', () => {
.to.throw()
})
it.skip('transforms array schemas', () => {
//
})
it('transforms array schemas', () => {
const joiArray = Joi.array().ordered(
Joi.string().required(),
Joi.number().required(),
Joi.number(),
Joi.string(),
).required()
it.skip('transforms object schemas', () => {
//
expect(transformSchema([
'string',
'number',
'number|notrequired',
'string|notrequired',
]))
.to.deep.equal(joiArray)
})
it.skip('passes `notrequired` option to schemas', () => {
//
it('transforms object schemas', () => {
const joiObject = Joi.object({
numberKey: Joi.number().required(),
stringOptional: Joi.string(),
someArray: Joi.array().ordered(Joi.string().required(), Joi.number()).required(),
}).required()
expect(transformSchema({
numberKey: 'number',
stringOptional: 'string|notrequired',
someArray: ['string', 'number|notrequired'],
}))
.to.deep.equal(joiObject)
})
it('passes `raw` option to schemas', () => {

12
test/validation.spec.ts

@ -14,6 +14,10 @@ const customValidator = { @@ -14,6 +14,10 @@ const customValidator = {
}
}
const simplifiedSchema = {
correctKey: 'string',
}
const validData = {
correctKey: 'correctValue'
}
@ -47,13 +51,15 @@ describe('Ensure valid data', () => { @@ -47,13 +51,15 @@ describe('Ensure valid data', () => {
})
})
describe.skip('Using simplified schemas', () => {
describe('Using simplified schemas', () => {
it('passes valid data', () => {
//
expect(() => ensureValidData(simplifiedSchema, validData))
.to.not.throw()
})
it('rejects invalid data', () => {
//
expect(() => ensureValidData(simplifiedSchema, invalidData))
.to.throw()
})
})
})

Loading…
Cancel
Save