Skip to content

Commit

Permalink
Merge pull request #580 from particle-iot/bugfix/ch53821/usb-list-dif…
Browse files Browse the repository at this point in the history
…f-acct

bugfix/ch53821/usb-list-diff-acct
  • Loading branch information
busticated committed May 5, 2020
2 parents c8c93da + 87a8327 commit e17405c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cmd/usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = class UsbCommand {
return Promise.all(info);
})
.then(([device, isInDfuMode, mode]) => {
const { name, platform_id: platformID, connected } = device || {};
const platform = platformsById[usbDevice.platformId];
const type = [platform];

Expand All @@ -62,10 +63,10 @@ module.exports = class UsbCommand {

return {
id: usbDevice.id,
name: (device && device.name) ? device.name : '',
name: name || '',
type: `${type.join(', ')}`,
platform_id: device.platform_id,
connected: device.connected
platform_id: platformID || '',
connected: !!connected
};
})
.finally(() => usbDevice.close());
Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ E2E_DEVICE_ID=<your test device's id>
E2E_DEVICE_NAME=<your test device's name>
E2E_DEVICE_PLATFORM_ID=<the platform id of your test device>
E2E_DEVICE_PLATFORM_NAME=<the platform name of your test device>
E2E_FOREIGN_USERNAME=<username for 3rd-party account>
E2E_FOREIGN_PASSWORD=<password for 3rd-party account>
E2E_FOREIGN_DEVICE_ID=<id for 3rd-party device the test user DOES NOT own>
E2E_FOREIGN_DEVICE_NAME=<name for 3rd-party device>
E2E_FOREIGN_DEVICE_PLATFORM_ID=<platform id for 3rd-party device>
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/usb.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ describe('USB Commands [@device]', function cliUSBCommands(){
args = ['usb', 'list'];
});

after(async () => {
await cli.setTestProfileAndLogin();
});

it('Lists connected devices', async () => {
const { stdout, stderr, exitCode } = await cli.run(args);

Expand Down Expand Up @@ -165,6 +169,24 @@ describe('USB Commands [@device]', function cliUSBCommands(){
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Lists connected devices when signed-in to a foreign account', async () => {
await cli.loginToForeignAcct();
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include(`<no name> [${DEVICE_ID}] (${platform})`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Fails to list devices when signed-out', async () => {
await cli.logout();
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include('The access token was not found');
expect(stderr).to.equal('');
expect(exitCode).to.equal(1);
});
});

describe('USB Start-Listening Subcommand', () => {
Expand Down
7 changes: 7 additions & 0 deletions test/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
PASSWORD,
DEVICE_ID,
DEVICE_NAME,
FOREIGN_USERNAME,
FOREIGN_PASSWORD,
PATH_TMP_DIR,
PATH_REPO_DIR,
PATH_PROJ_BLANK_INO,
Expand Down Expand Up @@ -36,6 +38,11 @@ module.exports.login = () => {
return run(['login', '-u', USERNAME, '-p', PASSWORD], { reject: true });
};

module.exports.loginToForeignAcct = () => {
const { run } = module.exports;
return run(['login', '-u', FOREIGN_USERNAME, '-p', FOREIGN_PASSWORD], { reject: true });
};

module.exports.logout = () => {
const { run } = module.exports;
return run(['logout'], { input: 'y\n', reject: true });
Expand Down
4 changes: 4 additions & 0 deletions test/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const {
E2E_DEVICE_NAME: DEVICE_NAME,
E2E_DEVICE_PLATFORM_ID: DEVICE_PLATFORM_ID,
E2E_DEVICE_PLATFORM_NAME: DEVICE_PLATFORM_NAME,
E2E_FOREIGN_USERNAME: FOREIGN_USERNAME,
E2E_FOREIGN_PASSWORD: FOREIGN_PASSWORD,
E2E_FOREIGN_DEVICE_ID: FOREIGN_DEVICE_ID,
E2E_FOREIGN_DEVICE_NAME: FOREIGN_DEVICE_NAME,
E2E_FOREIGN_DEVICE_PLATFORM_ID: FOREIGN_DEVICE_PLATFORM_ID,
Expand All @@ -41,6 +43,8 @@ module.exports = {
DEVICE_NAME,
DEVICE_PLATFORM_ID,
DEVICE_PLATFORM_NAME,
FOREIGN_USERNAME,
FOREIGN_PASSWORD,
FOREIGN_DEVICE_ID,
FOREIGN_DEVICE_NAME,
FOREIGN_DEVICE_PLATFORM_ID,
Expand Down

0 comments on commit e17405c

Please sign in to comment.