service-geoip
Version:
A RabbitMQ microservice wrapping the node-geoip package (geoip-lite on npm).
48 lines (41 loc) • 1.29 kB
JavaScript
var amqp = require('bunnymq')().producer,
uuid = require('node-uuid'),
request = require('request'),
config = require('../config.js');
describe('service geo:ip', function() {
beforeAll(function(done) {
config.queue = uuid.v4();
require('../index');
done();
});
it('should be able to ask for a french IP and get a valid answer', function(done) {
amqp.produce(config.queue, '85.69.30.121', { rpc: true })
.then(function(geo) {
expect(typeof geo).toBe('object');
expect(geo.country).toBe('FR');
})
.then(done);
});
it('should be able to ask for an invalid IP and get a blank answer', function(done) {
amqp.produce(config.queue, '127.0.0.1', { rpc: true })
.then(function(geo) {
expect(geo).toBe(null);
})
.then(done);
});
it('should be able to ask for nothing (blank object) and get a blank answer', function(done) {
amqp.produce(config.queue, {}, { rpc: true })
.then(function(geo) {
expect(geo).toBe(null);
})
.then(done);
});
it('should expose a healthcheck URL on port 3000', function(done) {
request('http://localhost:3000', function (error, response) {
if (!error && response.statusCode == 200) {
return done();
}
done(error);
});
});
});