Skip to content

Commit

Permalink
[tests] lint fix and edit help
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 21, 2024
1 parent cd1fc18 commit b61e545
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 59 deletions.
5 changes: 0 additions & 5 deletions src/cmd/device-protection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ describe('DeviceProtectionCommands', () => {
});

it('throws an error while getting the protection status of the device', async () => {
const expectedStatus = {
protected: true,
overridden: false
};

sinon.stub(deviceProtectionCommands, '_getDeviceProtection').rejects(new Error('random error'));

let error;
Expand Down
36 changes: 18 additions & 18 deletions test/e2e/device-protection.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
} = require('../lib/env');


describe('Wi-Fi Commands [@device,@device-protection]', () => {
describe('Device Protection Commands [@device,@device-protection]', () => {
const help = [
'Manage device protection',
'Usage: particle device-protection <command>',
Expand Down Expand Up @@ -62,65 +62,65 @@ describe('Wi-Fi Commands [@device,@device-protection]', () => {
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(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 () => {
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}) is not a protected device.`);
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is not a protected 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(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']);
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);
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 () => {
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(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(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(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']);
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);
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);
});

});
Expand Down
73 changes: 37 additions & 36 deletions test/e2e/help.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,43 @@ describe('Help & Unknown Command / Argument Handling', () => {
const sandbox = sinon.createSandbox();
const commandList = [
'Commands:',
' binary Inspect binaries',
' bundle Creates a bundle of application binary and assets',
' call Call a particular function on a device',
' cloud Access Particle cloud functionality',
' compile Compile a source file, or directory using the cloud compiler',
' config Configure and switch between multiple accounts',
' device Manipulate a device',
' doctor NOT SUPPORTED. Go to the device doctor tool at docs.particle.io/tools/doctor',
' flash Send firmware to your device',
' function Call functions on your device',
' get Retrieve a value from your device',
' identify Ask for and display device ID via serial',
' keys Manage your device\'s key pair and server public key',
' library Manage firmware libraries',
' list Display a list of your devices, as well as their variables and functions',
' logic-function Create, execute, and deploy Logic Functions',
' login Login to the cloud and store an access token locally',
' logout Log out of your session and clear your saved access token',
' monitor Connect and display messages from a device',
' nyan Make your device shout rainbows',
' preprocess Preprocess a Wiring file (ino) into a C++ file (cpp)',
' product Access Particle Product functionality [BETA]',
' project Manage application projects',
' publish Publish an event to the cloud',
' serial Simple serial interface to your devices',
' setup NOT SUPPORTED. Go to setup.particle.io with your browser',
' subscribe Listen to device event stream',
' token Manage access tokens (require username/password)',
' udp Talk UDP to repair devices, run patches, check Wi-Fi, and more!',
' update Update Device OS on a device via USB',
' update-cli Update the Particle CLI to the latest version',
' usb Control USB devices',
' variable Retrieve and monitor variables on your device',
' webhook Manage webhooks that react to device event streams',
' whoami prints signed-in username',
' wifi Configure Wi-Fi credentials to your device (Supported on Gen 3+ devices).'
' binary Inspect binaries',
' bundle Creates a bundle of application binary and assets',
' call Call a particular function on a device',
' cloud Access Particle cloud functionality',
' compile Compile a source file, or directory using the cloud compiler',
' config Configure and switch between multiple accounts',
' device Manipulate a device',
' device-protection Manage device protection',
' doctor NOT SUPPORTED. Go to the device doctor tool at docs.particle.io/tools/doctor',
' flash Send firmware to your device',
' function Call functions on your device',
' get Retrieve a value from your device',
' identify Ask for and display device ID via serial',
' keys Manage your device\'s key pair and server public key',
' library Manage firmware libraries',
' list Display a list of your devices, as well as their variables and functions',
' logic-function Create, execute, and deploy Logic Functions',
' login Login to the cloud and store an access token locally',
' logout Log out of your session and clear your saved access token',
' monitor Connect and display messages from a device',
' nyan Make your device shout rainbows',
' preprocess Preprocess a Wiring file (ino) into a C++ file (cpp)',
' product Access Particle Product functionality [BETA]',
' project Manage application projects',
' publish Publish an event to the cloud',
' serial Simple serial interface to your devices',
' setup NOT SUPPORTED. Go to setup.particle.io with your browser',
' subscribe Listen to device event stream',
' token Manage access tokens (require username/password)',
' udp Talk UDP to repair devices, run patches, check Wi-Fi, and more!',
' update Update Device OS on a device via USB',
' update-cli Update the Particle CLI to the latest version',
' usb Control USB devices',
' variable Retrieve and monitor variables on your device',
' webhook Manage webhooks that react to device event streams',
' whoami prints signed-in username',
' wifi Configure Wi-Fi credentials to your device (Supported on Gen 3+ devices).'
];

const allCmds = ['binary inspect', 'binary enable-device-protection', 'binary', 'bundle', 'call', 'cloud list',
Expand Down

0 comments on commit b61e545

Please sign in to comment.