Skip to content

Commit

Permalink
added ability to define Joi.object() in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
ShurakaiSoft committed May 18, 2016
1 parent f4ed4e5 commit 0632575
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/adapters/mongodb/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = function() {
'buffer': Buffer,
'boolean': Boolean,
'array': Array,
'any': Object
'any': Object,
'object': Object
}

mongooseSchema.type = 'string'
Expand Down
47 changes: 47 additions & 0 deletions test/converters.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict'

// dependencies
const Joi = require('joi')
const Mongoose = require('mongoose')

const config = require('./config')


// module under test
const converters = require('../lib/adapters/mongodb/converters')()


describe('Unit tests for converters module', function () {
let db

before(function () {
return new Promise((resolve, reject) => {
Mongoose.connect(config.mongodbUrl)

db = Mongoose.connection
db.on('error', reject)
db.on('open', resolve)
})
})

after(function () {
return db && db.close()
})

describe('funciton toMongooseModel', function () {

it('should exist as a funciton', function () {
expect(converters.toMongooseModel).to.be.a.Function
})

it('should not fail when Joi.object() types are used in a schema', function () {
const hhSchema = {
type: 'testObject',
attributes: {
anObject: Joi.object()
}
}
expect(converters.toMongooseModel(db, hhSchema)).to.be.a.Function
})
})
})

0 comments on commit 0632575

Please sign in to comment.