Skip to content

Commit

Permalink
Changes method value to "wifi"
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioschneider committed Mar 18, 2015
1 parent c0113ee commit 807334c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
15 changes: 4 additions & 11 deletions lib/agent/providers/geo/index.js
Expand Up @@ -11,7 +11,7 @@ var client = require('needle'),
get_agent = require('random-ua').generate,
providers = require('./../../providers');

var process_response = function(method, body, cb){
var process_response = function(body, cb){
var coords;

if (typeof body === 'object') {
Expand All @@ -31,7 +31,7 @@ var process_response = function(method, body, cb){
lat: coords.location.lat || coords.location.latitude,
lng: coords.location.lng || coords.location.longitude,
accuracy: coords.accuracy || coords.location.accuracy,
method: method
method: 'wifi'
};

cb(null, data);
Expand All @@ -40,14 +40,7 @@ var process_response = function(method, body, cb){

exports.send_data = function(list, cb){

var aps = [],
method = '';

if(list.length === 0) {
method = 'gapi_empty';
} else {
method = 'gapi_list';
}
var aps = [];

list.slice(0, 30).forEach(function(ap){
var str = 'wifi=mac:' + ap.mac_address + '|ssid:' + encodeURIComponent(ap.ssid);
Expand All @@ -61,7 +54,7 @@ exports.send_data = function(list, cb){

client.get(query, opts, function(err, resp, body) {
if (err) return cb(err);
process_response(method, body, cb);
process_response(body, cb);
});

};
Expand Down
37 changes: 2 additions & 35 deletions test/lib/agent/providers/geo/coordinates.js
Expand Up @@ -11,39 +11,6 @@ describe('location', function(){

describe('when access points list is empty', function(){

var list = [];

describe('and response contains valid coordinates', function(){

before(function(done){
fs.readFile(__dirname + '/../fixtures/location_response.json', function(err, data){
helpers.stub_request('get', null, { statusCode: 200 }, data.toString().trim());
done();
});
});

it('callsback coordinates', function(done){

provider.send_data(list, function(err, data){
// should.not.exist(err); TODO: fix this
data.should.be.an.instanceof(Object);
data.should.have.keys(['lat', 'lng', 'accuracy', 'method']);
done();
});

});

it('sets method to gapi_empty', function (done) {

provider.send_data(list, function (err, data){
data.method.should.equal('gapi_empty');
done();
});

});

});

});

describe('when access points is valid', function(){
Expand Down Expand Up @@ -98,10 +65,10 @@ describe('location', function(){

});

it('sets method to gapi_list', function (done) {
it('sets method to wifi', function (done) {

provider.send_data(list, function (err, data){
data.method.should.equal('gapi_list');
data.method.should.equal('wifi');
done();
});

Expand Down

0 comments on commit 807334c

Please sign in to comment.