Skip to content

Commit

Permalink
test(ap): checks ap config before enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Mar 3, 2016
1 parent 608134c commit 91c6de7
Showing 1 changed file with 85 additions and 5 deletions.
90 changes: 85 additions & 5 deletions test/unit/access-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ exports['Tessel.prototype.enableAccessPoint'] = {
this.reconnectWifi = this.sandbox.spy(commands, 'reconnectWifi');
this.reconnectDnsmasq = this.sandbox.spy(commands, 'reconnectDnsmasq');
this.reconnectDhcp = this.sandbox.spy(commands, 'reconnectDhcp');
this.getAccessPointConfig = this.sandbox.spy(commands, 'getAccessPointConfig');
this.getAccessPointIP = this.sandbox.spy(commands, 'getAccessPointIP');

this.tessel = TesselSimulator();
this.tessel.name = 'TestTessel';

done();
},
Expand All @@ -224,13 +227,41 @@ exports['Tessel.prototype.enableAccessPoint'] = {
},

turnsOn: function(test) {
test.expect(4);
test.expect(6);
var results = {
ssid: 'TestSSID',
key: 'TestPass123',
encryption: 'psk2',
disabled: '1',
ip: '192.168.200.1'
};

// Test is expecting two closes...;
this.tessel._rps.on('control', () => {
setImmediate(() => {
this.tessel._rps.emit('close');
});
this.tessel._rps.on('control', (command) => {
if (command.toString() === 'uci show wireless.@wifi-iface[1]') {
var info = new Buffer(tags.stripIndent `
wireless.cfg053579.ssid='${results.ssid}'
wireless.cfg053579.key='${results.key}'
wireless.cfg053579.encryption='${results.encryption}'
wireless.cfg053579.disabled='1'`);

setImmediate(() => {
this.tessel._rps.stdout.emit('data', info);
this.tessel._rps.emit('close');
});
} else if (command.toString() === 'uci get network.lan.ipaddr') {
var ipInfo = new Buffer(`${results.ip}\n`);

setImmediate(() => {
this.tessel._rps.stdout.emit('data', ipInfo);
this.tessel._rps.emit('close');
});
} else {
setImmediate(() => {
this.tessel._rps.stdout.removeAllListeners();
this.tessel._rps.emit('close');
});
}
});

this.tessel.enableAccessPoint()
Expand All @@ -239,12 +270,61 @@ exports['Tessel.prototype.enableAccessPoint'] = {
test.equal(this.reconnectWifi.callCount, 1);
test.equal(this.reconnectDnsmasq.callCount, 1);
test.equal(this.reconnectDhcp.callCount, 1);
test.equal(this.getAccessPointConfig.callCount, 1);
test.equal(this.getAccessPointIP.callCount, 1);
test.done();
})
.catch(error => {
test.ok(false, error.toString());
test.done();
});
},

failsWhenUnconfigured: function(test) {
test.expect(1);
var results = {
key: 'TestPass123',
encryption: 'psk2',
disabled: '1',
ip: '192.168.200.1'
};

// Test is expecting two closes...;
this.tessel._rps.on('control', (command) => {
if (command.toString() === 'uci show wireless.@wifi-iface[1]') {
var info = new Buffer(tags.stripIndent `
wireless.cfg053579.key='${results.key}'
wireless.cfg053579.encryption='${results.encryption}'
wireless.cfg053579.disabled='1'`);

setImmediate(() => {
this.tessel._rps.stdout.emit('data', info);
this.tessel._rps.emit('close');
});
} else if (command.toString() === 'uci get network.lan.ipaddr') {
var ipInfo = new Buffer(`${results.ip}\n`);

setImmediate(() => {
this.tessel._rps.stdout.emit('data', ipInfo);
this.tessel._rps.emit('close');
});
} else {
setImmediate(() => {
this.tessel._rps.stdout.removeAllListeners();
this.tessel._rps.emit('close');
});
}
});

this.tessel.enableAccessPoint()
.then(() => {
test.fail('Should not pass');
test.done();
})
.catch(error => {
test.ok(error);
test.done();
});
}
};

Expand Down

0 comments on commit 91c6de7

Please sign in to comment.