Skip to content

Commit

Permalink
Merge pull request #63 from adobe/CI-5874
Browse files Browse the repository at this point in the history
Add filtering options to fetch provider list for org
  • Loading branch information
sangeetha5491 authored Jul 12, 2023
2 parents 82c104e + 900037e commit 640ad79
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 9 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value> | -p <value>] [--instanceId <value>] [-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=<value>... 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=<value> Filter providers for org by provider metadata id (and instance id if applicable)
--providerMetadataId=<value> 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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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",
"inquirer": "^8.2.5",
Expand Down
28 changes: 27 additions & 1 deletion src/commands/event/provider/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -65,6 +73,24 @@ 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)'
}),
providerMetadataIds: Flags.string({
multiple: true,
char: 'p',
description: 'Filter providers for org by list of provider metadata ids',
exclusive: ['providerMetadataId']
}),
json: Flags.boolean({
description: 'Output json',
char: 'j',
Expand Down
48 changes: 47 additions & 1 deletion test/commands/event/provider/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -45,7 +47,7 @@ describe('console:provider:list', () => {
command = new ProviderListCommand([])
command.conf = {
org: {
id: 'ORGID'
id: ORG_ID
}
}
})
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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')
})
})
})

0 comments on commit 640ad79

Please sign in to comment.