icebergh-hapi-mongo-models
Advanced tools
Comparing version 7.1.1 to 7.1.2
@@ -36,7 +36,7 @@ 'use strict'; | ||
console.log(`Creating indexes for ${model.collectionName}, ${JSON.stringify(model.indexes)}`); | ||
model.createIndexes.bind(model, model.indexes); | ||
}) | ||
.then(resp => console.log(resp)); | ||
model.createIndexes(model.indexes); | ||
}); | ||
await Promise.all(indexJobs); | ||
await Promise.all(indexJobs) | ||
.catch(err => server.log(['error', 'mongodb'], `Error when creating indexes: ${err}`)); | ||
@@ -43,0 +43,0 @@ server.log(['info', 'mongodb'], 'HapiMongoModels: finished processing auto indexes.'); |
{ | ||
"name": "icebergh-hapi-mongo-models", | ||
"version": "7.1.1", | ||
"version": "7.1.2", | ||
"description": "A hapi plugin for mongo-models", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "lab -c -L" | ||
"test": "lab -c" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
'use strict'; | ||
const Joi = require('joi'); | ||
const MongoModels = require('mongo-models'); | ||
const MongoModels = require('icebergh-mongo-models'); | ||
class Dummy extends MongoModels {} | ||
class Dummy extends MongoModels { | ||
} | ||
@@ -11,9 +12,9 @@ Dummy.collectionName = 'dummies'; | ||
Dummy.schema = Joi.object().keys({ | ||
name: Joi.string().required(), | ||
hasHat: Joi.boolean() | ||
name: Joi.string().required(), | ||
hasHat: Joi.boolean() | ||
}); | ||
Dummy.indexes = [ | ||
{ key: { name: 1 } }, | ||
{ key: { hasHat: -1 } } | ||
{ key: { name: 1 } }, | ||
{ key: { hasHat: -1 } } | ||
]; | ||
@@ -20,0 +21,0 @@ |
'use strict'; | ||
const Joi = require('joi'); | ||
const MongoModels = require('mongo-models'); | ||
const MongoModels = require('icebergh-mongo-models'); | ||
class NoIndex extends MongoModels {} | ||
class NoIndex extends MongoModels { | ||
} | ||
@@ -11,4 +12,4 @@ NoIndex.collectionName = 'noindexes'; | ||
NoIndex.schema = Joi.object().keys({ | ||
name: Joi.string().required(), | ||
hasHat: Joi.boolean() | ||
name: Joi.string().required(), | ||
hasHat: Joi.boolean() | ||
}); | ||
@@ -15,0 +16,0 @@ |
@@ -11,19 +11,19 @@ 'use strict'; | ||
const config = { | ||
mongodb: { | ||
connection: { | ||
uri: 'mongodb://localhost:27017/', | ||
db: 'hapi-mongo-models-test' | ||
}, | ||
options: {} | ||
mongodb: { | ||
connection: { | ||
uri: 'mongodb://admin:adminpass@localhost:27017/', | ||
db: 'hapi-mongo-models-test' | ||
}, | ||
models: [ | ||
Path.resolve(__dirname, 'fixtures/dummy-model'), | ||
Path.resolve(__dirname, 'fixtures/noindex-model') | ||
] | ||
options: {} | ||
}, | ||
models: [ | ||
Path.resolve(__dirname, 'fixtures/dummy-model'), | ||
Path.resolve(__dirname, 'fixtures/noindex-model') | ||
] | ||
}; | ||
const stub = { | ||
MongoModels: {} | ||
MongoModels: {} | ||
}; | ||
const HapiMongoModels = Proxyquire('..', { | ||
'mongo-models': stub.MongoModels | ||
'icebergh-mongo-models': stub.MongoModels | ||
}); | ||
@@ -34,90 +34,90 @@ | ||
lab.test('it throws an error when the db connection fails', async () => { | ||
lab.test('it throws an error when the db connection fails', async () => { | ||
const realConnect = stub.MongoModels.connect; | ||
const realConnect = stub.MongoModels.connect; | ||
stub.MongoModels.connect = function (connection, options) { | ||
stub.MongoModels.connect = function (connection, options) { | ||
throw Error('connect failed'); | ||
}; | ||
throw Error('connect failed'); | ||
}; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: config | ||
}; | ||
const throws = async function () { | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: config | ||
}; | ||
const throws = async function () { | ||
await server.register(plugin); | ||
}; | ||
await server.register(plugin); | ||
}; | ||
await Code.expect(throws()).to.reject(); | ||
await Code.expect(throws()).to.reject(); | ||
stub.MongoModels.connect = realConnect; | ||
}); | ||
stub.MongoModels.connect = realConnect; | ||
}); | ||
lab.test('it successfuly connects and exposes the plugin (default autoIndex value)', async () => { | ||
lab.test('it successfuly connects and exposes the plugin (default autoIndex value)', async () => { | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: config | ||
}; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: config | ||
}; | ||
await server.register(plugin); | ||
await server.start(); | ||
await server.register(plugin); | ||
await server.start(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
await server.stop(); | ||
}); | ||
await server.stop(); | ||
}); | ||
lab.test('it connects to the db and creates indexes during pre-start (autoIndex set manually)', async () => { | ||
lab.test('it connects to the db and creates indexes during pre-start (autoIndex set manually)', async () => { | ||
const configClone = JSON.parse(JSON.stringify(config)); | ||
const configClone = JSON.parse(JSON.stringify(config)); | ||
configClone.autoIndex = true; | ||
configClone.autoIndex = true; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: configClone | ||
}; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: configClone | ||
}; | ||
await server.register(plugin); | ||
await server.start(); | ||
await server.register(plugin); | ||
await server.start(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
await server.stop(); | ||
}); | ||
await server.stop(); | ||
}); | ||
lab.test('it connects to the db and skips creating indexes during pre-start (autoIndex set manually)', async () => { | ||
lab.test('it connects to the db and skips creating indexes during pre-start (autoIndex set manually)', async () => { | ||
const configClone = JSON.parse(JSON.stringify(config)); | ||
const configClone = JSON.parse(JSON.stringify(config)); | ||
configClone.autoIndex = false; | ||
configClone.autoIndex = false; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: configClone | ||
}; | ||
const server = Hapi.Server(); | ||
const plugin = { | ||
plugin: HapiMongoModels, | ||
options: configClone | ||
}; | ||
await server.register(plugin); | ||
await server.start(); | ||
await server.register(plugin); | ||
await server.start(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
Code.expect(server.plugins['hapi-mongo-models']).to.be.an.object(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
server.plugins['hapi-mongo-models']['mongo-models'].disconnect(); | ||
await server.stop(); | ||
}); | ||
await server.stop(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157
10026