Skip to content

Commit

Permalink
add e2e tests for usb cloud-status command
Browse files Browse the repository at this point in the history
  • Loading branch information
busticated committed Apr 27, 2020
1 parent 94b64b3 commit 5ac886e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/e2e/help.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ describe('Help & Unknown Command / Argument Handling', () => {
'token create', 'token', 'udp send', 'udp listen', 'udp', 'update',
'update-cli', 'usb list', 'usb start-listening', 'usb listen',
'usb stop-listening', 'usb safe-mode', 'usb dfu', 'usb reset',
'usb setup-done', 'usb configure', 'usb', 'variable list', 'variable get',
'variable monitor', 'variable', 'webhook create', 'webhook list',
'webhook delete', 'webhook POST', 'webhook GET', 'webhook', 'whoami'];
'usb setup-done', 'usb configure', 'usb cloud-status', 'usb',
'variable list', 'variable get', 'variable monitor', 'variable',
'webhook create', 'webhook list', 'webhook delete', 'webhook POST',
'webhook GET', 'webhook', 'whoami'];

const mainCmds = dedupe(allCmds.map(c => c.split(' ')[0]));

Expand Down
41 changes: 41 additions & 0 deletions test/e2e/usb.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('USB Commands [@device]', () => {
'Commands:',
' list List the devices connected to the host computer',
' start-listening Put a device into the listening mode',
' listen alias for start-listening',
' stop-listening Make a device exit the listening mode',
' safe-mode Put a device into the safe mode',
' dfu Put a device into the DFU mode',
' reset Reset a device',
' setup-done Set the setup done flag',
' configure Update the system USB configuration',
' cloud-status Check a device\'s cloud connection state',
'',
'Global Options:',
' -v, --verbose Increases how much logging to display [count]',
Expand Down Expand Up @@ -247,4 +249,43 @@ describe('USB Commands [@device]', () => {
expect(exitCode).to.equal(1);
});
});

describe('Cloud Status Subcommand', () => {
it('Reports current cloud connection status', async () => {
const { stdout, stderr, exitCode } = await cli.run(['usb', 'cloud-status', DEVICE_NAME]);

expect(stdout).to.equal('connected');
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Reports current cloud connection status for device id', async () => {
const { stdout, stderr, exitCode } = await cli.run(['usb', 'cloud-status', DEVICE_ID]);

expect(stdout).to.equal('connected');
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Polls cloud connection status using the `--until` flag', async () => {
await cli.run(['usb', 'reset', DEVICE_ID]);

const args = ['usb', 'cloud-status', DEVICE_ID, '--until', 'connected'];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.equal('connected');
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Fails with timeout error when polling cloud connection status using the `--until` flag', async () => {
const args = ['usb', 'cloud-status', DEVICE_ID, '--until', 'disconnecting', '--timeout', 2 * 1000];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.equal('timed-out waiting for status...');
expect(stderr).to.equal('');
expect(exitCode).to.equal(1);
});
});
});

0 comments on commit 5ac886e

Please sign in to comment.