Skip to content

Commit

Permalink
[e2e] Add e2e tests for device protection
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 21, 2024
1 parent 1d92580 commit 7f2a19d
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions test/e2e/device-protection.e2e.js
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);
});

});

});

0 comments on commit 7f2a19d

Please sign in to comment.