Skip to content

Commit

Permalink
Merge 5133e95 into e3a4328
Browse files Browse the repository at this point in the history
  • Loading branch information
monkbroc committed Feb 7, 2020
2 parents e3a4328 + 5133e95 commit 8e0ed04
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CloudCommand {
return api.claimDevice(deviceId).then(() => {
console.log('Successfully claimed device ' + deviceId);
}, (err) => {
if (err && typeof err === 'string' && err.indexOf('That belongs to someone else.') >= 0) {
if (err && typeof err[0] === 'string' && err[0].indexOf('That belongs to someone else.') >= 0) {
return prompt([{
type: 'confirm',
name: 'transfer',
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/cloud.e2e.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const path = require('path');
const capitalize = require('lodash/capitalize');
const { expect } = require('../setup');
const { delay } = require('../lib/mocha-utils');
const stripANSI = require('../lib/ansi-strip');
const cli = require('../lib/cli');
const {
DEVICE_ID,
DEVICE_NAME,
DEVICE_PLATFORM_NAME,
FOREIGN_DEVICE_ID,
PATH_TMP_DIR,
PATH_PROJ_STROBY_INO,
PATH_FIXTURES_PROJECTS_DIR
Expand Down Expand Up @@ -184,6 +187,37 @@ describe('Cloud Commands [@device]', () => {
expect(exitCode).to.equal(0);
});

it('Fails to claim an unknown device', async () => {
const invalidDeviceID = '1234567890';
const args = ['cloud', 'claim', invalidDeviceID];
const { stdout, stderr, exitCode } = await cli.run(args);
const log = [
`Claiming device ${invalidDeviceID}`,
'Failed to claim device: device not found'
];

expect(stdout.split('\n')).to.include.members(log);
expect(stderr).to.equal('');
expect(exitCode).to.equal(1);
});

it('Fails to claim a device owned by someone else', async () => {
const args = ['cloud', 'claim', FOREIGN_DEVICE_ID];
const subprocess = cli.run(args);

await delay(1000);
subprocess.stdin.write('n');
subprocess.stdin.write('\n');

const { all, exitCode } = await subprocess;
const log = stripANSI(all);

expect(log).to.include(`Claiming device ${FOREIGN_DEVICE_ID}`);
expect(log).to.include('That device belongs to someone else. Would you like to request a transfer?');
expect(log).to.include('Failed to claim device: You cannot claim a device owned by someone else');
expect(exitCode).to.equal(1);
});

it('Names a device', async () => {
const name = `${DEVICE_NAME}-updated`;
const args = ['cloud', 'name', DEVICE_ID, name];
Expand Down
10 changes: 9 additions & 1 deletion test/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const {
E2E_DEVICE_ID: DEVICE_ID,
E2E_DEVICE_NAME: DEVICE_NAME,
E2E_DEVICE_PLATFORM_ID: DEVICE_PLATFORM_ID,
E2E_DEVICE_PLATFORM_NAME: DEVICE_PLATFORM_NAME
E2E_DEVICE_PLATFORM_NAME: DEVICE_PLATFORM_NAME,
E2E_FOREIGN_DEVICE_ID: FOREIGN_DEVICE_ID,
E2E_FOREIGN_DEVICE_NAME: FOREIGN_DEVICE_NAME,
E2E_FOREIGN_DEVICE_PLATFORM_ID: FOREIGN_DEVICE_PLATFORM_ID,
E2E_FOREIGN_DEVICE_PLATFORM_NAME: FOREIGN_DEVICE_PLATFORM_NAME
} = process.env;


Expand All @@ -36,6 +40,10 @@ module.exports = {
DEVICE_NAME,
DEVICE_PLATFORM_ID,
DEVICE_PLATFORM_NAME,
FOREIGN_DEVICE_ID,
FOREIGN_DEVICE_NAME,
FOREIGN_DEVICE_PLATFORM_ID,
FOREIGN_DEVICE_PLATFORM_NAME,
PATH_REPO_DIR,
PATH_TEST_DIR,
PATH_FIXTURES_DIR,
Expand Down

0 comments on commit 8e0ed04

Please sign in to comment.