Skip to content

Commit

Permalink
Tests and lint pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Oct 8, 2015
1 parent fc8f2a6 commit 8c661bf
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Tessel.list = function(opts) {
var seeker = new discover.TesselSeeker().start(seekerOpts);
var noTessels = opts.authorized ?
'No Authorized Tessels Found.' :
'No Tessels Found.' ;
'No Tessels Found.';

// When a Tessel is found
seeker.on('tessel', function displayResults(tessel) {
Expand Down Expand Up @@ -120,14 +120,16 @@ Tessel.get = function(opts) {
lan: opts.lan,
authorized: true
};

if (opts.authorized !== undefined) {
seekerOpts.authorized = opts.authorized;
}

// Create a seeker object and start detecting any Tessels
var seeker = new discover.TesselSeeker().start(seekerOpts);
var noTessels = seekerOpts.authorized ?
'No Authorized Tessels Found.' :
'No Tessels Found.' ;
'No Tessels Found.';

function searchComplete() {
// If we found no Tessels
Expand Down
5 changes: 4 additions & 1 deletion test/common/tessel-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ function TesselSimulator(options) {
return Promise.resolve();
},


close: function() {
return Promise.resolve();
},

open: function() {
return Promise.resolve();
},

connectionType: options.type || 'USB',

};
Expand Down
75 changes: 71 additions & 4 deletions test/unit/tessel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var sinon = require('sinon');
var Tessel = require('../../lib/tessel/tessel');
var Seeker = require('../../lib/discover.js');
var discover = require('../../lib/discover.js');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var logs = require('../../lib/logs');
// Require this function so that the functions in the
// controller placed on the Tessel prototype
var controller = require('../../lib/controller');
var lan = require('../../lib/lan_connection');
var TesselSimulator = require('../common/tessel-simulator');


exports['Tessel (get)'] = {

Expand All @@ -16,10 +19,10 @@ exports['Tessel (get)'] = {
this.activeSeeker = undefined;
// This is necessary to prevent an EventEmitter memory leak warning
this.processOn = this.sandbox.stub(process, 'on');
this.seeker = this.sandbox.stub(Seeker, 'TesselSeeker', function Seeker() {
this.start = function(timeout) {
this.seeker = this.sandbox.stub(discover, 'TesselSeeker', function Seeker() {
this.start = function(options) {
self.activeSeeker = this;
setTimeout(this.stop.bind(this), timeout);
setTimeout(this.stop.bind(this), options.timeout);
return this;
};
this.stop = function() {
Expand Down Expand Up @@ -379,3 +382,67 @@ exports['Tessel (get)'] = {
this.activeSeeker.emit('tessel', b);
},
};


exports['Tessel (get); filter: unauthorized'] = {

setUp: function(done) {
var self = this;
this.sandbox = sinon.sandbox.create();
this.activeSeeker = undefined;
// This is necessary to prevent an EventEmitter memory leak warning
this.processOn = this.sandbox.stub(process, 'on');

var Seeker = discover.TesselSeeker;

this.start = this.sandbox.spy(Seeker.prototype, 'start');

this.seeker = this.sandbox.stub(discover, 'TesselSeeker', function() {
self.activeSeeker = new Seeker();
return self.activeSeeker;
});

this.startScan = this.sandbox.stub(lan, 'startScan', function() {
return new EventEmitter();
});

util.inherits(this.seeker, EventEmitter);
this.logsWarn = this.sandbox.stub(logs, 'warn', function() {});
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});

this.menu = this.sandbox.stub(controller, 'menu', function() {
return Promise.resolve();
});

done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

unauthorizedLANDoesNotSurface: function(test) {
test.expect(1);

Tessel.get({
timeout: 1,
authorized: true,
})
.then(function() {
test.fail();
}.bind(this))
.catch(function(message) {
test.equal(message, 'No Authorized Tessels Found.');
test.done();
});

var lan = TesselSimulator({
type: 'LAN',
authorized: false
});

this.activeSeeker.lanScan.emit('connection', lan.connection);
this.activeSeeker.emit('end');
},
};

0 comments on commit 8c661bf

Please sign in to comment.