Skip to content

Commit 662a4b8

Browse files
Merge pull request #316 from salesforcecli/bm/W-10100779
test: for open and status commands
2 parents 0e970e7 + 2d8141e commit 662a4b8

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2021, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
9+
import { expect } from 'chai';
10+
11+
let session: TestSession;
12+
13+
describe('test org:open command', () => {
14+
before(async () => {
15+
session = await TestSession.create({
16+
project: { name: 'forceOrgList' },
17+
setupCommands: ['sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --wait 10'],
18+
});
19+
});
20+
21+
it('org:open command', async () => {
22+
const result = execCmd('force:org:open --urlonly --json', {
23+
ensureExitCode: 0,
24+
}).jsonOutput.result as { url: string; orgId: string; username: string };
25+
expect(result).to.be.ok;
26+
expect(result).to.have.keys(['url', 'orgId', 'username']);
27+
expect(result?.url).to.include('/secur/frontdoor.jsp');
28+
});
29+
30+
after(async () => {
31+
await session.zip(undefined, 'artifacts');
32+
await session.clean();
33+
});
34+
});
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2021, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import * as path from 'path';
9+
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
10+
import { expect } from 'chai';
11+
import * as shell from 'shelljs';
12+
import { AuthInfo, Connection, SandboxProcessObject } from '@salesforce/core';
13+
import { Env } from '@salesforce/kit';
14+
import { ensureString } from '@salesforce/ts-types';
15+
16+
let session: TestSession;
17+
let sandboxName: string;
18+
19+
function unsetAlias() {
20+
const execOptions: shell.ExecOptions = {
21+
silent: true,
22+
};
23+
shell.exec(`sfdx alias:unset ${sandboxName}`, execOptions) as shell.ShellString;
24+
}
25+
26+
function unsetConfig() {
27+
const execOptions: shell.ExecOptions = {
28+
silent: true,
29+
};
30+
shell.exec('sfdx config:unset defaultusername -g', execOptions) as shell.ShellString;
31+
}
32+
33+
function logoutSandbox(username: string) {
34+
const execOptions: shell.ExecOptions = {
35+
silent: true,
36+
};
37+
const rv = shell.exec(`sfdx auth:logout -u ${username}.${sandboxName} --noprompt`, execOptions) as shell.ShellString;
38+
if (rv.code !== 0) {
39+
throw new Error(`sfdx auth:logout failed with error:\n${rv.stderr}`);
40+
}
41+
}
42+
43+
describe('test sandbox status command', () => {
44+
const env = new Env();
45+
let username: string;
46+
47+
before(async () => {
48+
session = await TestSession.create({
49+
project: {
50+
sourceDir: path.join(process.cwd(), 'test', 'nut', 'commands', 'force', 'org'),
51+
},
52+
});
53+
username = ensureString(env.getString('TESTKIT_HUB_USERNAME'));
54+
const queryStr =
55+
"SELECT SandboxName FROM SandboxProcess WHERE Status != 'E' and Status != 'D' ORDER BY CreatedDate DESC LIMIT 1";
56+
const connection = await Connection.create({
57+
authInfo: await AuthInfo.create({ username }),
58+
});
59+
const queryResult = (await connection.tooling.query(queryStr)) as { records: SandboxProcessObject[] };
60+
expect(queryResult?.records?.length).to.equal(1);
61+
sandboxName = queryResult?.records[0]?.SandboxName;
62+
});
63+
64+
afterEach(() => {
65+
unsetAlias();
66+
unsetConfig();
67+
logoutSandbox(username);
68+
});
69+
70+
it('sandbox status command', async () => {
71+
const orgStatusResult = execCmd<SandboxProcessObject>(
72+
`force:org:status --sandboxname ${sandboxName} -u ${username} --json`,
73+
{
74+
ensureExitCode: 0,
75+
}
76+
).jsonOutput.result;
77+
expect(orgStatusResult).to.be.a('object');
78+
expect(orgStatusResult).to.have.all.keys([
79+
'attributes',
80+
'Id',
81+
'Status',
82+
'SandboxName',
83+
'SandboxInfoId',
84+
'LicenseType',
85+
'CreatedDate',
86+
'CopyProgress',
87+
'SandboxOrganization',
88+
'SourceId',
89+
'Description',
90+
'EndDate',
91+
]);
92+
});
93+
94+
it('sandbox status command sets setdefaultusername', async () => {
95+
const orgStatusResult = execCmd<SandboxProcessObject>(
96+
`force:org:status --sandboxname ${sandboxName} -u ${username} -s --json`,
97+
{
98+
ensureExitCode: 0,
99+
}
100+
).jsonOutput.result;
101+
expect(orgStatusResult).to.be.ok;
102+
const execOptions: shell.ExecOptions = {
103+
silent: true,
104+
};
105+
const result = shell.exec('sfdx config:get defaultusername --json', execOptions) as shell.ShellString;
106+
expect(result.code).to.equal(0);
107+
expect(result.stdout).to.contain(`"${username}.${sandboxName}"`);
108+
});
109+
110+
it('sandbox status command set alias', async () => {
111+
const orgStatusResult = execCmd<SandboxProcessObject>(
112+
`force:org:status --sandboxname ${sandboxName} -u ${username} -a ${sandboxName} --json`,
113+
{
114+
ensureExitCode: 0,
115+
}
116+
).jsonOutput.result;
117+
expect(orgStatusResult).to.be.ok;
118+
const execOptions: shell.ExecOptions = {
119+
silent: true,
120+
};
121+
const result = shell.exec('sfdx alias:list --json', execOptions) as shell.ShellString;
122+
expect(result.code).to.equal(0);
123+
expect(result.stdout).to.contain(`"${sandboxName}"`);
124+
});
125+
126+
after(async () => {
127+
await session.zip(undefined, 'artifacts');
128+
await session.clean();
129+
});
130+
});

0 commit comments

Comments
 (0)