Skip to content

Commit d5fa264

Browse files
committed
Modify e2e tests
1 parent d6540bf commit d5fa264

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/cli/wifi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.exports = ({ commandProcessor, root }) => {
101101
}
102102
});
103103

104-
commandProcessor.createCommand(wifi, 'status', 'Gets the current wifi network', {
104+
commandProcessor.createCommand(wifi, 'current', 'Gets the current wifi network', {
105105
handler: () => {
106106
const WiFiCommands = require('../cmd/wifi');
107107
return new WiFiCommands().getCurrentNetwork();

src/cmd/wifi.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ module.exports = class WiFiCommands extends CLICommandBase {
136136
error.isUsageError = true;
137137
throw error;
138138
}
139-
console.log('tp security: ', security);
140-
// TEST this with security type:
141139
return { ssid: network, security: this._convertToKnownSecType(security), password };
142140
}
143141

@@ -317,7 +315,7 @@ module.exports = class WiFiCommands extends CLICommandBase {
317315
this.ui.stdout.write(`Wi-Fi network '${ssid}' configured and joined successfully.${os.EOL}`);
318316
}
319317

320-
async joinKnownWifi({ ssid }) {
318+
async joinKnownWifi(ssid) {
321319
await this._performWifiOperation(`Joining a known Wi-Fi network '${ssid}'`, async () => {
322320
await this.device.joinKnownWifiNetwork({ ssid }, { timeout: JOIN_NETWORK_TIMEOUT });
323321
});
@@ -379,17 +377,10 @@ module.exports = class WiFiCommands extends CLICommandBase {
379377
});
380378

381379
this.ui.stdout.write(`Current Wi-Fi network:${os.EOL}${os.EOL}`);
382-
if (parsedResult?.ssid) {
383-
let bssid = null;
384-
if (parsedResult?.bssid) {
385-
// Convert buffer to string separated by colons
386-
bssid = Array.from(parsedResult.bssid).map((byte) => byte.toString(16).padStart(2, '0')).join(':');
387-
}
388-
this.ui.stdout.write(`- SSID: ${parsedResult.ssid}${os.EOL}` +
389-
(bssid ? ` BSSID: ${bssid}${os.EOL}` : '') +
390-
` Channel: ${parsedResult.channel}${os.EOL}` +
391-
` RSSI: ${parsedResult.rssi}${os.EOL}${os.EOL}`);
392-
}
380+
this.ui.stdout.write(`- SSID: ${parsedResult?.ssid}${os.EOL}` +
381+
(` BSSID: ${parsedResult?.bssid}${os.EOL}`) +
382+
` Channel: ${parsedResult?.channel}${os.EOL}` +
383+
` RSSI: ${parsedResult?.rssi}${os.EOL}${os.EOL}`);
393384
}
394385

395386
async _pickNetworkManually() {
@@ -490,6 +481,9 @@ module.exports = class WiFiCommands extends CLICommandBase {
490481
}
491482
let helperString = '';
492483
switch (error.message) {
484+
case 'Invalid state':
485+
helperString = 'Check that the device is connected to the network and try again.';
486+
break;
493487
case 'Not found':
494488
helperString = 'If you are using a hidden network, please add the hidden network credentials first using \'particle wifi add\'.';
495489
break;

test/e2e/wifi.e2e.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
describe('Wi-Fi Commands [@device,@wifi]', () => {
1212

1313
const help = [
14-
'Configure Wi-Fi credentials to your device',
14+
'Configure Wi-Fi credentials to your device (Supported on Gen 3+ devices).',
1515
'Usage: particle wifi <command>',
1616
'Help: particle help wifi <command>',
1717
'',
@@ -21,7 +21,7 @@ describe('Wi-Fi Commands [@device,@wifi]', () => {
2121
' clear Clears the list of wifi networks on your device',
2222
' list Lists the wifi networks on your device',
2323
' remove Removes a wifi network from the device',
24-
' status Gets the current wifi network',
24+
' current Gets the current wifi network',
2525
'',
2626
'Global Options:',
2727
' -v, --verbose Increases how much logging to display [count]',
@@ -60,25 +60,25 @@ describe('Wi-Fi Commands [@device,@wifi]', () => {
6060
it('Adds a Wi-Fi network', async () => {
6161
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'add', '--file', WIFI_CREDS_FILE]);
6262

63-
expect(stdout).to.include('blahme');
63+
expect(stdout).to.include(`Wi-Fi network ${WIFI_SSID}' added successfully.`);
6464
expect(stderr).to.equal('');
6565
expect(exitCode).to.equal(0);
6666
});
6767

6868
it('Joins a Wi-Fi network', async () => {
6969
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'join', '--file', WIFI_CREDS_FILE]);
7070

71-
expect(stdout).to.include('blahme');
71+
expect(stdout).to.include(`Wi-Fi network '${WIFI_SSID}' configured and joined successfully.`);
7272
expect(stderr).to.equal('');
7373
expect(exitCode).to.equal(0);
7474
});
7575

7676
it('Joins a known Wi-Fi network', async () => {
77-
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'join', '--ssid', 'myNetwork1']);
78-
7977
// expect that the network is present in the list
80-
const { stdout: listStdout, stderr: listStderr, exitCode: listExitCode } = await cli.run(['wifi', 'list']);
81-
78+
const { stdout: listStdout } = await cli.run(['wifi', 'list']);
79+
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'join', '--ssid', WIFI_SSID]);
80+
81+
expect(listStdout).to.include(WIFI_SSID);
8282
expect(stdout).to.include(`Wi-Fi network '${WIFI_SSID}' configured and joined successfully.`);
8383
expect(stderr).to.equal('');
8484
expect(exitCode).to.equal(0);
@@ -87,33 +87,36 @@ describe('Wi-Fi Commands [@device,@wifi]', () => {
8787
it('Lists networks on the device', async () => {
8888
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'list']);
8989

90-
expect(stdout).to.include('blahme');
90+
expect(stdout).to.include('List of Wi-Fi networks on the device:');
91+
expect(stdout).to.include(WIFI_SSID);
9192
expect(stderr).to.equal('');
9293
expect(exitCode).to.equal(0);
9394
});
9495

9596
it('removes a Wi-Fi network', async () => {
96-
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'remove', '--ssid', 'myNetwork1']);
97+
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'remove', '--ssid', WIFI_SSID]);
9798

98-
// expect that the network to not be present in the list
99-
const { stdout: listStdout, stderr: listStderr, exitCode: listExitCode } = await cli.run(['wifi', 'list']);
99+
const { stdout: listStdout } = await cli.run(['wifi', 'list']);
100100

101-
expect(stdout).to.include(`Wi-Fi network 'myNetwork1' removed successfully.`);
101+
expect(stdout).to.include(`Wi-Fi network ${WIFI_SSID} removed from device's list successfully.`);
102+
expect(listStdout).to.not.include(WIFI_SSID);
102103
expect(stderr).to.equal('');
103104
expect(exitCode).to.equal(0);
104105
});
105106

106107
it('Clears networks from the device', async () => {
107-
await cli.run(['wifi', 'join', '--ssid', 'myNetwork1']);
108+
// Let the device join a network and then clear it
109+
await cli.run(['wifi', 'join', '--ssid', WIFI_SSID]);
110+
const { stdout: listStdoutBeforeClearing } = await cli.run(['wifi', 'list']);
108111
const { stdout, stderr, exitCode } = await cli.run(['wifi', 'clear']);
112+
const { stdout : listStdoutAfterClearing } = await cli.run(['wifi', 'list']);
109113

110-
const { stdout : stdoutList } = await cli.run(['wifi', 'list']);
111-
112-
expect(stdout).to.include('blahme');
114+
expect(listStdoutBeforeClearing).to.include(WIFI_SSID);
115+
expect(stdout).to.include(`Wi-Fi networks cleared successfully.`);
113116
expect(stderr).to.equal('');
114117
expect(exitCode).to.equal(0);
118+
expect(listStdoutAfterClearing).to.not.include(WIFI_SSID);
115119
});
116-
117120
});
118121

119122
});

0 commit comments

Comments
 (0)