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

W-16972747 Sl/w 16972747 #1257

Merged
merged 11 commits into from
Nov 13, 2024
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
24 changes: 0 additions & 24 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
## [5.1.4](https://github.com/salesforcecli/plugin-org/compare/5.1.3...5.1.4) (2024-11-10)

### Bug Fixes

- **deps:** bump @salesforce/source-deploy-retrieve ([4ffc31e](https://github.com/salesforcecli/plugin-org/commit/4ffc31edb50ddd778089bdfba017f17e5fb5dd44))

## [5.1.3](https://github.com/salesforcecli/plugin-org/compare/5.1.2...5.1.3) (2024-11-10)

### Bug Fixes

- **deps:** bump @salesforce/sf-plugins-core from 12.0.9 to 12.0.11 ([8eee152](https://github.com/salesforcecli/plugin-org/commit/8eee152e796144653a6c3152653ccac52dd33531))

## [5.1.2](https://github.com/salesforcecli/plugin-org/compare/5.1.1...5.1.2) (2024-11-03)

### Bug Fixes

- **deps:** bump @salesforce/source-deploy-retrieve ([a81d795](https://github.com/salesforcecli/plugin-org/commit/a81d7953e712a0c901ae6b5b8d6224ba495435de))

## [5.1.1](https://github.com/salesforcecli/plugin-org/compare/5.1.0...5.1.1) (2024-11-03)

### Bug Fixes

- **deps:** bump @salesforce/core from 8.6.3 to 8.6.4 ([e4775b9](https://github.com/salesforcecli/plugin-org/commit/e4775b9aed2edfb42aed8bd72c988694b3f5c38f))

# [5.1.0](https://github.com/salesforcecli/plugin-org/compare/5.0.2...5.1.0) (2024-10-30)

### Features
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ FLAG DESCRIPTIONS
You can specify either --source-sandbox-name or --source-id when cloning an existing sandbox, but not both.
```

_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/create/sandbox.ts)_
_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/create/sandbox.ts)_

## `sf org create scratch`

Expand Down Expand Up @@ -395,7 +395,7 @@ FLAG DESCRIPTIONS
Omit this flag to have Salesforce generate a unique username for your org.
```

_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/create/scratch.ts)_
_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/create/scratch.ts)_

## `sf org delete sandbox`

Expand Down Expand Up @@ -441,7 +441,7 @@ EXAMPLES
$ sf org delete sandbox --target-org my-sandbox --no-prompt
```

_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/delete/sandbox.ts)_
_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/delete/sandbox.ts)_

## `sf org delete scratch`

Expand Down Expand Up @@ -485,7 +485,7 @@ EXAMPLES
$ sf org delete scratch --target-org my-scratch-org --no-prompt
```

_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/delete/scratch.ts)_
_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/delete/scratch.ts)_

## `sf org disable tracking`

Expand Down Expand Up @@ -524,7 +524,7 @@ EXAMPLES
$ sf org disable tracking
```

_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/disable/tracking.ts)_
_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/disable/tracking.ts)_

## `sf org display`

Expand Down Expand Up @@ -569,7 +569,7 @@ EXAMPLES
$ sf org display --target-org TestOrg1 --verbose
```

_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/display.ts)_
_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/display.ts)_

## `sf org enable tracking`

Expand Down Expand Up @@ -611,7 +611,7 @@ EXAMPLES
$ sf org enable tracking
```

_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/enable/tracking.ts)_
_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/enable/tracking.ts)_

## `sf org list`

Expand Down Expand Up @@ -650,7 +650,7 @@ EXAMPLES
$ sf org list --clean
```

_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/list.ts)_
_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/list.ts)_

## `sf org list metadata`

Expand Down Expand Up @@ -717,7 +717,7 @@ FLAG DESCRIPTIONS
Examples of metadata types that use folders are Dashboard, Document, EmailTemplate, and Report.
```

_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/list/metadata.ts)_
_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/list/metadata.ts)_

## `sf org list metadata-types`

Expand Down Expand Up @@ -772,7 +772,7 @@ FLAG DESCRIPTIONS
Override the api version used for api requests made by this command
```

_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/list/metadata-types.ts)_
_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/list/metadata-types.ts)_

## `sf org open`

Expand Down Expand Up @@ -848,7 +848,7 @@ EXAMPLES
$ sf org open --source-file force-app/main/default/bots/Coral_Cloud_Agent/Coral_Cloud_Agent.bot-meta.xml
```

_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/open.ts)_
_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/open.ts)_

## `sf org refresh sandbox`

Expand Down Expand Up @@ -925,7 +925,7 @@ FLAG DESCRIPTIONS
By default, a sandbox auto-activates after a refresh. Use this flag to control sandbox activation manually.
```

_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/refresh/sandbox.ts)_
_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/refresh/sandbox.ts)_

## `sf org resume sandbox`

Expand Down Expand Up @@ -988,7 +988,7 @@ FLAG DESCRIPTIONS
returns the job ID. To resume checking the sandbox creation, rerun this command.
```

_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/resume/sandbox.ts)_
_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/resume/sandbox.ts)_

## `sf org resume scratch`

Expand Down Expand Up @@ -1035,6 +1035,6 @@ FLAG DESCRIPTIONS
The job ID is valid for 24 hours after you start the scratch org creation.
```

_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.4/src/commands/org/resume/scratch.ts)_
_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/5.1.0/src/commands/org/resume/scratch.ts)_

<!-- commandsstop -->
4 changes: 4 additions & 0 deletions messages/delete_scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ Successfully deleted scratch org %s.
# error.missingUsername

Unable to determine the username of the org to delete. Specify the username with the --target-org | -o flag.

# error.unknownScratch

Unable to find a scratch org with username %s.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"@oclif/multi-stage-output": "^0.7.8",
"@salesforce/core": "^8.6.4",
"@salesforce/kit": "^3.2.3",
"@salesforce/sf-plugins-core": "^12.0.11",
"@salesforce/source-deploy-retrieve": "^12.10.1",
"@salesforce/sf-plugins-core": "^12.0.9",
"@salesforce/source-deploy-retrieve": "^12.8.1",
"@salesforce/ts-types": "^2.0.12",
"ansis": "^3.2.0",
"change-case": "^5.4.4",
"is-wsl": "^3.1.0",
Expand Down
13 changes: 9 additions & 4 deletions src/commands/org/delete/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { AuthInfo, AuthRemover, Messages, Org } from '@salesforce/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { ensureString } from '@salesforce/ts-types';
import { orgThatMightBeDeleted } from '../../../shared/flags.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand Down Expand Up @@ -37,17 +38,18 @@ export default class DeleteScratch extends SfCommand<ScratchDeleteResponse> {
public async run(): Promise<ScratchDeleteResponse> {
const flags = (await this.parse(DeleteScratch)).flags;
const resolvedUsername = flags['target-org'];
const orgId = (await AuthInfo.create({ username: resolvedUsername })).getFields().orgId as string;
const { orgId, isScratch } = (await AuthInfo.create({ username: resolvedUsername })).getFields();
if (!isScratch) {
throw messages.createError('error.unknownScratch', [resolvedUsername]);
}

if (
flags['no-prompt'] ||
(await this.confirm({ message: messages.getMessage('prompt.confirm', [resolvedUsername]) }))
) {
try {
const org = await Org.create({ aliasOrUsername: resolvedUsername });

await org.delete();
this.logSuccess(messages.getMessage('success', [org.getUsername()]));
return { username: org.getUsername() as string, orgId: org.getOrgId() };
} catch (e) {
if (e instanceof Error && e.name === 'DomainNotFoundError') {
Expand All @@ -63,6 +65,9 @@ export default class DeleteScratch extends SfCommand<ScratchDeleteResponse> {
}
}
}
return { username: resolvedUsername, orgId };
return {
username: resolvedUsername,
orgId: ensureString(orgId),
};
}
}
34 changes: 34 additions & 0 deletions test/unit/org/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ describe('org delete', () => {
});

it('will prompt before attempting to delete by username', async () => {
$$.SANDBOX.stub(AuthInfo.prototype, 'getFields').returns({
orgId: testOrg.orgId,
isScratch: true,
});
await $$.stubConfig({ 'target-org': testOrg.username });
const res = await DeleteScratch.run([]);
expect(prompterStubs.confirm.callCount).to.equal(1);
Expand All @@ -153,7 +157,27 @@ describe('org delete', () => {
expect(res).to.deep.equal({ orgId: testOrg.orgId, username: testOrg.username });
});

it('will throw an error when the org is not identified as a scratch', async () => {
$$.SANDBOX.stub(AuthInfo.prototype, 'getFields').returns({
orgId: testOrg.orgId,
isScratch: false,
});
await $$.stubConfig({ 'target-org': testOrg.username });
try {
await DeleteScratch.run(['--target-org', testOrg.username]);
expect.fail('should have thrown UnknownScratchError');
} catch (e) {
const err = e as SfError;
expect(err.name).to.equal('UnknownScratchError');
}
});

it('will prompt before attempting to delete by alias', async () => {
$$.SANDBOX.stub(AuthInfo.prototype, 'getFields').returns({
orgId: testOrg.orgId,
isScratch: true,
});

await $$.stubConfig({ 'target-org': 'myAlias' });
$$.stubAliases({ myAlias: testOrg.username });
const res = await DeleteScratch.run(['--target-org', 'myAlias']);
Expand All @@ -166,6 +190,12 @@ describe('org delete', () => {

it('will NOT prompt before deleting scratch org when flag is provided', async () => {
await $$.stubConfig({ 'target-org': testOrg.username });
$$.SANDBOX.stub(AuthInfo.prototype, 'getFields').returns({
orgId: testOrg.orgId,
isScratch: true,
});
orgDeleteStub.restore();
$$.SANDBOX.stub(Org.prototype, 'delete').throws(new SfError('bah!', 'DomainNotFoundError'));
const res = await DeleteScratch.run(['--no-prompt', '--target-org', testOrg.username]);
expect(prompterStubs.confirm.calledOnce).to.equal(false);
expect(sfCommandUxStubs.logSuccess.callCount).to.equal(1);
Expand All @@ -176,6 +206,10 @@ describe('org delete', () => {
});

it('will catch the ScratchOrgNotFound and wrap correctly', async () => {
$$.SANDBOX.stub(AuthInfo.prototype, 'getFields').returns({
orgId: testOrg.orgId,
isScratch: true,
});
orgDeleteStub.restore();
$$.SANDBOX.stub(Org.prototype, 'delete').throws(new SfError('bah!', 'ScratchOrgNotFound'));
const res = await DeleteScratch.run(['--no-prompt', '--target-org', testOrg.username]);
Expand Down
Loading
Loading