Permalink
Browse files

Changes to mongo atlas (#674)

* Changes to mongo atlas

Update database.js to allow users to use a cluster with mongo atlas

* * Moved the regex to its own function
* Added test to check if the regex is valid

* * Renamed function names and updated test name
  • Loading branch information...
Tom5om authored and wingsbob committed Sep 13, 2018
1 parent a7f1a1b commit 759837ca8831c190ed8e043801e8d7bf87c0c927
Showing with 25 additions and 2 deletions.
  1. +2 −1 lib/agenda/database.js
  2. +9 −0 lib/agenda/has-mongo-protocol.js
  3. +14 −1 test/agenda.js
View
@@ -1,6 +1,7 @@
'use strict';
const {MongoClient} = require('mongodb');
const debug = require('debug')('agenda:database');
const hasMongoProtocol = require('./has-mongo-protocol');
/**
* Connect to the spec'd MongoDB server and database.
@@ -20,7 +21,7 @@ const debug = require('debug')('agenda:database');
*/
module.exports = function(url, collection, options, cb) {
const self = this;
if (!url.match(/^mongodb:\/\/.*/)) {
if (!hasMongoProtocol(url)) {
url = 'mongodb://' + url;
}
@@ -0,0 +1,9 @@
'use strict';
/**
* Given a mongo connection url will check if it contains the mongo
* @param url
* @returns {boolean}
*/
module.exports = function(url) {
return url.match(/mongodb(?:\+srv)?:\/\/.*/) !== null;
};
View
@@ -5,6 +5,7 @@ const {MongoClient} = require('mongodb');
const delay = require('delay');
const Agenda = require('..');
const Job = require('../lib/job');
const hasMongoProtocol = require('../lib/agenda/has-mongo-protocol');
const mongoHost = process.env.MONGODB_HOST || 'localhost';
const mongoPort = process.env.MONGODB_PORT || '27017';
@@ -74,6 +75,19 @@ describe('Agenda', () => {
});
describe('configuration methods', () => {
describe('mongo connection tester', () => {
it('passing a valid server connection string', () => {
expect(hasMongoProtocol(mongoCfg)).to.equal(true);
});
it('passing a valid multiple server connection string', () => {
expect(hasMongoProtocol('mongodb+srv://' + mongoHost + '/agenda-test')).to.equal(true);
});
it('passing an invalid connection string', () => {
expect(hasMongoProtocol(mongoHost + '/agenda-test')).to.equal(false);
});
});
describe('mongo', () => {
it('sets the _db directly', () => {
const agenda = new Agenda();
@@ -96,7 +110,6 @@ describe('Agenda', () => {
expect(jobs.name('test queue')).to.be(jobs);
});
});
describe('processEvery', () => {
it('sets the processEvery time', () => {
jobs.processEvery('3 minutes');

0 comments on commit 759837c

Please sign in to comment.