Skip to content

Commit

Permalink
Merge pull request #65 from Notastica/coverage
Browse files Browse the repository at this point in the history
more and more coverage
  • Loading branch information
Panthro authored Nov 9, 2016
2 parents 6106340 + b6c600d commit 763e976
Show file tree
Hide file tree
Showing 8 changed files with 3,390 additions and 15 deletions.
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ node_js:
- '5'
- '6'
before_install:
# Repo for newer Node.js versions
- curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# Repo for Yarn
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -qq
- sudo apt-get install -y -qq yarn
- docker pull elasticsearch:2
- docker pull rabbitmq:3
- docker run -d -p 9200:9200 -p 9300:9300 elasticsearch:2
- docker run -d -p 5671:5671 -p 5672:5672 -p 25672:25672 rabbitmq:3
- docker ps -a
cache:
directories:
- $HOME/.yarn-cache
install:
- npm install
- yarn
script:
- npm run check
- npm run build
- npm run validate
- yarn run check
- yarn run build
- yarn run validate
after_success:
- npm run coveralls
- yarn run coveralls
deploy:
provider: npm
email: panthro.rafael@gmail.com
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"audit"
],
"dependencies": {
"@google/maps": "^0.1.0",
"@google/maps": "^0.3.0",
"bluebird": "3.4.6",
"body-parser": "^1.15.2",
"chalk": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Module extends EventEmitter {
}

options = _.defaults(options, defaults);
if (!options instanceof Module) {
if (!(options instanceof Module)) {
logger.debug('Initializing module with options:', options);
}

Expand Down
16 changes: 9 additions & 7 deletions src/modules/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const elasticsearch = (options) => {
})
.then(() => {
return m.esClient.indices.exists({ index: options.messagesIndex })
.then(() => {
logger.info(`[${symbols.check}] ElasticSearch already exists [${options.messagesIndex}]`);
}).catch(() => {
return m.esClient.indices.create({ index: options.messagesIndex })
.then(() => {
logger.info(`[${symbols.check}] ElasticSearch index created [${options.messagesIndex}]`);
});
.then((exists) => {
if (exists) {
logger.info(`[${symbols.check}] ElasticSearch already exists [${options.messagesIndex}]`);
} else {
return m.esClient.indices.create({ index: options.messagesIndex })
.then(() => {
logger.info(`[${symbols.check}] ElasticSearch index created [${options.messagesIndex}]`);
});
}
});

})
Expand Down
50 changes: 50 additions & 0 deletions test/geocoding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,56 @@ describe('geocoding module', function () {

});

it('Should return the message with UNKNOWN location if passed an invalid address', function () {

const defaultOptions = {
registerQueue: `register-${uuid.v4()}`,
messagesQueue: `messages-${uuid.v4()}`
};

const apiKey = process.env.GAPI_KEY;
let mock = mockPersistence(defaultOptions);
const o = new Orchestrator(defaultOptions);
const m = geocoding(_.defaults({
apiKey: apiKey
}, defaultOptions));

mock.register().then((result) => {
mock = result;
}); // register mock async
return o.listen().then(() => {
return m.register();
}).then(() => {
const pub = o.amqpContext.socket('PUSH');
const message = { uuid: uuid.v4(), address: '' };

pub.connect(o.messagesQueue, () => {
pub.write(JSON.stringify(message));
});

return new Promise((resolve) => {
let mockReceivedCount = 2;

mock.on('data', () => {
if (--mockReceivedCount <= 0) {
if (Object.keys(mock.messages).length > 0) {
chai.expect(mock.messages).to.have.contains.key(message.uuid);
chai.expect(mock.messages[message.uuid]).to.contains.key('address');
chai.expect(mock.messages[message.uuid]).to.contains.key('location');
chai.expect(mock.messages[message.uuid].location).to.be.equal('UNKNOWN');
resolve();
}
}
});
});


});


});


it('Should query ES to avoid multiple calls for the same venue', function () {

const defaultOptions = {
Expand Down
43 changes: 43 additions & 0 deletions test/module.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as chai from 'chai';
import dirtyChai from 'dirty-chai';
import Module from '../src/module';
import logger from '../src/logging/logger';
import dockerNames from 'docker-names';

// TEST SETUP
Expand All @@ -22,6 +23,48 @@ describe('Module', function () {
});
});

it('Should log when a new module is being initialized with options', function (done) {

logger._test_debug = logger.debug;
logger.debug = function () {
if (arguments[0] === 'Initializing module with options:') {
// reset logger;
logger.debug = logger._test_debug;
done();
}
logger._test_debug.apply(logger, arguments);

};

const m = new Module({ service: 'testService' });

logger.info(`Module initialized [${m.service}]-[${m.name}]`);

});

it('Should NOT log when a new module is being initialized with Module', function (done) {

let m = new Module({ service: 'testService' });

logger._test_debug = logger.debug;
logger.debug = function () {
if (arguments[0] === 'Initializing module with options:') {
// reset logger;
logger.debug = logger._test_debug;
done(new Error('Module initialization with module should not be logged'));
}
logger._test_debug.apply(logger, arguments);

};

m = new Module(m);

logger.info(`Module initialized [${m.service}]-[${m.name}]`);
logger.debug = logger._test_debug;
done();

});

it('Should fail when a new property is added and not reflected in the test', function () {
const m = new Module('test-service-name');

Expand Down
18 changes: 17 additions & 1 deletion test/orchestrator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let o;
describe('Orchestrator', function () {

const registerMock = function () {
mock({
return mock({
registerQueue: o.registerQueue
}).register();
};
Expand Down Expand Up @@ -385,5 +385,21 @@ describe('Orchestrator', function () {
});
});

it('Should always only have 1 persistence module', function () {
registerMock();
return o.listen()
.then(() => {
chai.expect(o.modulesCollection.find({ type: 'persistence' }))
.to.have.lengthOf(1);
return registerMock()
.then((newModule) => {
const registeredModules = o.modulesCollection.find({ type: 'persistence' });

chai.expect(registeredModules).to.have.lengthOf(1);
chai.expect(registeredModules[0].name).to.be.equal(newModule.name);
});
});
});

})
;
Loading

0 comments on commit 763e976

Please sign in to comment.