From b3efcfe75d956525a771ea57dd8e26a83b7005ac Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 18 Nov 2013 15:29:00 -0600 Subject: [PATCH 1/4] basic passing test for geolocate-ip script. --- src/spec/geolocate-ip.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/spec/geolocate-ip.spec.js b/src/spec/geolocate-ip.spec.js index 41d6e45..5194cd4 100644 --- a/src/spec/geolocate-ip.spec.js +++ b/src/spec/geolocate-ip.spec.js @@ -1,3 +1,12 @@ /** * Created by mattjohansen on 11/18/13. */ +var geoip = require('../scripts/geolocate-ip.coffee'); + +describe('geolocation', function() { + + it('should be a function', function(){ + expect(typeof(geoip)).toBe('function'); + }) + +}); \ No newline at end of file From 210300406b09424d14d683d7ed8db06f4d36ac62 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 18 Nov 2013 16:01:06 -0600 Subject: [PATCH 2/4] added another test. kind of stuck on how to test if it actually works as expected though. --- src/spec/geolocate-ip.spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/spec/geolocate-ip.spec.js b/src/spec/geolocate-ip.spec.js index 5194cd4..081538e 100644 --- a/src/spec/geolocate-ip.spec.js +++ b/src/spec/geolocate-ip.spec.js @@ -7,6 +7,18 @@ describe('geolocation', 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); + expect(robot.respond).toHaveBeenCalled(); + }); + + //TODO: Need a way to call robot. Not sure how to do this without access to hubot itself. }); \ No newline at end of file From 109c0cbb7392175b0c81b8bd7e9f3f7cf98b29ff Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 18 Nov 2013 18:26:06 -0600 Subject: [PATCH 3/4] passing tests for geolocation IP url --- src/spec/geolocate-ip.spec.js | 38 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/spec/geolocate-ip.spec.js b/src/spec/geolocate-ip.spec.js index 081538e..98798b9 100644 --- a/src/spec/geolocate-ip.spec.js +++ b/src/spec/geolocate-ip.spec.js @@ -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. - }); \ No newline at end of file From 6491e81bcd0af5e5770a7fd72412adff022d88e9 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 19 Nov 2013 12:01:31 -0600 Subject: [PATCH 4/4] added a TODO --- src/spec/geolocate-ip.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spec/geolocate-ip.spec.js b/src/spec/geolocate-ip.spec.js index 98798b9..ea4e00d 100644 --- a/src/spec/geolocate-ip.spec.js +++ b/src/spec/geolocate-ip.spec.js @@ -41,4 +41,6 @@ describe('geolocation', function() { expect(robot.http.mostRecentCall.args[0]).toBe('http://api.hostip.info/get_json.php?ip=1.2.3.4') }); + //TODO - More verbose tests to make sure this doesn't get called when Regex fails + }); \ No newline at end of file