Skip to content

Commit 583fd4f

Browse files
committed
test(nuts): get default hub from current session
1 parent f3fd6c5 commit 583fd4f

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

test/nut/commands/force/org/org.nut.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import * as querystring from 'querystring';
99
import { expect } from '@salesforce/command/lib/test';
1010
import { TestSession } from '@salesforce/cli-plugins-testkit';
1111
import { execCmd } from '@salesforce/cli-plugins-testkit';
12-
import { asDictionary, AnyJson, Dictionary, getString, isArray } from '@salesforce/ts-types';
12+
import { asDictionary, AnyJson, Dictionary, getString, isArray, ensureString } from '@salesforce/ts-types';
13+
14+
let hubOrgUsername: string;
1315

1416
const verifyHumanResults = (
1517
lines: string[],
@@ -18,7 +20,7 @@ const verifyHumanResults = (
1820
verbose = false
1921
): void => {
2022
expect(lines.length).to.have.greaterThan(0);
21-
const devHubLine = lines.find((line) => line.includes(process.env.TESTKIT_HUB_USERNAME));
23+
const devHubLine = lines.find((line) => line.includes(hubOrgUsername));
2224
expect(devHubLine).to.be.ok;
2325
expect(devHubLine).to.include('(D)');
2426
expect(devHubLine).to.include('Connected');
@@ -44,15 +46,26 @@ describe('Org Command NUT', () => {
4446
let aliasedUsername: string;
4547
let defaultUserOrgId: string;
4648
let aliasUserOrgId: string;
49+
4750
before(async () => {
4851
session = await TestSession.create({
4952
project: { name: 'forceOrgList' },
5053
setupCommands: [
5154
'sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --wait 10',
5255
'sfdx force:org:create -f config/project-scratch-def.json --setalias anAlias --wait 10',
56+
'sfdx config:get defaultdevhubusername --json',
5357
],
5458
});
5559

60+
// get default devhub username
61+
if (isArray<AnyJson>(session.setup)) {
62+
hubOrgUsername = ensureString(
63+
(session.setup[2] as { result: [{ key: string; value: string }] }).result.find(
64+
(config) => config.key === 'defaultdevhubusername'
65+
)?.value
66+
);
67+
}
68+
5669
if (isArray<AnyJson>(session.setup)) {
5770
defaultUsername = getString(session.setup[0], 'result.username');
5871
defaultUserOrgId = getString(session.setup[0], 'result.orgId');
@@ -89,7 +102,7 @@ describe('Org Command NUT', () => {
89102
});
90103
expect(nonScratchOrgs).to.include(
91104
{
92-
username: process.env.TESTKIT_HUB_USERNAME,
105+
username: hubOrgUsername,
93106
defaultMarker: '(D)',
94107
isDevHub: true,
95108
connectedStatus: 'Connected',
@@ -103,7 +116,7 @@ describe('Org Command NUT', () => {
103116
const nonScratchOrgs = asDictionary(listResult.nonScratchOrgs[0]);
104117
expect(nonScratchOrgs).to.include(
105118
{
106-
username: process.env.TESTKIT_HUB_USERNAME,
119+
username: hubOrgUsername,
107120
defaultMarker: '(D)',
108121
isDevHub: true,
109122
},
@@ -124,7 +137,7 @@ describe('Org Command NUT', () => {
124137
const result = execCmd<Dictionary>('force:org:display --json', { ensureExitCode: 0 }).jsonOutput.result;
125138
expect(result).to.be.ok;
126139
expect(result).to.include({
127-
devHubId: process.env.TESTKIT_HUB_USERNAME,
140+
devHubId: hubOrgUsername,
128141
username: defaultUsername,
129142
});
130143
});
@@ -133,7 +146,7 @@ describe('Org Command NUT', () => {
133146
.jsonOutput.result;
134147
expect(result).to.be.ok;
135148
expect(result).to.include({
136-
devHubId: process.env.TESTKIT_HUB_USERNAME,
149+
devHubId: hubOrgUsername,
137150
username: aliasedUsername,
138151
});
139152
});

test/nut/commands/force/org/sandbox.sandboxNut.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@
66
*/
77
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
88
import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, StatusEvent } from '@salesforce/core';
9+
import { isArray, AnyJson, ensureString } from '@salesforce/ts-types';
910
import { expect } from 'chai';
1011

1112
Messages.importMessagesDirectory(__dirname);
1213
const messages = Messages.loadMessages('@salesforce/plugin-org', 'create');
1314

15+
let hubOrgUsername: string;
16+
1417
describe('Sandbox Orgs', () => {
1518
let session: TestSession;
1619

1720
before(async () => {
1821
session = await TestSession.create({
22+
setupCommands: ['sfdx config:get defaultdevhubusername --json'],
1923
project: { name: 'sandboxCreate' },
2024
});
25+
// get default devhub username
26+
if (isArray<AnyJson>(session.setup)) {
27+
hubOrgUsername = ensureString(
28+
(session.setup[0] as { result: [{ key: string; value: string }] }).result.find(
29+
(config) => config.key === 'defaultdevhubusername'
30+
)?.value
31+
);
32+
}
2133
});
2234

2335
it('will create a sandbox, verify it can be opened, and then attempt to delete it', async () => {
@@ -29,7 +41,7 @@ describe('Sandbox Orgs', () => {
2941
});
3042
result = execCmd<SandboxProcessObject>(
3143
// TODO: revert to org:create once out of beta
32-
`force:org:beta:create -a mySandbox -t sandbox -s licenseType='Developer' -w 60 -u ${process.env.TESTKIT_HUB_USERNAME} --json`,
44+
`force:org:beta:create -a mySandbox -t sandbox -s licenseType='Developer' -w 60 -u ${hubOrgUsername} --json`,
3345
{ timeout: 3600000 }
3446
).jsonOutput.result;
3547
// autogenerated sandbox names start with 'sbx'
@@ -41,7 +53,7 @@ describe('Sandbox Orgs', () => {
4153
expect(e.message, 'org:create DNS issue').to.include(messages.getMessage('dnsTimeout'));
4254
expect(e.exitCode, 'org:create DNS issue').to.equal(68);
4355
}
44-
const sandboxUsername = `${process.env.TESTKIT_HUB_USERNAME}.${result.SandboxName}`;
56+
const sandboxUsername = `${hubOrgUsername}.${result.SandboxName}`;
4557
// even if a DNS issue occurred, the sandbox should still be present and available.
4658
const openResult = execCmd<{ username: string }>('force:org:open -u mySandbox --urlonly --json', {
4759
ensureExitCode: 0,

test/nut/commands/force/org/status.sandboxNut.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
1010
import { expect } from 'chai';
1111
import * as shell from 'shelljs';
1212
import { AuthInfo, Connection, SandboxProcessObject } from '@salesforce/core';
13-
import { Env } from '@salesforce/kit';
14-
import { ensureString } from '@salesforce/ts-types';
13+
import { isArray, AnyJson, ensureString } from '@salesforce/ts-types';
1514

1615
let session: TestSession;
1716
let sandboxName: string;
17+
let hubOrgUsername: string;
1818

1919
function unsetAlias() {
2020
const execOptions: shell.ExecOptions = {
@@ -41,20 +41,25 @@ function logoutSandbox(username: string) {
4141
}
4242

4343
describe('test sandbox status command', () => {
44-
const env = new Env();
45-
let username: string;
46-
4744
before(async () => {
4845
session = await TestSession.create({
46+
setupCommands: ['sfdx config:get defaultdevhubusername --json'],
4947
project: {
5048
sourceDir: path.join(process.cwd(), 'test', 'nut', 'commands', 'force', 'org'),
5149
},
5250
});
53-
username = ensureString(env.getString('TESTKIT_HUB_USERNAME'));
51+
// get default devhub username
52+
if (isArray<AnyJson>(session.setup)) {
53+
hubOrgUsername = ensureString(
54+
(session.setup[0] as { result: [{ key: string; value: string }] }).result.find(
55+
(config) => config.key === 'defaultdevhubusername'
56+
)?.value
57+
);
58+
}
5459
const queryStr =
5560
"SELECT SandboxName FROM SandboxProcess WHERE Status != 'E' and Status != 'D' ORDER BY CreatedDate DESC LIMIT 1";
5661
const connection = await Connection.create({
57-
authInfo: await AuthInfo.create({ username }),
62+
authInfo: await AuthInfo.create({ username: hubOrgUsername }),
5863
});
5964
const queryResult = (await connection.tooling.query(queryStr)) as { records: SandboxProcessObject[] };
6065
expect(queryResult?.records?.length).to.equal(1);
@@ -64,12 +69,12 @@ describe('test sandbox status command', () => {
6469
afterEach(() => {
6570
unsetAlias();
6671
unsetConfig();
67-
logoutSandbox(username);
72+
logoutSandbox(hubOrgUsername);
6873
});
6974

7075
it('sandbox status command', async () => {
7176
const orgStatusResult = execCmd<SandboxProcessObject>(
72-
`force:org:status --sandboxname ${sandboxName} -u ${username} --json`,
77+
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} --json`,
7378
{
7479
ensureExitCode: 0,
7580
}
@@ -93,7 +98,7 @@ describe('test sandbox status command', () => {
9398

9499
it('sandbox status command sets setdefaultusername', async () => {
95100
const orgStatusResult = execCmd<SandboxProcessObject>(
96-
`force:org:status --sandboxname ${sandboxName} -u ${username} -s --json`,
101+
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} -s --json`,
97102
{
98103
ensureExitCode: 0,
99104
}
@@ -104,12 +109,12 @@ describe('test sandbox status command', () => {
104109
};
105110
const result = shell.exec('sfdx config:get defaultusername --json', execOptions) as shell.ShellString;
106111
expect(result.code).to.equal(0);
107-
expect(result.stdout).to.contain(`"${username}.${sandboxName}"`);
112+
expect(result.stdout).to.contain(`"${hubOrgUsername}.${sandboxName}"`);
108113
});
109114

110115
it('sandbox status command set alias', async () => {
111116
const orgStatusResult = execCmd<SandboxProcessObject>(
112-
`force:org:status --sandboxname ${sandboxName} -u ${username} -a ${sandboxName} --json`,
117+
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} -a ${sandboxName} --json`,
113118
{
114119
ensureExitCode: 0,
115120
}

0 commit comments

Comments
 (0)