Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion messages/autoinstall.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand All @@ -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"
}
38 changes: 38 additions & 0 deletions src/commands/analytics/autoinstall/app/cancel.ts
Original file line number Diff line number Diff line change
@@ -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]));
}
}
18 changes: 18 additions & 0 deletions src/lib/analytics/autoinstall/autoinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,6 +176,23 @@ export default class AutoInstall {
return this.performPost(body);
}

public async cancel(autoinstallid: string): Promise<string | undefined> {
const body = JSON.stringify({
requestStatus: cancelStatusType
});

const response = await connectRequest<AutoInstallRequestType>(this.connection, {
method: 'PATCH',
url: this.autoInstallUrl + encodeURIComponent(autoinstallid),
body
});
if (response) {
return response.id;
} else {
throwError(response);
}
}

private async performPost(body: string): Promise<string | undefined> {
const response = await connectRequest<AutoInstallRequestType>(this.connection, {
method: 'POST',
Expand Down
23 changes: 23 additions & 0 deletions test/commands/autoinstall/app/cancel.test.ts
Original file line number Diff line number Diff line change
@@ -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]));
});
});