diff --git a/command-snapshot.json b/command-snapshot.json index dbb8b9dc..23c51d07 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -77,6 +77,11 @@ "plugin": "@salesforce/analytics", "flags": ["apiversion", "assetid", "json", "loglevel", "targetusername"] }, + { + "command": "analytics:autoinstall:app:cancel", + "plugin": "@salesforce/analytics", + "flags": ["apiversion", "autoinstallid", "json", "loglevel", "targetusername"] + }, { "command": "analytics:autoinstall:app:create", "plugin": "@salesforce/analytics", diff --git a/messages/autoinstall.json b/messages/autoinstall.json index d3304c74..6dc58702 100644 --- a/messages/autoinstall.json +++ b/messages/autoinstall.json @@ -45,6 +45,7 @@ "enableAsyncLongDescription": "Enable asynchronously.", "enableSuccess": "Successfully enabled Analytics from auto-install request [%s]", "enableFailed": "Failure during Analytics enable from auto-install request [%s]", + "appAutoInstallCancelRequestSuccess": "Successfully created app auto-install cancel request [%s]", "appCreateAsyncDescription": "create app asynchronously", "appCreateAsyncLongDescription": "Create app asynchronously.", "appCreateRequestSuccess": "Successfully created app auto-install request to create Analytics app [%s]", @@ -59,5 +60,7 @@ "appDeleteAsyncLongDescription": "Delete app asynchronously.", "appDeleteRequestSuccess": "Successfully created app auto-install request to delete Analytics app [%s]", "appDeleteSuccess": "Successfully deleted Analytics app [%s] from auto-install request [%s]", - "appDeleteFailed": "Failure during Analytics app delete from auto-install request [%s]" + "appDeleteFailed": "Failure during Analytics app delete from auto-install request [%s]", + "cancelAutoinstallCommandDescription": "cancels app-auto install request", + "cancelAutoinstallCommandLongDescription": "Cancels app-auto install request" } diff --git a/src/commands/analytics/autoinstall/app/cancel.ts b/src/commands/analytics/autoinstall/app/cancel.ts new file mode 100644 index 00000000..8e376412 --- /dev/null +++ b/src/commands/analytics/autoinstall/app/cancel.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, Org } from '@salesforce/core'; + +import AutoInstall from '../../../../lib/analytics/autoinstall/autoinstall'; + +Messages.importMessagesDirectory(__dirname); +const messages = Messages.loadMessages('@salesforce/analytics', 'autoinstall'); + +export default class Cancel extends SfdxCommand { + public static description = messages.getMessage('cancelAutoinstallCommandDescription'); + public static longDescription = messages.getMessage('cancelAutoinstallCommandLongDescription'); + + public static examples = ['$ sfdx analytics:autoinstall:app:cancel -i id']; + + protected static flagsConfig = { + autoinstallid: flags.id({ + char: 'i', + required: true, + description: messages.getMessage('autoinstallidFlagDescription'), + longDescription: messages.getMessage('autoinstallidFlagLongDescription') + }) + }; + + protected static requiresUsername = true; + protected static requiresProject = false; + + public async run() { + const autoinstall = new AutoInstall(this.org as Org); + await autoinstall.cancel(this.flags.autoinstallid as string); + this.ux.log(messages.getMessage('appAutoInstallCancelRequestSuccess', [this.flags.autoinstallid])); + } +} diff --git a/src/lib/analytics/autoinstall/autoinstall.ts b/src/lib/analytics/autoinstall/autoinstall.ts index 59655d2f..987165af 100644 --- a/src/lib/analytics/autoinstall/autoinstall.ts +++ b/src/lib/analytics/autoinstall/autoinstall.ts @@ -65,6 +65,7 @@ const enqueuedStatus = 'Enqueued'; const createType = 'WaveAppCreate'; const updateType = 'WaveAppUpdate'; const deleteType = 'WaveAppDelete'; +const cancelStatusType = 'Cancelled'; export default class AutoInstall { public readonly serverVersion: number; @@ -175,6 +176,23 @@ export default class AutoInstall { return this.performPost(body); } + public async cancel(autoinstallid: string): Promise { + const body = JSON.stringify({ + requestStatus: cancelStatusType + }); + + const response = await connectRequest(this.connection, { + method: 'PATCH', + url: this.autoInstallUrl + encodeURIComponent(autoinstallid), + body + }); + if (response) { + return response.id; + } else { + throwError(response); + } + } + private async performPost(body: string): Promise { const response = await connectRequest(this.connection, { method: 'POST', diff --git a/test/commands/autoinstall/app/cancel.test.ts b/test/commands/autoinstall/app/cancel.test.ts new file mode 100644 index 00000000..8c42b49b --- /dev/null +++ b/test/commands/autoinstall/app/cancel.test.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import * as core from '@salesforce/core'; +import { expect, test } from '@salesforce/command/lib/test'; + +core.Messages.importMessagesDirectory(__dirname); +const messages = core.Messages.loadMessages('@salesforce/analytics', 'autoinstall'); +const autoinstallId = '0llxx000000000zCAA'; + +describe('analytics:autoinstall:app:cancel', () => { + test + .withOrg({ username: 'test@org.com' }, true) + .withConnectionRequest(() => Promise.resolve({})) + .stdout() + .command(['analytics:autoinstall:app:cancel', '-i', autoinstallId]) + .it('runs analytics:autoinstall:app:cancel -i', ctx => { + expect(ctx.stdout).to.contain(messages.getMessage('appAutoInstallCancelRequestSuccess', [autoinstallId])); + }); +});