Skip to content

Commit

Permalink
passing tests for geolocation IP url
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjay committed Nov 19, 2013
1 parent 2103004 commit 109c0cb
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/spec/geolocate-ip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@
* Created by mattjohansen on 11/18/13.
*/
var geoip = require('../scripts/geolocate-ip.coffee');
var HttpClient = require('scoped-http-client');

describe('geolocation', function() {
var robot, msg = null;

beforeEach(function(){
robot = {
respond: function(regex, callback){},
http: function(url){
//HttpClient.create(url);
}
}
spyOn(robot, 'respond').andCallThrough();
spyOn(robot, 'http').andCallFake(function(){
var url = robot.http.mostRecentCall.args[0];
var client = HttpClient.create(url);
spyOn(client, 'get').andReturn(function(){});
return client
});
geoip(robot);
msg = {
match: 'geolocate 1.2.3.4'.match(robot.respond.mostRecentCall.args[0]),
send: function() {}
}
});

it('should be a function', function(){
expect(typeof(geoip)).toBe('function');
});

it('should call respond when called', function() {
var robot = {
respond: function(){}
};

spyOn(robot, 'respond');
geoip(robot);
it('should generate the correct URL', function() {
expect(robot.respond).toHaveBeenCalled();
console.log(robot.respond.mostRecentCall.args[1]);
robot.respond.mostRecentCall.args[1](msg);
expect(robot.http).toHaveBeenCalled();
expect(robot.http.mostRecentCall.args[0]).toBeDefined();
expect(robot.http.mostRecentCall.args[0]).toBe('http://api.hostip.info/get_json.php?ip=1.2.3.4')
});

//TODO: Need a way to call robot. Not sure how to do this without access to hubot itself.

});

0 comments on commit 109c0cb

Please sign in to comment.