UNPKG

particle-cli

Version:

Simple Node commandline application for working with your Particle devices and using the Particle Cloud

140 lines (125 loc) 5.64 kB
const { expect } = require('../../test/setup'); const commandProcessor = require('../app/command-processor'); const product = require('./product'); describe('Product Command-Line Interface', () => { let root; beforeEach(() => { root = commandProcessor.createAppCategory(); product({ root, commandProcessor }); }); describe('Top-Level `product` Namespace', () => { it('Handles `product` command', () => { const argv = commandProcessor.parse(root, ['product']); expect(argv.clierror).to.equal(undefined); expect(argv.params).to.equal(undefined); }); it('Includes help with examples', () => { commandProcessor.parse(root, ['product', '--help']); commandProcessor.showHelp((helpText) => { expect(helpText).to.equal([ 'Access Particle Product functionality [BETA]', 'Usage: particle product <command>', 'Help: particle help product <command>', '', 'Commands:', ' device Manage the devices associated with your product', '' ].join('\n')); }); }); }); describe('Handles `product device` Namespace', () => { it('Handles `product` command', () => { const argv = commandProcessor.parse(root, ['product', 'device']); expect(argv.clierror).to.equal(undefined); expect(argv.params).to.equal(undefined); }); it('Includes help with examples', () => { commandProcessor.parse(root, ['product', 'device', '--help']); commandProcessor.showHelp((helpText) => { expect(helpText).to.equal([ 'Manage the devices associated with your product', 'Usage: particle product device <command>', 'Help: particle help product device <command>', '', 'Commands:', ' list List all devices that are part of a product', ' add Adds one or more devices into a Product', ' remove Removes a device from a Product', '' ].join('\n')); }); }); }); describe('Handles `product device list` Command', () => { it('Parses arguments', () => { const argv = commandProcessor.parse(root, ['product', 'device', 'list', '12345']); expect(argv.clierror).to.equal(undefined); expect(argv.params).to.eql({ product: '12345', device: undefined }); }); it('Errors when required arguments are missing', () => { const argv = commandProcessor.parse(root, ['product', 'device', 'list']); expect(argv.clierror).to.be.an.instanceof(Error); expect(argv.clierror).to.have.property('message', 'Parameter \'product\' is required.'); expect(argv.clierror).to.have.property('data', 'product'); expect(argv.clierror).to.have.property('isUsageError', true); expect(argv.params).to.eql({}); }); it('Includes help with examples', () => { const termWidth = null; // don't right-align option type labels so testing is easier commandProcessor.parse(root, ['product', 'device', 'list', '--help'], termWidth); commandProcessor.showHelp((helpText) => { expect(helpText).to.equal([ 'List all devices that are part of a product', 'Usage: particle product device list [options] <product> [device]', '', 'Options:', ' --name, -n Filter to devices with this name (partial matching) [string]', ' --page, -p Start listing at the given page number [number]', ' --limit, -l The number of items to show per page [number]', ' --groups, -g Space separated list of groups to include [array]', ' --json Output JSON formatted data (experimental) [boolean]', '', 'Examples:', ' particle product device list 12345 Lists devices in product `12345`', ' particle product device list 12345 0123456789abcdef01234567 Get details for device with id `0123456789abcdef01234567` within in product `12345`', ' particle product device list 12345 --groups foo bar Lists devices in product which are assigned the `foo` or `bar` groups', '' ].join('\n')); }); }); }); describe('Handles `product device add` Command', () => { it('Parses arguments', () => { const argv = commandProcessor.parse(root, ['product', 'device', 'add', '12345', '5a8ef38cb85f8720edce631a']); expect(argv.clierror).to.equal(undefined); expect(argv.params).to.eql({ product: '12345', deviceID: '5a8ef38cb85f8720edce631a' }); }); it('Errors when required arguments are missing', () => { const argv = commandProcessor.parse(root, ['product', 'device', 'add']); expect(argv.clierror).to.be.an.instanceof(Error); expect(argv.clierror).to.have.property('message', 'Parameter \'product\' is required.'); expect(argv.clierror).to.have.property('data', 'product'); expect(argv.clierror).to.have.property('isUsageError', true); expect(argv.params).to.eql({}); }); it('Includes help with examples', () => { const termWidth = null; // don't right-align option type labels so testing is easier commandProcessor.parse(root, ['product', 'device', 'add', '--help'], termWidth); commandProcessor.showHelp((helpText) => { expect(helpText).to.equal([ 'Adds one or more devices into a Product', 'Usage: particle product device add [options] <product> [deviceID]', '', 'Options:', ' --file, -f Path to single column .txt file with list of IDs, S/Ns, IMEIs, or ICCIDs of the devices to add [string]', '', 'Examples:', ' particle product device add 12345 0123456789abcdef01234567 Add device id `0123456789abcdef01234567` into product `12345`', ' particle product device add 12345 --file ./path/to/device_ids.txt Adds a list of devices into product `12345`', '' ].join('\n')); }); }); }); });