diff options
author | eug-vs <eug-vs@keemail.me> | 2020-12-02 04:10:15 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-12-02 04:10:36 +0300 |
commit | 6f52408e7bf79730df9eb7b487dcacf468e409e1 (patch) | |
tree | 0bc1caf00ad8a95ac4faa438ff2f848529d36a2b /test/utils | |
parent | 40ffcc5e78f5ee41353e383ca25b81134084ab9f (diff) | |
download | mongo-cronjob-6f52408e7bf79730df9eb7b487dcacf468e409e1.tar.gz |
test: Event model
Diffstat (limited to 'test/utils')
-rw-r--r-- | test/utils/dbConnection.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/utils/dbConnection.ts b/test/utils/dbConnection.ts new file mode 100644 index 0000000..ee1e9e0 --- /dev/null +++ b/test/utils/dbConnection.ts @@ -0,0 +1,26 @@ +import mongoose from 'mongoose'; +import Promise from 'bluebird'; + +mongoose.Promise = Promise; + +const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/mongo-cronjob-test'; +const { MONGODB_USER, MONGODB_PASSWORD } = process.env; + +mongoose.connect(MONGODB_URL, { + user: MONGODB_USER, + pass: MONGODB_PASSWORD, + useNewUrlParser: true, + useUnifiedTopology: true, + useCreateIndex: true, + useFindAndModify: false, + family: 4 // Use IPv4, skip trying IPv6 +}); + +const db = mongoose.connection; +db.on('error', console.error.bind(console, 'connection error:')); +db.once('open', () => { + console.log('Connection to MongoDB successful'); +}); + +export default db; + |