From c25c2bc8a84b49bcde743f67894cf1867851a6af Mon Sep 17 00:00:00 2001 From: keeramis Date: Tue, 14 May 2024 01:34:56 -0700 Subject: [PATCH 1/2] Remove private and publish args --- src/cli/publish.js | 9 --------- src/cli/publish.test.js | 6 +----- src/cmd/api.js | 4 ++-- src/cmd/publish.js | 8 +++----- src/lib/api-client.js | 10 +++------- test/e2e/publish.e2e.js | 31 +------------------------------ 6 files changed, 10 insertions(+), 58 deletions(-) diff --git a/src/cli/publish.js b/src/cli/publish.js index d424a1d2e..07a59d1aa 100644 --- a/src/cli/publish.js +++ b/src/cli/publish.js @@ -2,15 +2,6 @@ module.exports = ({ commandProcessor, root }) => { commandProcessor.createCommand(root, 'publish', 'Publish an event to the cloud', { params: ' [data]', options: { - 'private': { - boolean: true, - default: true, - description: 'Publish to the private stream' - }, - 'public': { - boolean: true, - description: 'Publish to the public stream' - }, 'product': { description: 'Publish to the given Product ID or Slug\'s stream' } diff --git a/src/cli/publish.test.js b/src/cli/publish.test.js index e2c1da3bb..edc99acc8 100644 --- a/src/cli/publish.test.js +++ b/src/cli/publish.test.js @@ -25,11 +25,9 @@ describe('Publish Command-Line Interface', () => { }); it('Parses options', () => { - const argv = commandProcessor.parse(root, ['publish', 'my-event', '--private', '--public', '--product', '12345']); + const argv = commandProcessor.parse(root, ['publish', 'my-event', '--product', '12345']); expect(argv.clierror).to.equal(undefined); expect(argv.params).to.eql({ event: 'my-event', data: undefined }); - expect(argv.private).to.equal(true); - expect(argv.public).to.equal(true); expect(argv.product).to.equal('12345'); }); @@ -56,8 +54,6 @@ describe('Publish Command-Line Interface', () => { 'Usage: particle publish [options] [data]', '', 'Options:', - ' --private Publish to the private stream [boolean] [default: true]', - ' --public Publish to the public stream [boolean]', ' --product Publish to the given Product ID or Slug\'s stream [string]', '', 'Examples:', diff --git a/src/cmd/api.js b/src/cmd/api.js index 28c5cf8fc..a8a25cdd1 100644 --- a/src/cmd/api.js +++ b/src/cmd/api.js @@ -209,13 +209,13 @@ module.exports = class ParticleApi { ); } - publishEvent(name, data, isPrivate, product){ + publishEvent(name, data, product){ return this._wrap( this.api.publishEvent({ name, data, product, - isPrivate, + isPrivate: true, auth: this.accessToken }) ); diff --git a/src/cmd/publish.js b/src/cmd/publish.js index 67f61fdc8..6364e2342 100644 --- a/src/cmd/publish.js +++ b/src/cmd/publish.js @@ -11,16 +11,14 @@ module.exports = class PublishCommand extends CLICommandBase { super(...args); } - publishEvent({ private: isPrivate, public: isPublic, product, params: { event, data } }){ - isPrivate = (isPublic && !product) ? false : isPrivate; // `isPrivate: true` by default see: src/cli/publish.js - const visibility = isPrivate ? 'private' : 'public'; - let epilogue = `${visibility} event: ${event}`; + publishEvent({ product, params: { event, data } }){ + let epilogue = `private event: ${event}`; if (product){ epilogue += ` to product: ${product}`; } - const publishEvent = createAPI().publishEvent(event, data, isPrivate, product); + const publishEvent = createAPI().publishEvent(event, data, product); return this.ui.showBusySpinnerUntilResolved(`Publishing ${epilogue}`, publishEvent) .then(() => this.ui.stdout.write(`Published ${epilogue}${os.EOL}${os.EOL}`)) .catch(error => { diff --git a/src/lib/api-client.js b/src/lib/api-client.js index f020470f1..05b8c92ce 100644 --- a/src/lib/api-client.js +++ b/src/lib/api-client.js @@ -946,7 +946,7 @@ module.exports = class ApiClient { }); } - publishEvent(eventName, data, setPrivate){ + publishEvent(eventName, data){ const { request, _access_token: token } = this; let self = this; @@ -959,7 +959,7 @@ module.exports = class ApiClient { name: eventName, data: data, access_token: token, - private: setPrivate + private: true } }; @@ -977,11 +977,7 @@ module.exports = class ApiClient { return reject(body); } - console.log( - `Published ${setPrivate ? 'private' : 'public'}`, - 'event:', - eventName - ); + console.log(`Published private event: ${eventName}`); console.log(''); resolve(body); }); diff --git a/test/e2e/publish.e2e.js b/test/e2e/publish.e2e.js index 72ea9ba93..bf0f27734 100644 --- a/test/e2e/publish.e2e.js +++ b/test/e2e/publish.e2e.js @@ -16,8 +16,6 @@ describe('Publish Commands', () => { '', 'Options:', ' --private Publish to the private stream [boolean] [default: true]', - ' --public Publish to the public stream [boolean]', - ' --product Publish to the given Product ID or Slug\'s stream [string]', '', 'Examples:', ' particle publish temp 25.0 Publish a temp event to your private event stream', @@ -66,24 +64,6 @@ describe('Publish Commands', () => { expect(exitCode).to.equal(0); }); - it('Publishes a private event', async () => { - const args = ['publish', eventName, '--private']; - const { stdout, stderr, exitCode } = await cli.run(args); - - expect(stdout).to.include(`Published private event: ${eventName}${os.EOL}`); - expect(stderr).to.equal(''); - expect(exitCode).to.equal(0); - }); - - it('Publishes a public event', async () => { - const args = ['publish', eventName, '--public']; - const { stdout, stderr, exitCode } = await cli.run(args); - - expect(stdout).to.include(`Published public event: ${eventName}${os.EOL}`); - expect(stderr).to.equal(''); - expect(exitCode).to.equal(0); - }); - it('Publishes a product event', async () => { const args = ['publish', eventName, '--product', PRODUCT_01_ID]; const { stdout, stderr, exitCode } = await cli.run(args); @@ -94,16 +74,7 @@ describe('Publish Commands', () => { }); it('Publishes a private product event', async () => { - const args = ['publish', eventName, '--product', PRODUCT_01_ID, '--private']; - const { stdout, stderr, exitCode } = await cli.run(args); - - expect(stdout).to.include(`Published private event: ${eventName} to product: ${PRODUCT_01_ID}${os.EOL}`); - expect(stderr).to.equal(''); - expect(exitCode).to.equal(0); - }); - - it('Ignores `--public` flag when publishing a product event', async () => { - const args = ['publish', eventName, '--product', PRODUCT_01_ID, '--public']; + const args = ['publish', eventName, '--product', PRODUCT_01_ID]; const { stdout, stderr, exitCode } = await cli.run(args); expect(stdout).to.include(`Published private event: ${eventName} to product: ${PRODUCT_01_ID}${os.EOL}`); From 461b2ad4a4a596cd00292e123f4875915e09fa6f Mon Sep 17 00:00:00 2001 From: keeramis Date: Tue, 14 May 2024 23:44:38 -0700 Subject: [PATCH 2/2] Minor fix in the tests --- test/e2e/publish.e2e.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/publish.e2e.js b/test/e2e/publish.e2e.js index bf0f27734..c5a077a57 100644 --- a/test/e2e/publish.e2e.js +++ b/test/e2e/publish.e2e.js @@ -15,7 +15,7 @@ describe('Publish Commands', () => { ' -q, --quiet Decreases how much logging to display [count]', '', 'Options:', - ' --private Publish to the private stream [boolean] [default: true]', + ' --product Publish to the given Product ID or Slug\'s stream [string]', '', 'Examples:', ' particle publish temp 25.0 Publish a temp event to your private event stream',