-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[e2e] Add e2e tests for device protection
- Loading branch information
Showing
1 changed file
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
const { expect } = require('../setup'); | ||
const cli = require('../lib/cli'); | ||
const { | ||
DEVICE_ID, | ||
PRODUCT_01_DEVICE_01_ID | ||
} = require('../lib/env'); | ||
|
||
|
||
describe('Wi-Fi Commands [@device,@device-protection]', () => { | ||
const help = [ | ||
'Manage device protection', | ||
'Usage: particle device-protection <command>', | ||
'Help: particle help device-protection <command>', | ||
'', | ||
'Commands:', | ||
' status Gets the current device protection status', | ||
' disable Disables device protection', | ||
' enable Enables device protection', | ||
'', | ||
'Global Options:', | ||
' -v, --verbose Increases how much logging to display [count]', | ||
' -q, --quiet Decreases how much logging to display [count]', | ||
'' | ||
]; | ||
|
||
|
||
before(async () => { | ||
await cli.setTestProfileAndLogin(); | ||
}); | ||
|
||
after(async () => { | ||
await cli.run(['usb', 'setup-done']); | ||
await cli.logout(); | ||
await cli.setDefaultProfile(); | ||
}); | ||
|
||
it('Shows `help` content', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['help', 'device-protection']); | ||
|
||
expect(stdout).to.equal(''); | ||
expect(stderr.split('\n')).to.include.members(help); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Shows `help` content when run without arguments', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run('device-protection'); | ||
|
||
expect(stdout).to.equal(''); | ||
expect(stderr.split('\n')).to.include.members(help); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Shows `help` content when run with `--help` flag', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', '--help']); | ||
|
||
expect(stdout).to.equal(''); | ||
expect(stderr.split('\n')).to.include.members(help); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
describe('DeviceProtection Commands', () => { | ||
it('Gets the current device protection status', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Attempts to disable protection status on an open device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Enables protection status on the device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now a protected device.\nDevice removed from development mode to maintain current settings.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Gets the current status of the device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Protected device\nRun particle device-protection disable to put the device in service mode.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Attempts to enable protection status on a protected device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'enable']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is already a protected device.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Puts the device in service mode', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now in service mode.\nA protected device stays in service mode for a total of 20 reboots or 24 hours.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Turns the device to an open device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now an open device.\nDevice placed in development mode to maintain current settings.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('Gets the current status of the device', async () => { | ||
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']); | ||
|
||
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`); | ||
expect(stderr).to.equal(''); | ||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|