mirror of https://github.com/ojizero/portal
2 changed files with 50 additions and 1 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/// <reference path='typings/globals.d.ts' />
|
||||
|
||||
import { ensureValidData } from '../src/validation' |
||||
|
||||
import Joi, { valid } from 'joi' |
||||
|
||||
const joiSchema = Joi.object({ |
||||
correctKey: Joi.strict().required() |
||||
}).required() |
||||
|
||||
const customValidator = { |
||||
validate (data) { |
||||
return 'correctKey' in data |
||||
} |
||||
} |
||||
|
||||
const validData = { |
||||
correctKey: 'correctValue' |
||||
} |
||||
|
||||
const invalidData = { |
||||
incorrectKey: 'some value', |
||||
} |
||||
|
||||
describe('ensureValidData', () => { |
||||
describe('Using Joi schemas', () => { |
||||
it('passes valid data', () => { |
||||
expect(() => ensureValidData(joiSchema, validData)) |
||||
.to.not.throw() |
||||
}) |
||||
|
||||
it('rejects invalid data', () => { |
||||
expect(() => ensureValidData(joiSchema, invalidData)) |
||||
.to.throw() |
||||
}) |
||||
}) |
||||
|
||||
describe('Using custom validators', () => { |
||||
it('passes valid data', () => { |
||||
expect(() => ensureValidData(customValidator, validData)) |
||||
.to.not.throw() |
||||
}) |
||||
|
||||
it('rejects invalid data', () => { |
||||
expect(() => ensureValidData(customValidator, invalidData)) |
||||
.to.throw() |
||||
}) |
||||
}) |
||||
}) |
Loading…
Reference in new issue