Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loadSchemasFrom to be an index of schemas, upgrade versions. #23

Merged
merged 12 commits into from
Apr 28, 2020
Prev Previous commit
remove deprecation warning from test output
  • Loading branch information
nakardo committed Apr 28, 2020
commit 481e37618ddc1c90344e6753b411bfa97638cf46
88 changes: 60 additions & 28 deletions test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const { expect } = require('@hapi/code');

const { connected } = Mongoose.STATES;

const options = {
useUnifiedTopology: true
};

const lab = exports.lab = require('@hapi/lab').script();
const { describe, it } = lab;

Expand All @@ -17,15 +21,17 @@ it('can be registered once', async () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
}
}
},
{
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test-2'
uri: 'mongodb://localhost:27017/test-2',
options
}
}
}
Expand All @@ -44,7 +50,8 @@ describe('connection', () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'http://google.com'
uri: 'http://google.com',
options
}
}
};
Expand All @@ -60,7 +67,8 @@ describe('connection', () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017,localhost:27018/test?replicaSet=rs0'
uri: 'mongodb://localhost:27017,localhost:27018/test?replicaSet=rs0',
options
}
}
};
Expand All @@ -76,6 +84,7 @@ describe('connection', () => {
connection: {
uri: 'mongodb://localhost:27017/test-auth',
options: {
...options,
auth: {
user: 'user',
password: 'password'
Expand All @@ -94,7 +103,8 @@ describe('connection', () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
}
}
};
Expand All @@ -116,13 +126,14 @@ describe('connection', () => {
expect(models).to.be.empty();
});

it('adds useNewUrlParser by default on mongooseOptions', async () => {
it('adds useNewUrlParser by default on options', async () => {

const plugin = {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
}
}
};
Expand All @@ -146,7 +157,8 @@ describe('connection', () => {
options: {
connection: {
alias: 'test-db',
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
}
}
};
Expand All @@ -167,7 +179,8 @@ describe('connection', () => {
options: {
connection: {
uri: 'mongodb://localhost:27017/test',
loadSchemasFrom: ['test/schemas/empty.json']
loadSchemasFrom: ['test/schemas/empty.json'],
options
}
}
};
Expand All @@ -184,7 +197,8 @@ describe('connection', () => {
options: {
connection: {
uri: 'mongodb://localhost:27017/test',
loadSchemasFrom: ['test/schemas/fns/invalid-fn.js']
loadSchemasFrom: ['test/schemas/fns/invalid-fn.js'],
options
}
}
};
Expand All @@ -208,7 +222,8 @@ describe('connection', () => {
'!**/invalid-fn.js',
'!test/schemas/fns/admin.js',
'!test/schemas/package/index.js'
]
],
options
}
}
};
Expand All @@ -230,7 +245,8 @@ describe('connection', () => {
options: {
connection: {
uri: 'mongodb://localhost:27017/test',
loadSchemasFrom: ['test/schemas/fns/admin.js']
loadSchemasFrom: ['test/schemas/fns/admin.js'],
options
}
}
};
Expand Down Expand Up @@ -258,7 +274,8 @@ describe('connection', () => {
'!**/*.json',
'!**/invalid-fn.js',
'!test/schemas/package/index.js'
]
],
options
}
}
};
Expand All @@ -280,7 +297,8 @@ describe('connection', () => {
options: {
connection: {
uri: 'mongodb://localhost:27017/test',
loadSchemasFrom: ['test/schemas/fns/admin.js']
loadSchemasFrom: ['test/schemas/fns/admin.js'],
options
}
}
};
Expand Down Expand Up @@ -315,7 +333,8 @@ describe('connection', () => {
options: {
connection: {
uri: 'mongodb://localhost:27017/test',
loadSchemasFrom: require('./schemas/package')
loadSchemasFrom: require('./schemas/package'),
options
}
}
};
Expand All @@ -336,7 +355,8 @@ describe('connection', () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
},
decorations: ['server']
}
Expand All @@ -355,7 +375,8 @@ describe('connection', () => {
plugin: HapiMongoose,
options: {
connection: {
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/test',
options
},
decorations: ['server']
}
Expand Down Expand Up @@ -399,7 +420,8 @@ describe('connection', () => {
'!**/*.json',
'!**/invalid-fn.js',
'!test/schemas/package/index.js'
]
],
options
}
}
};
Expand Down Expand Up @@ -429,10 +451,12 @@ describe('connections', () => {
options: {
connections: [
{
uri: 'mongodb://localhost:27017/test-1'
uri: 'mongodb://localhost:27017/test-1',
options
},
{
uri: 'mongodb://localhost:27017/test-2'
uri: 'mongodb://localhost:27017/test-2',
options
}
]
}
Expand Down Expand Up @@ -467,10 +491,12 @@ describe('connections', () => {
connections: [
{
alias: 'test-db',
uri: 'mongodb://localhost:27017/test-1'
uri: 'mongodb://localhost:27017/test-1',
options
},
{
uri: 'mongodb://localhost:27017/test-2'
uri: 'mongodb://localhost:27017/test-2',
options
}
]
}
Expand All @@ -496,11 +522,13 @@ describe('connections', () => {
connections: [
{
uri: 'mongodb://localhost:27017/test-1',
loadSchemasFrom: ['test/**/animal.js']
loadSchemasFrom: ['test/**/animal.js'],
options
},
{
uri: 'mongodb://localhost:27017/test-2',
loadSchemasFrom: ['test/**/blog.js']
loadSchemasFrom: ['test/**/blog.js'],
options
}
]
}
Expand All @@ -525,10 +553,12 @@ describe('connections', () => {
options: {
connections: [
{
uri: 'mongodb://localhost:27017/test-1'
uri: 'mongodb://localhost:27017/test-1',
options
},
{
uri: 'mongodb://localhost:27017/test-2'
uri: 'mongodb://localhost:27017/test-2',
options
}
],
decorations: ['server']
Expand All @@ -553,10 +583,12 @@ describe('connections', () => {
options: {
connections: [
{
uri: 'mongodb://localhost:27017/test-1'
uri: 'mongodb://localhost:27017/test-1',
options
},
{
uri: 'mongodb://localhost:27017/test-2'
uri: 'mongodb://localhost:27017/test-2',
options
}
],
decorations: ['server']
Expand Down