From 325324404f8472463b9a8626cb9d53fdd7f6b43a Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Wed, 28 Jun 2023 00:08:25 +0530 Subject: [PATCH 1/2] add filtering options to fetch provider list for org --- package.json | 2 +- src/commands/event/provider/list.js | 29 +++++++++++++- test/commands/event/provider/list.test.js | 48 ++++++++++++++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 63650e3..99ecfbf 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@adobe/aio-lib-console": "^4.0.0", "@adobe/aio-lib-core-config": "^3.0.0", "@adobe/aio-lib-core-logging": "^2.0.0", - "@adobe/aio-lib-events": "^3.0.0", + "@adobe/aio-lib-events": "^3.1.0", "@adobe/aio-lib-ims": "^6.0.1", "@oclif/core": "^1.5.2", "js-yaml": "^3.13.1", diff --git a/src/commands/event/provider/list.js b/src/commands/event/provider/list.js index 629d9be..6f868a2 100644 --- a/src/commands/event/provider/list.js +++ b/src/commands/event/provider/list.js @@ -20,7 +20,15 @@ class ProviderListCommand extends BaseCommand { try { await this.initSdk() cli.action.start('Fetching all Event Providers') - const providers = await this.eventClient.getAllProviders(this.conf.org.id) + const options = { + fetchEventMetadata: flags.fetchEventMetadata, + filterBy: { + providerMetadataId: flags.providerMetadataId, + instanceId: flags.instanceId, + providerMetadataIds: flags.providerMetadataIds + } + } + const providers = await this.eventClient.getAllProviders(this.conf.org.id, options) cli.action.stop() if (flags.json) { this.printJson(providers) @@ -65,6 +73,25 @@ ProviderListCommand.aliases = [ ProviderListCommand.flags = { ...BaseCommand.flags, + fetchEventMetadata: Flags.boolean({ + description: 'Fetch event metadata with provider' + }), + providerMetadataId: Flags.string({ + multiple: false, + description: 'Filter providers for org by provider metadata id (and instance id if applicable)', + exclusive: ['providerMetadataIds'] + }), + instanceId: Flags.string({ + multiple: false, + description: 'Filter providers for org by provider metadata id (and instance id if applicable)', + exclusive: ['providerMetadataIds'] + }), + providerMetadataIds: Flags.string({ + multiple: true, + char: 'p', + description: 'Filter providers for org by list of provider metadata ids', + exclusive: ['providerMetadataId', 'instanceId'] + }), json: Flags.boolean({ description: 'Output json', char: 'j', diff --git a/test/commands/event/provider/list.test.js b/test/commands/event/provider/list.test.js index e78c713..693a491 100644 --- a/test/commands/event/provider/list.test.js +++ b/test/commands/event/provider/list.test.js @@ -14,6 +14,8 @@ const { stdout } = require('stdout-stderr') const mock = require('../../../mocks') const ProviderListCommand = require('../../../../src/commands/event/provider/list') +const ORG_ID = 'ORGID' + test('exports', async () => { expect(typeof ProviderListCommand).toEqual('function') expect(ProviderListCommand.prototype instanceof Command).toBeTruthy() @@ -45,7 +47,7 @@ describe('console:provider:list', () => { command = new ProviderListCommand([]) command.conf = { org: { - id: 'ORGID' + id: ORG_ID } } }) @@ -84,6 +86,45 @@ describe('console:provider:list', () => { await expect(command.run()).resolves.not.toThrowError() expect(stdout.output).toMatchFixture('provider/list.yml') }) + + test('should return list of providers with event metadata', async () => { + command.argv = ['--fetchEventMetadata'] + await expect(command.run()).resolves.not.toThrowError() + expect(command.eventClient.getAllProviders).toHaveBeenCalledWith(ORG_ID, { + fetchEventMetadata: true, + filterBy: { + instanceId: undefined, + providerMetadataId: undefined, + providerMetadataIds: undefined + } + }) + }) + + test('should return providers for provider metadata id and instance id', async () => { + command.argv = ['--providerMetadataId', 'pm-1', '--instanceId', 'instance1'] + await expect(command.run()).resolves.not.toThrowError() + expect(command.eventClient.getAllProviders).toHaveBeenCalledWith(ORG_ID, { + fetchEventMetadata: undefined, + filterBy: { + instanceId: 'instance1', + providerMetadataId: 'pm-1', + providerMetadataIds: undefined + } + }) + }) + + test('should return list of providers for provider metadata id list', async () => { + command.argv = ['--providerMetadataIds', 'pm-1', 'pm-2'] + await expect(command.run()).resolves.not.toThrowError() + expect(command.eventClient.getAllProviders).toHaveBeenCalledWith(ORG_ID, { + fetchEventMetadata: undefined, + filterBy: { + instanceId: undefined, + providerMetadataId: undefined, + providerMetadataIds: ['pm-1', 'pm-2'] + } + }) + }) }) describe('fail to fetch list of providers', () => { @@ -100,5 +141,10 @@ describe('console:provider:list', () => { test('should return error on get list of providers', async () => { await expect(command.run()).rejects.toThrowError(new Error('Error retrieving providers')) }) + + test('should return error on passing both providerMetadataId and providerMetadataIds flags', async () => { + command.argv = ['--providerMetadataId', 'pm-1', '--providerMetadataIds', 'pm-1', 'pm-2'] + await expect(command.run()).rejects.toThrow('--providerMetadataId=pm-1 cannot also be provided when using --providerMetadataIds') + }) }) }) From acacc00213404465f9e178c8a5675020afa79449 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Wed, 28 Jun 2023 00:16:05 +0530 Subject: [PATCH 2/2] update documentation and remove unnecessary exclusions --- README.md | 17 +++++++++++------ src/commands/event/provider/list.js | 5 ++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e90c5aa..25e2abf 100644 --- a/README.md +++ b/README.md @@ -326,14 +326,19 @@ Get list of all Providers for the Organization ``` USAGE - $ aio event provider list [--help] [-v] [--version] [-j | -y] + $ aio event provider list [--help] [-v] [--version] [--fetchEventMetadata] [--providerMetadataId | -p ] [--instanceId ] [-j | -y] FLAGS - -j, --json Output json - -v, --verbose Verbose output - -y, --yml Output yml - --help Show help - --version Show version + -j, --json Output json + -p, --providerMetadataIds=... Filter providers for org by list of provider metadata ids + -v, --verbose Verbose output + -y, --yml Output yml + --fetchEventMetadata Fetch event metadata with provider + --help Show help + --instanceId= Filter providers for org by provider metadata id (and instance id if applicable) + --providerMetadataId= Filter providers for org by provider metadata id (and instance id if applicable) + --version Show version + DESCRIPTION Get list of all Providers for the Organization diff --git a/src/commands/event/provider/list.js b/src/commands/event/provider/list.js index 6f868a2..ed51960 100644 --- a/src/commands/event/provider/list.js +++ b/src/commands/event/provider/list.js @@ -83,14 +83,13 @@ ProviderListCommand.flags = { }), instanceId: Flags.string({ multiple: false, - description: 'Filter providers for org by provider metadata id (and instance id if applicable)', - exclusive: ['providerMetadataIds'] + description: 'Filter providers for org by provider metadata id (and instance id if applicable)' }), providerMetadataIds: Flags.string({ multiple: true, char: 'p', description: 'Filter providers for org by list of provider metadata ids', - exclusive: ['providerMetadataId', 'instanceId'] + exclusive: ['providerMetadataId'] }), json: Flags.boolean({ description: 'Output json',