Skip to content

Instantly share code, notes, and snippets.

@harveyslash
Created January 11, 2017 18:29
Show Gist options
  • Save harveyslash/f90c039ce370484d15dffaec44249395 to your computer and use it in GitHub Desktop.
Save harveyslash/f90c039ce370484d15dffaec44249395 to your computer and use it in GitHub Desktop.
/**
* Created by harshvardhangupta on 07/01/17.
*/
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('../../bin/www');
let group = require('../../core/group/model');
let Joi = require('joi');
let should = chai.should();
describe("Group model", function () {
it('should add a dummy group to database, and overwrite the _id field', function (done) {
console.log(new ObjectID());
let testGroup = new group({name: 'bleh', admin: "me",users:[{
_id: new ObjectID(),
},{
_id:new ObjectID(),
isAdmina:false
}]});
testGroup.save().then(function (data) {
// data.should.have.all.keys(['name', '_id']);
done();
}).catch(function (err) {
done(err);
});
});
it("should check for validation of group schema", function (done) {
const schema = Joi.object().keys({
name: Joi.string().required(),
users: Joi.array().required().items(Joi.object().keys({
_id: Joi.required(),
isAdmin: Joi.boolean(),
})
)
});
let testGroup = {
name: 'my name',
users: [{_id: '134fasdf',isAdmin:true}]
};
console.log(Joi.validate(testGroup, schema,{stripUnknown:true}).value);
should.equal(Joi.validate(testGroup, schema,{stripUnknown:undefined}).error,null);
done();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment