Skip to content

Commit

Permalink
add e2e tests for cloud claim error scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
busticated committed Feb 7, 2020
1 parent 0580b6f commit 5133e95
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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 5133e95

Please sign in to comment.