Skip to content

Commit

Permalink
tests(wifi): wifi does not require password
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Dec 4, 2015
1 parent 63952cb commit 492a144
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 26 deletions.
46 changes: 43 additions & 3 deletions test/unit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,47 @@ exports['controller.closeTesselConnections'] = {
done();
},

noSSID: function(test) {
noNetworkSSID: function(test) {
test.expect(1);

controller.connectToNetwork({
ssid: undefined
})
.catch(function(error) {
test.ok(error);
test.done();
});
},

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

controller.connectToNetwork({
ssid: 'test',
password: undefined,
security: 'psk2'
})
.catch(function(error) {
test.ok(error);
test.done();
});
},

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

controller.connectToNetwork({
ssid: 'test',
password: undefined,
security: 'reallySecure'
})
.catch(function(error) {
test.ok(error);
test.done();
});
},

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

controller.createAccessPoint({
Expand All @@ -810,7 +850,7 @@ exports['controller.closeTesselConnections'] = {
});
},

noPasswordWithSecurity: function(test) {
noAccessPointPasswordWithSecurity: function(test) {
test.expect(1);

controller.createAccessPoint({
Expand All @@ -824,7 +864,7 @@ exports['controller.closeTesselConnections'] = {
});
},

invalidSecurityOption: function(test) {
invalidAccessPointSecurityOption: function(test) {
test.expect(1);

controller.createAccessPoint({
Expand Down
79 changes: 56 additions & 23 deletions test/unit/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,34 @@ module.exports['Tessel.prototype.connectToNetwork'] = {
this.reconnectWifi.restore();
done();
},
noSSID: function(test) {
noPassword: function(test) {
var self = this;
test.expect(4);
this.tessel.connectToNetwork({
ssid: undefined,
password: 'fish'
})
.catch(function(error) {
test.ok(error);
test.equal(self.setNetworkSSID.callCount, 0);
test.expect(7);
var creds = {
ssid: 'tank',
password: undefined
};

// Test is expecting two closes...;
self.tessel._rps.on('control', function() {
setImmediate(function() {
self.tessel._rps.emit('close');
});
});

this.tessel.connectToNetwork(creds)
.then(function() {
test.equal(self.setNetworkSSID.callCount, 1);
test.equal(self.setNetworkPassword.callCount, 0);
test.equal(self.setNetworkEncryption.callCount, 0);
test.equal(self.setNetworkEncryption.callCount, 1);
test.equal(self.commitWirelessCredentials.callCount, 1);
test.equal(self.reconnectWifi.callCount, 1);
test.ok(self.setNetworkSSID.lastCall.calledWith(creds.ssid));
test.ok(self.setNetworkEncryption.lastCall.calledWith('none'));
test.done();
});
},
noPassword: function(test) {
var self = this;
test.expect(4);
this.tessel.connectToNetwork({
ssid: 'tank',
password: undefined
})
.catch(function(error) {
test.ok(error);
test.equal(self.setNetworkSSID.callCount, 0);
test.equal(self.setNetworkPassword.callCount, 0);
test.equal(self.setNetworkEncryption.callCount, 0);
test.done();
test.fail(error);
});
},
properCredentials: function(test) {
Expand Down Expand Up @@ -202,6 +202,39 @@ module.exports['Tessel.prototype.connectToNetwork'] = {
.catch(function(error) {
test.fail(error);
});
},

properCredentialsWithSecurity: function(test) {
var self = this;
test.expect(8);
var creds = {
ssid: 'tank',
password: 'fish',
security: 'wpa2'
};

// Test is expecting two closes...;
self.tessel._rps.on('control', function() {
setImmediate(function() {
self.tessel._rps.emit('close');
});
});

this.tessel.connectToNetwork(creds)
.then(function() {
test.equal(self.setNetworkSSID.callCount, 1);
test.equal(self.setNetworkPassword.callCount, 1);
test.equal(self.setNetworkEncryption.callCount, 1);
test.equal(self.commitWirelessCredentials.callCount, 1);
test.equal(self.reconnectWifi.callCount, 1);
test.ok(self.setNetworkSSID.lastCall.calledWith(creds.ssid));
test.ok(self.setNetworkPassword.lastCall.calledWith(creds.password));
test.ok(self.setNetworkEncryption.lastCall.calledWith(creds.security));
test.done();
})
.catch(function(error) {
test.fail(error);
});
}
};

Expand Down

0 comments on commit 492a144

Please sign in to comment.