Skip to content

Commit c8254f5

Browse files
committed
chore: better examples
1 parent 155c3b9 commit c8254f5

File tree

6 files changed

+93
-82
lines changed

6 files changed

+93
-82
lines changed

messages/status.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"examples": [
3-
"sfdx force:org:status --sandboxname mySandbox -u devhub",
4-
"sfdx force:org:status --sandboxname mySandbox -u devhub -w 45",
5-
"sfdx force:org:status --sandboxname mySandbox -u devhub --setalias alias",
6-
"sfdx force:org:status --sandboxname mySandbox -u devhub --setdefaultusername"
3+
"sfdx force:org:status --sandboxname DevSbx1 --setalias MySandbox -u prodOrg",
4+
"sfdx force:org:status --sandboxname DevSbx1 --wait 45 --setdefaultusername -u prodOrg"
75
],
86
"description": "report status of sandbox creation or clone and authenticate to it\nUse this command to check the status of your sandbox creation or clone and, if the sandbox is ready, authenticate to it.\nUse the --wait (-w) parameter to specify the number of minutes that the command waits for the sandbox creation or clone to complete before returning control of the terminal to you.\nSet the --targetusername (-u) parameter to the username or alias of the production org that contains the sandbox license.",
97
"flags": {

test/commands/force/org/display.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { $$, expect, test } from '@salesforce/command/lib/test';
7+
import { expect, test } from '@salesforce/command/lib/test';
88
import { Aliases, AuthInfo, Connection, Org } from '@salesforce/core';
9-
9+
import * as sinon from 'sinon';
1010
import { stubMethod, stubInterface, StubbedType } from '@salesforce/ts-sinon';
1111
import * as utils from '../../../../src/shared/utils';
1212

@@ -45,15 +45,15 @@ const fakeAuthUrl = 'fakeAuthUrl';
4545

4646
describe('org:display', () => {
4747
let authInfoStub: StubbedType<AuthInfo>;
48+
const sandbox = sinon.createSandbox();
4849

4950
beforeEach(async function () {
50-
$$.SANDBOX.restore();
51-
stubMethod($$.SANDBOX, Aliases, 'fetch')
51+
stubMethod(sandbox, Aliases, 'fetch')
5252
.withArgs('nonscratchalias')
5353
.resolves('[email protected]')
5454
.withArgs('scratchAlias')
5555
.resolves('[email protected]');
56-
stubMethod($$.SANDBOX, utils, 'getAliasByUsername')
56+
stubMethod(sandbox, utils, 'getAliasByUsername')
5757
.withArgs('[email protected]')
5858
.resolves('nonscratchalias')
5959
.withArgs('[email protected]')
@@ -62,9 +62,13 @@ describe('org:display', () => {
6262
.resolves(undefined);
6363
});
6464

65+
afterEach(() => {
66+
sandbox.restore();
67+
});
68+
6569
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6670
async function prepareStubs(AuthInfoModifications: any = {}) {
67-
authInfoStub = stubInterface<AuthInfo>($$.SANDBOX, {
71+
authInfoStub = stubInterface<AuthInfo>(sandbox, {
6872
getFields: () => ({
6973
...baseAuthInfo,
7074
...AuthInfoModifications,
@@ -76,7 +80,7 @@ describe('org:display', () => {
7680
return 'badUrl';
7781
},
7882
});
79-
stubMethod($$.SANDBOX, AuthInfo, 'create').callsFake(async () => authInfoStub);
83+
stubMethod(sandbox, AuthInfo, 'create').callsFake(async () => authInfoStub);
8084
}
8185

8286
test
@@ -206,16 +210,16 @@ describe('org:display', () => {
206210
await prepareStubs({
207211
devHubUsername: devHub.username,
208212
});
209-
stubMethod($$.SANDBOX, Org, 'create').resolves(Org.prototype);
210-
stubMethod($$.SANDBOX, Org.prototype, 'getUsername').returns('[email protected]');
213+
stubMethod(sandbox, Org, 'create').resolves(Org.prototype);
214+
stubMethod(sandbox, Org.prototype, 'getUsername').returns('[email protected]');
211215

212-
stubMethod($$.SANDBOX, Org.prototype, 'getOrgId').resolves(devHub.id);
213-
stubMethod($$.SANDBOX, Org.prototype, 'getDevHubOrg').resolves({
216+
stubMethod(sandbox, Org.prototype, 'getOrgId').resolves(devHub.id);
217+
stubMethod(sandbox, Org.prototype, 'getDevHubOrg').resolves({
214218
getUsername: () => devHub.username,
215219
});
216-
stubMethod($$.SANDBOX, Org.prototype, 'getConnection').returns(Connection.prototype);
220+
stubMethod(sandbox, Org.prototype, 'getConnection').returns(Connection.prototype);
217221

218-
stubMethod($$.SANDBOX, Connection.prototype, 'sobject').returns({
222+
stubMethod(sandbox, Connection.prototype, 'sobject').returns({
219223
find: async () => {
220224
return [
221225
{

test/commands/force/org/list.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { $$, expect, test } from '@salesforce/command/lib/test';
7+
import { expect, test } from '@salesforce/command/lib/test';
88
import * as chai from 'chai';
9+
import * as sinon from 'sinon';
910
import * as chaiAsPromised from 'chai-as-promised';
1011
import cli from 'cli-ux';
1112

@@ -18,23 +19,24 @@ import OrgListMock = require('../../../shared/orgListMock');
1819
import { OrgListUtil } from '../../../../src/shared/orgListUtil';
1920

2021
describe('org_list', () => {
22+
const sandbox = sinon.createSandbox();
2123
beforeEach(async () => {
22-
stubMethod($$.SANDBOX, AuthInfo, 'listAllAuthFiles');
24+
stubMethod(sandbox, AuthInfo, 'listAllAuthFiles');
2325
});
2426
afterEach(() => {
25-
$$.SANDBOX.restore();
27+
sandbox.restore();
2628
});
2729

2830
describe('hub org defined', () => {
2931
beforeEach(async () => {
3032
// await workspace.configureHubOrg();
31-
stubMethod($$.SANDBOX, OrgListUtil, 'readLocallyValidatedMetaConfigsGroupedByOrgType').resolves(
33+
stubMethod(sandbox, OrgListUtil, 'readLocallyValidatedMetaConfigsGroupedByOrgType').resolves(
3234
OrgListMock.AUTH_INFO
3335
);
3436
});
3537

3638
afterEach(async () => {
37-
$$.SANDBOX.restore();
39+
sandbox.restore();
3840
});
3941

4042
test
@@ -62,14 +64,14 @@ describe('org_list', () => {
6264
afterEach(() => spies.clear());
6365

6466
beforeEach(() => {
65-
$$.SANDBOX.stub(OrgListUtil, 'readLocallyValidatedMetaConfigsGroupedByOrgType').resolves(OrgListMock.AUTH_INFO);
66-
const authInfoStub = stubInterface<AuthInfo>($$.SANDBOX, {
67+
sandbox.stub(OrgListUtil, 'readLocallyValidatedMetaConfigsGroupedByOrgType').resolves(OrgListMock.AUTH_INFO);
68+
const authInfoStub = stubInterface<AuthInfo>(sandbox, {
6769
getConnectionOptions: () => ({}),
6870
});
69-
stubMethod($$.SANDBOX, Connection, 'create').resolves({});
70-
stubMethod($$.SANDBOX, AuthInfo, 'create').resolves(async () => authInfoStub);
71-
stubMethod($$.SANDBOX, Org, 'create').resolves(Org.prototype);
72-
spies.set('orgRemove', stubMethod($$.SANDBOX, Org.prototype, 'remove').resolves());
71+
stubMethod(sandbox, Connection, 'create').resolves({});
72+
stubMethod(sandbox, AuthInfo, 'create').resolves(async () => authInfoStub);
73+
stubMethod(sandbox, Org, 'create').resolves(Org.prototype);
74+
spies.set('orgRemove', stubMethod(sandbox, Org.prototype, 'remove').resolves());
7375
});
7476

7577
test

test/commands/force/org/open.test.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { $$, expect, test } from '@salesforce/command/lib/test';
7+
import { expect, test } from '@salesforce/command/lib/test';
88
import { Org, MyDomainResolver, Messages } from '@salesforce/core';
9+
import * as sinon from 'sinon';
910
import { stubMethod } from '@salesforce/ts-sinon';
1011
import * as utils from '../../../../src/shared/utils';
1112

@@ -30,20 +31,23 @@ const testJsonStructure = (response: Record<string, unknown>) => {
3031
};
3132

3233
describe('open commands', () => {
34+
const sandbox = sinon.createSandbox();
3335
const spies = new Map();
3436
afterEach(() => spies.clear());
3537

3638
beforeEach(async function () {
37-
$$.SANDBOX.restore();
38-
stubMethod($$.SANDBOX, Org, 'create').resolves(Org.prototype);
39-
stubMethod($$.SANDBOX, Org.prototype, 'getField').withArgs(Org.Fields.INSTANCE_URL).returns(testInstance);
40-
stubMethod($$.SANDBOX, Org.prototype, 'refreshAuth').resolves({});
41-
stubMethod($$.SANDBOX, Org.prototype, 'getOrgId').returns(orgId);
42-
stubMethod($$.SANDBOX, Org.prototype, 'getUsername').returns(username);
43-
stubMethod($$.SANDBOX, Org.prototype, 'getConnection').returns({
39+
stubMethod(sandbox, Org, 'create').resolves(Org.prototype);
40+
stubMethod(sandbox, Org.prototype, 'getField').withArgs(Org.Fields.INSTANCE_URL).returns(testInstance);
41+
stubMethod(sandbox, Org.prototype, 'refreshAuth').resolves({});
42+
stubMethod(sandbox, Org.prototype, 'getOrgId').returns(orgId);
43+
stubMethod(sandbox, Org.prototype, 'getUsername').returns(username);
44+
stubMethod(sandbox, Org.prototype, 'getConnection').returns({
4445
accessToken,
4546
});
46-
spies.set('open', stubMethod($$.SANDBOX, utils, 'openUrl').resolves());
47+
spies.set('open', stubMethod(sandbox, utils, 'openUrl').resolves());
48+
});
49+
afterEach(() => {
50+
sandbox.restore();
4751
});
4852

4953
describe('url generation', () => {
@@ -88,11 +92,11 @@ describe('open commands', () => {
8892

8993
describe('domain resolution, with callout', () => {
9094
beforeEach(() => {
91-
stubMethod($$.SANDBOX, MyDomainResolver, 'create').resolves(MyDomainResolver.prototype);
95+
stubMethod(sandbox, MyDomainResolver, 'create').resolves(MyDomainResolver.prototype);
9296
});
9397
test
9498
.do(() => {
95-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
99+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
96100
})
97101
.stdout()
98102
.command(['force:org:open', '--json', '--targetusername', username, '--path', testPath])
@@ -109,7 +113,7 @@ describe('open commands', () => {
109113
.do(() => {
110114
spies.set(
111115
'resolver',
112-
stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').throws({ message: 'timeout' })
116+
stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').throws({ message: 'timeout' })
113117
);
114118
})
115119
.stdout()
@@ -125,8 +129,8 @@ describe('open commands', () => {
125129

126130
describe('domain resolution, no callout', () => {
127131
beforeEach(() => {
128-
stubMethod($$.SANDBOX, MyDomainResolver, 'create').resolves(MyDomainResolver.prototype);
129-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
132+
stubMethod(sandbox, MyDomainResolver, 'create').resolves(MyDomainResolver.prototype);
133+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
130134
});
131135
it('does not wait for domains on internal urls');
132136

@@ -168,7 +172,7 @@ describe('open commands', () => {
168172
describe('human output', () => {
169173
test
170174
.do(() => {
171-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
175+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
172176
})
173177
.stdout()
174178
.command(['force:org:open', '--targetusername', username, '--path', testPath])
@@ -180,7 +184,7 @@ describe('open commands', () => {
180184

181185
test
182186
.do(() => {
183-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
187+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
184188
})
185189
.stdout()
186190
.command(['force:org:open', '--targetusername', username, '--path', testPath, '--urlonly'])
@@ -192,7 +196,7 @@ describe('open commands', () => {
192196
.do(() => {
193197
spies.set(
194198
'resolver',
195-
stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').throws({ message: 'timeout' })
199+
stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').throws({ message: 'timeout' })
196200
);
197201
})
198202
.stderr()
@@ -207,7 +211,7 @@ describe('open commands', () => {
207211
describe('browser argument', () => {
208212
test
209213
.do(() => {
210-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
214+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
211215
})
212216
.stdout()
213217
.command(['force:org:open', '--targetusername', username, '--path', testPath])
@@ -219,7 +223,7 @@ describe('open commands', () => {
219223

220224
test
221225
.do(() => {
222-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
226+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
223227
})
224228
.stdout()
225229
.command(['force:org:open', '--targetusername', username, '--path', testPath, '-b', testBrowser])
@@ -231,7 +235,7 @@ describe('open commands', () => {
231235

232236
test
233237
.do(() => {
234-
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
238+
spies.set('resolver', stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
235239
})
236240
.stdout()
237241
.command(['force:org:open', '--targetusername', username, '--path', testPath, '-b', 'duff'])

0 commit comments

Comments
 (0)