Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for live-only flag to bots:list #127

Merged
merged 10 commits into from
Dec 8, 2022
39 changes: 30 additions & 9 deletions src/commands/bots/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export default class BotsList extends MixCommand {
static description = `list bots in an organization

Use this command to list bots for a specific Mix organization.
A number of flags can be used to constrain the returned results.`
Use flag 'full' to list all bot details, including the list of bot configs.
Use flag 'live-only' with flag 'full' to filter out
bot configs that are NOT deployed.
Use flag 'omit-overridden' with flag 'full' to filter out
bot configs that are overridden.
Flags 'live-only' and 'omit-overridden' cannot be used together.
Flags 'live-only' and 'omit-overridden' can only be used with flag 'full'.`

static examples = [
'$ mix bots:list -O 64',
Expand All @@ -31,11 +37,17 @@ A number of flags can be used to constrain the returned results.`
static flags = {
full: MixFlags.showFullBotDetailsFlag,
json: MixFlags.jsonFlag,
'live-only': flags.boolean({
description: MixFlags.liveOnlyFlag.description,
dependsOn: ['full'],
exclusive: ['omit-overridden'],
}),
organization: MixFlags.organizationFlag,
...MixFlags.tableFlags({except: ['extended']}),
'omit-overridden': flags.boolean({
description: MixFlags.omitOverriddenDesc,
dependsOn: ['full'],
exclusive: ['live-only'],
}),
yaml: MixFlags.yamlFlag,
}
Expand Down Expand Up @@ -72,13 +84,23 @@ A number of flags can be used to constrain the returned results.`

get viewType() {
debug('get viewType()')
const {full, 'live-only': liveOnly, 'omit-overridden': omitOverridden} = this.options

// oclif ensures that full is provided with either live-only/omit-overridden
// otherwise command errors out before viewType() gets called
if (!full) {
return 'BV_VIEW_UNSPECIFIED'
}

if (liveOnly) {
return 'BV_FULL_LIVE_CONFIGS'
}

if (omitOverridden) {
return 'BV_FULL_AVAILABLE_CONFIGS'
}

const {full, 'omit-overridden': omitOverridden} = this.options
return full && omitOverridden ?
'BV_FULL_AVAILABLE_CONFIGS' :
(full ?
'BV_FULL' :
'BV_VIEW_UNSPECIFIED')
return 'BV_FULL'
}

async buildRequestParameters(options: Partial<flags.Output>): Promise<BotsListParams> {
Expand All @@ -100,8 +122,7 @@ A number of flags can be used to constrain the returned results.`
debug('outputHumanReadable()')
const {columns, options} = this
if (transformedData.length === 0) {
const msg = 'No bots found.'
this.log(msg)
this.log('No bots found.')

return
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const mixApplicationIDDesc = 'Mix application ID'
export const noProjectInfoDesc = 'omit project details in table mode'
export const noChannelsDesc = 'omit channel details in table mode'
export const noDataPacksDesc = 'omit data pack details in table mode'
export const omitOverriddenDesc = 'omit application configurations that are overriden'
export const omitOverriddenDesc = 'omit application configurations that are overridden'
export const projectDesc = 'project ID'
export const projectDescriptionDesc = 'project description (for child data compliance)'
export const projectDescWithDefault = `project ID (defaults to ${projectEnvVarDefault})`
Expand Down
39 changes: 38 additions & 1 deletion test/commands/bots/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ describe('bots:list command', () => {
])
.it('bots:list omits overriden app configs in list for given organization')
// test fails if wrong view is passed

test
.nock(mixAPIServerURL, (api) =>
api
.get(endpoint)
.query({
view: 'BV_FULL_LIVE_CONFIGS',
})
.reply(200, fullBotsDetailsResponse)
)
.stdout()
.stderr()
.command(['bots:list',
`-O=${orgId}`,
'--full',
'--live-only'
])
.it('bots:list provides currently deployed app configs in list for given organization')
// test fails if wrong view is passed
}),

describe('bots:list handling of missing flags', () => {
Expand All @@ -122,6 +141,14 @@ describe('bots:list command', () => {
})
.it('bots:list errors out when no parameters supplied')

test
.stderr()
.command(['bots:list', '-O', '24', '--live-only'])
.catch(ctx => {
expect(ctx.message).to.contain('--full')
})
.it('bots:list errors out when --live-only is used without --full')

test
.stderr()
.command(['bots:list', '-O', '24', '--omit-overridden'])
Expand All @@ -131,6 +158,16 @@ describe('bots:list command', () => {
.it('bots:list errors out when --omit-overriden is used without --full')
}),

describe('bots:list handling of conflict flags', () => {
test
.stderr()
.command(['bots:list', '-O', '24', '--full', '--live-only', '--omit-overridden'])
.catch(ctx => {
expect(ctx.message).to.contain('cannot also be provided')
})
.it('bots:list errors out when --live-only and --omit-overridden supplied together')
}),

describe('bots:list handling of empty data', () => {
const orgId = '221'
const endpoint = `/v4/organizations/${orgId}/bots`
Expand All @@ -146,7 +183,7 @@ describe('bots:list command', () => {
)
.stdout()
.command(['bots:list', '-O', orgId])
.it('bots:list shows error message for organization with no bots', (ctx) => {
.it('bots:list shows relevant message if organization has no bots', (ctx) => {
expect(ctx.stdout).to.contain('No bots')
})
})
Expand Down