Skip to content

Commit adf993d

Browse files
committed
chore: rename test
1 parent 8a3f33c commit adf993d

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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 fs from 'fs';
9+
import * as path from 'path';
10+
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
11+
import { expect } from 'chai';
12+
import * as shell from 'shelljs';
13+
import { AuthInfo, Connection, SandboxProcessObject } from '@salesforce/core';
14+
import { Env } from '@salesforce/kit';
15+
import { ensureString } from '@salesforce/ts-types';
16+
17+
let session: TestSession;
18+
let sandboxName: string;
19+
20+
function unsetAlias() {
21+
const execOptions: shell.ExecOptions = {
22+
silent: true,
23+
};
24+
shell.exec(`sfdx alias:unset ${sandboxName}`, execOptions) as shell.ShellString;
25+
}
26+
27+
function unsetConfig() {
28+
const execOptions: shell.ExecOptions = {
29+
silent: true,
30+
};
31+
shell.exec('sfdx config:unset defaultusername -g', execOptions) as shell.ShellString;
32+
}
33+
34+
function logoutSandbox(username: string) {
35+
const execOptions: shell.ExecOptions = {
36+
silent: true,
37+
};
38+
const rv = shell.exec(`sfdx auth:logout -u ${username}.${sandboxName} --noprompt`, execOptions) as shell.ShellString;
39+
if (rv.code !== 0) {
40+
throw new Error(`sfdx auth:logout failed with error:\n${rv.stderr}`);
41+
}
42+
}
43+
44+
describe('test sandbox status command', () => {
45+
const env = new Env();
46+
let username: string;
47+
48+
before(async () => {
49+
username = ensureString(env.getString('TESTKIT_HUB_USERNAME'));
50+
const queryStr =
51+
"SELECT SandboxName FROM SandboxProcess WHERE Status != 'E' and Status != 'D' ORDER BY CreatedDate DESC LIMIT 1";
52+
const connection = await Connection.create({
53+
authInfo: await AuthInfo.create({ username }),
54+
});
55+
const queryResult = (await connection.tooling.query(queryStr)) as { records: SandboxProcessObject[] };
56+
expect(queryResult?.records?.length).to.equal(1);
57+
sandboxName = queryResult?.records[0]?.SandboxName;
58+
session = await TestSession.create({
59+
project: {
60+
sourceDir: path.join(process.cwd(), 'test', 'nut', 'commands', 'force', 'org'),
61+
},
62+
});
63+
});
64+
65+
afterEach(() => {
66+
unsetAlias();
67+
unsetConfig();
68+
logoutSandbox(username);
69+
});
70+
71+
it('sandbox status command', async () => {
72+
const orgStatusResult = execCmd<SandboxProcessObject>(
73+
`force:org:status --sandboxname ${sandboxName} -u ${username} --json`,
74+
{
75+
ensureExitCode: 0,
76+
}
77+
).jsonOutput.result;
78+
expect(orgStatusResult).to.be.a('object');
79+
expect(orgStatusResult).to.have.all.keys([
80+
'attributes',
81+
'Id',
82+
'Status',
83+
'SandboxName',
84+
'SandboxInfoId',
85+
'LicenseType',
86+
'CreatedDate',
87+
'CopyProgress',
88+
'SandboxOrganization',
89+
'SourceId',
90+
'Description',
91+
'EndDate',
92+
]);
93+
});
94+
95+
it('sandbox status command sets setdefaultusername', async () => {
96+
const orgStatusResult = execCmd<SandboxProcessObject>(
97+
`force:org:status --sandboxname ${sandboxName} -u ${username} -s --json`,
98+
{
99+
ensureExitCode: 0,
100+
}
101+
).jsonOutput.result;
102+
expect(orgStatusResult).to.be.ok;
103+
104+
const config = JSON.parse(
105+
fs.readFileSync(path.join(session.project.dir, '..', '.sfdx', 'sfdx-config.json'), 'utf8')
106+
) as Record<string, string>;
107+
expect(config.defaultusername).to.be.equal(`${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+
119+
const aliases = JSON.parse(
120+
fs.readFileSync(path.join(session.project.dir, '..', '.sfdx', 'alias.json'), 'utf8')
121+
) as {
122+
orgs: Record<string, string>;
123+
};
124+
125+
expect(aliases).to.deep.equal({
126+
orgs: {
127+
[`${sandboxName}`]: `${username}.${sandboxName}`,
128+
},
129+
});
130+
});
131+
132+
after(async () => {
133+
await session.zip(undefined, 'artifacts');
134+
await session.clean();
135+
});
136+
});

0 commit comments

Comments
 (0)