Last active
July 17, 2020 14:39
-
-
Save crizstian/5459225fbe0b21fd3d349b69372bcb4f to your computer and use it in GitHub Desktop.
Example of testing joi validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env mocha */ | |
const test = require('assert') | |
const {validate} = require('./') | |
console.log(Object.getPrototypeOf(validate)) | |
describe('Schemas Validation', () => { | |
it('can validate a booking object', (done) => { | |
const now = new Date() | |
now.setDate(now.getDate() + 1) | |
const testBooking = { | |
city: 'Morelia', | |
cinema: 'Plaza Morelia', | |
movie: 'Assasins Creed', | |
schedule: now, | |
cinemaRoom: 7, | |
seats: ['45'], | |
totalAmount: 71 | |
} | |
validate(testBooking, 'booking') | |
.then(value => { | |
console.log('validated') | |
console.log(value) | |
done() | |
}) | |
.catch(err => { | |
console.log(err) | |
done() | |
}) | |
}) | |
it('can validate a user object', (done) => { | |
const testUser = { | |
name: 'Cristian', | |
lastName: 'Ramirez', | |
email: 'cristiano@nupp.com', | |
creditCard: '1111222233334444', | |
membership: '7777888899990000' | |
} | |
validate(testUser, 'user') | |
.then(value => { | |
console.log('validated') | |
console.log(value) | |
done() | |
}) | |
.catch(err => { | |
console.log(err) | |
done() | |
}) | |
}) | |
it('can validate a ticket object', (done) => { | |
const testTicket = { | |
cinema: 'Plaza Morelia', | |
schedule: new Date(), | |
movie: 'Assasins Creed', | |
seats: ['35'], | |
cinemaRoom: 1, | |
orderId: '34jh1231ll' | |
} | |
validate(testTicket, 'ticket') | |
.then(value => { | |
console.log('validated') | |
console.log(value) | |
done() | |
}) | |
.catch(err => { | |
console.log(err) | |
done() | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment