Skip to content

Commit d3d37e5

Browse files
HipsterBrownrwaldron
authored andcommitted
test(Tessel.AP): cover methods and helpers
1 parent 4c37d5a commit d3d37e5

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

Diff for: node/tessel-export.js

+1
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,7 @@ function getWifiInfo() {
15701570

15711571
// attempt to parse out the security configuration from the returned network object
15721572
if (network.encryption && network.encryption.enabled) {
1573+
/* istanbul ignore else*/
15731574
if (network.encryption.wep) {
15741575
network.security = 'wep';
15751576
} else if (network.encryption.authentication && network.encryption.wpa) {

Diff for: node/test/unit/tessel.js

+123-1
Original file line numberDiff line numberDiff line change
@@ -4805,7 +4805,8 @@ exports['Tessel.AP'] = {
48054805
test.expect(4);
48064806

48074807
var settings = {
4808-
ssid: 'TestNetwork'
4808+
ssid: 'TestNetwork',
4809+
security: 'none'
48094810
};
48104811
var ip = '192.168.1.101';
48114812

@@ -4875,6 +4876,43 @@ exports['Tessel.AP'] = {
48754876
});
48764877
},
48774878

4879+
createGetAccessPointIPThrowsError: function(test) {
4880+
test.expect(2);
4881+
4882+
var settings = {
4883+
ssid: 'TestNetwork'
4884+
};
4885+
var testError = 'This is a test';
4886+
4887+
this.exec.restore();
4888+
this.exec = sandbox.stub(childProcess, 'exec').callsFake((cmd, callback) => {
4889+
if (cmd === 'uci get network.lan.ipaddr') {
4890+
callback(testError);
4891+
} else {
4892+
callback();
4893+
}
4894+
});
4895+
4896+
this.tessel.network.ap.on('create', () => {
4897+
test.fail('should not connect');
4898+
test.done();
4899+
});
4900+
4901+
this.tessel.network.ap.on('error', (error) => {
4902+
test.equal(error, testError, 'error event fires correctly');
4903+
});
4904+
4905+
this.tessel.network.ap.create(settings, (error) => {
4906+
if (error) {
4907+
test.equal(error, testError, 'error should be passed into callback');
4908+
test.done();
4909+
} else {
4910+
test.fail('should not connect');
4911+
test.done();
4912+
}
4913+
});
4914+
},
4915+
48784916
reset: function(test) {
48794917
test.expect(5);
48804918

@@ -4906,6 +4944,42 @@ exports['Tessel.AP'] = {
49064944
});
49074945
},
49084946

4947+
resetErrorCallback: function(test) {
4948+
test.expect(5);
4949+
4950+
const testError = new Error('Testing error');
4951+
this.exec.restore();
4952+
this.exec = sandbox.stub(childProcess, 'exec').callsFake((cmd, callback) => {
4953+
callback(testError);
4954+
});
4955+
4956+
this.tessel.network.ap.on('reset', () => {
4957+
test.ok(true, 'reset event is fired');
4958+
});
4959+
4960+
this.tessel.network.ap.on('off', () => {
4961+
test.ok(true, 'off event is fired');
4962+
});
4963+
4964+
this.tessel.network.ap.on('disable', () => {
4965+
test.ok(true, 'disable event is fired');
4966+
});
4967+
4968+
this.tessel.network.ap.on('error', (error) => {
4969+
test.ok(error);
4970+
});
4971+
4972+
this.tessel.network.ap.reset((error) => {
4973+
if (error) {
4974+
test.ok(error);
4975+
test.done();
4976+
} else {
4977+
test.fail(error);
4978+
test.done();
4979+
}
4980+
});
4981+
},
4982+
49094983
disable: function(test) {
49104984
test.expect(2);
49114985

@@ -4927,6 +5001,30 @@ exports['Tessel.AP'] = {
49275001
});
49285002
},
49295003

5004+
disableErrorCallback: function(test) {
5005+
test.expect(2);
5006+
5007+
const testError = new Error('Testing error');
5008+
this.exec.restore();
5009+
this.exec = sandbox.stub(childProcess, 'exec').callsFake((cmd, callback) => {
5010+
callback(testError);
5011+
});
5012+
5013+
this.tessel.network.ap.on('error', (error) => {
5014+
test.ok(error);
5015+
});
5016+
5017+
this.tessel.network.ap.disable((error) => {
5018+
if (error) {
5019+
test.ok(error);
5020+
test.done();
5021+
} else {
5022+
test.fail(error);
5023+
test.done();
5024+
}
5025+
});
5026+
},
5027+
49305028
enable: function(test) {
49315029
test.expect(2);
49325030

@@ -4946,5 +5044,29 @@ exports['Tessel.AP'] = {
49465044
test.done();
49475045
}
49485046
});
5047+
},
5048+
5049+
enableErrorCallback: function(test) {
5050+
test.expect(2);
5051+
5052+
const testError = new Error('Testing error');
5053+
this.exec.restore();
5054+
this.exec = sandbox.stub(childProcess, 'exec').callsFake((cmd, callback) => {
5055+
callback(testError);
5056+
});
5057+
5058+
this.tessel.network.ap.on('error', (error) => {
5059+
test.ok(error);
5060+
});
5061+
5062+
this.tessel.network.ap.enable((error) => {
5063+
if (error) {
5064+
test.ok(error);
5065+
test.done();
5066+
} else {
5067+
test.fail(error);
5068+
test.done();
5069+
}
5070+
});
49495071
}
49505072
};

0 commit comments

Comments
 (0)