update constructor, add option validation tests

This commit is contained in:
2016-04-14 15:03:29 -07:00
parent 83823ebdf0
commit 5619612943
3 changed files with 60 additions and 13 deletions

View File

@@ -1,12 +1,38 @@
class User {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
import events from 'events';
import Joi from 'joi';
getName() {
return `${this.firstName} ${this.lastName}`
export default class Elastique extends events.EventEmitter {
constructor(options = {}) {
super();
var schema = Joi.object({
url: Joi.string().uri({ scheme: ['http', 'https'] }).default('http://localhost:9200'),
index: Joi.string().required(),
interval: Joi.string().default('1w'),
timeout: Joi.number().min(10000).default(10000),
}).default();
const validateSchema = () => new Promise(function (resolve, reject) {
schema.validate(options, (err, settings) => {
if (err) return reject(err);
resolve(settings);
})
})
this.ready = true;
Promise.all([
validateSchema()
])
.then(([ settings ]) => {
console.log('settings', settings);
this.settings = settings;
})
.catch((err) => {
this.ready = false;
this.emit('error', err);
throw err;
});
}
}
export default User;