Browse Source

test cases for simplified joi

tags/v1.0.0-alpha.2
ojizero 1 year ago
parent
commit
c0bf238d1c
No account linked to committer's email address
3 changed files with 75 additions and 19 deletions
  1. 2
    2
      README.md
  2. 64
    14
      test/simplified-joi.spec.ts
  3. 9
    3
      test/validation.spec.ts

+ 2
- 2
README.md View File

@@ -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


+ 64
- 14
test/simplified-joi.spec.ts View File

@@ -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', () => {
.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', () => {

+ 9
- 3
test/validation.spec.ts View File

@@ -14,6 +14,10 @@ const customValidator = {
}
}

const simplifiedSchema = {
correctKey: 'string',
}

const validData = {
correctKey: 'correctValue'
}
@@ -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