Skip to content

Commit 7f2a19d

Browse files
committed
[e2e] Add e2e tests for device protection
1 parent 1d92580 commit 7f2a19d

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

test/e2e/device-protection.e2e.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const { expect } = require('../setup');
2+
const cli = require('../lib/cli');
3+
const {
4+
DEVICE_ID,
5+
PRODUCT_01_DEVICE_01_ID
6+
} = require('../lib/env');
7+
8+
9+
describe('Wi-Fi Commands [@device,@device-protection]', () => {
10+
const help = [
11+
'Manage device protection',
12+
'Usage: particle device-protection <command>',
13+
'Help: particle help device-protection <command>',
14+
'',
15+
'Commands:',
16+
' status Gets the current device protection status',
17+
' disable Disables device protection',
18+
' enable Enables device protection',
19+
'',
20+
'Global Options:',
21+
' -v, --verbose Increases how much logging to display [count]',
22+
' -q, --quiet Decreases how much logging to display [count]',
23+
''
24+
];
25+
26+
27+
before(async () => {
28+
await cli.setTestProfileAndLogin();
29+
});
30+
31+
after(async () => {
32+
await cli.run(['usb', 'setup-done']);
33+
await cli.logout();
34+
await cli.setDefaultProfile();
35+
});
36+
37+
it('Shows `help` content', async () => {
38+
const { stdout, stderr, exitCode } = await cli.run(['help', 'device-protection']);
39+
40+
expect(stdout).to.equal('');
41+
expect(stderr.split('\n')).to.include.members(help);
42+
expect(exitCode).to.equal(0);
43+
});
44+
45+
it('Shows `help` content when run without arguments', async () => {
46+
const { stdout, stderr, exitCode } = await cli.run('device-protection');
47+
48+
expect(stdout).to.equal('');
49+
expect(stderr.split('\n')).to.include.members(help);
50+
expect(exitCode).to.equal(0);
51+
});
52+
53+
it('Shows `help` content when run with `--help` flag', async () => {
54+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', '--help']);
55+
56+
expect(stdout).to.equal('');
57+
expect(stderr.split('\n')).to.include.members(help);
58+
expect(exitCode).to.equal(0);
59+
});
60+
61+
describe('DeviceProtection Commands', () => {
62+
it('Gets the current device protection status', async () => {
63+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);
64+
65+
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
66+
expect(stderr).to.equal('');
67+
expect(exitCode).to.equal(0);
68+
});
69+
70+
it('Attempts to disable protection status on an open device', async () => {
71+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']);
72+
73+
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
74+
expect(stderr).to.equal('');
75+
expect(exitCode).to.equal(0);
76+
});
77+
78+
it('Enables protection status on the device', async () => {
79+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);
80+
81+
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.`);
82+
expect(stderr).to.equal('');
83+
expect(exitCode).to.equal(0);
84+
});
85+
86+
it('Gets the current status of the device', async () => {
87+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);
88+
89+
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.`);
90+
expect(stderr).to.equal('');
91+
expect(exitCode).to.equal(0);
92+
});
93+
94+
it('Attempts to enable protection status on a protected device', async () => {
95+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'enable']);
96+
97+
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is already a protected device.`);
98+
expect(stderr).to.equal('');
99+
expect(exitCode).to.equal(0);
100+
});
101+
102+
it('Puts the device in service mode', async () => {
103+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']);
104+
105+
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.`);
106+
expect(stderr).to.equal('');
107+
expect(exitCode).to.equal(0);
108+
});
109+
110+
it('Turns the device to an open device', async () => {
111+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);
112+
113+
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.`);
114+
expect(stderr).to.equal('');
115+
expect(exitCode).to.equal(0);
116+
});
117+
118+
it('Gets the current status of the device', async () => {
119+
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);
120+
121+
expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
122+
expect(stderr).to.equal('');
123+
expect(exitCode).to.equal(0);
124+
});
125+
126+
});
127+
128+
});
129+

0 commit comments

Comments
 (0)