Skip to content

Commit 331c0a1

Browse files
authored
Merge pull request #54 from salesforcecli/phale/org-nut
chore: add nut tests for plugin-org
2 parents fecf29c + f875263 commit 331c0a1

File tree

6 files changed

+608
-361
lines changed

6 files changed

+608
-361
lines changed

.circleci/config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ workflows:
1313
name: node-latest
1414
node_version: latest
1515
upload-coverage: true
16+
- release-management/test-nut:
17+
name: nuts-on-linux
18+
sfdx_version: latest
19+
requires:
20+
- node-latest
21+
- release-management/test-nut:
22+
name: nuts-on-windows
23+
sfdx_version: latest
24+
os: windows
25+
requires:
26+
- node-latest
1627
- release-management/test-package:
1728
name: node-12
1829
- release-management/release-package:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"@oclif/dev-cli": "^1",
1717
"@oclif/plugin-command-snapshot": "^2.0.0",
18-
"@salesforce/cli-plugins-testkit": "^0.0.13",
18+
"@salesforce/cli-plugins-testkit": "^0.0.14",
1919
"@salesforce/dev-config": "^2.1.0",
2020
"@salesforce/dev-scripts": "0.9.1",
2121
"@salesforce/plugin-command-reference": "^1.3.0",

src/shared/orgHighlighter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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 chalk from 'chalk';
7+
import chalk = require('chalk');
88
import { ExtendedAuthFields } from './orgTypes';
99

1010
/* eslint-disable @typescript-eslint/no-unsafe-return */
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright (c) 2020, 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 querystring from 'querystring';
9+
import { expect } from '@salesforce/command/lib/test';
10+
import { TestSession } from '@salesforce/cli-plugins-testkit';
11+
import { execCmd } from '@salesforce/cli-plugins-testkit';
12+
import { asDictionary, AnyJson, Dictionary, getString, isArray } from '@salesforce/ts-types';
13+
14+
const verifyHumanResults = (
15+
lines: string[],
16+
defaultUsername: string,
17+
aliasedUsername: string,
18+
verbose = false
19+
): void => {
20+
expect(lines.length).to.have.greaterThan(0);
21+
const devHubLine = lines.find((line) => line.includes(process.env.TESTKIT_HUB_USERNAME));
22+
expect(devHubLine).to.be.ok;
23+
expect(devHubLine).to.include('(D)');
24+
expect(devHubLine).to.include('Connected');
25+
const defaultUserLine = lines.find((line) => line.includes(defaultUsername));
26+
expect(defaultUserLine).to.be.ok;
27+
expect(defaultUserLine).to.include('(U)');
28+
const aliasUserLine = lines.find((line) => line.includes(aliasedUsername));
29+
expect(aliasUserLine).to.be.ok;
30+
expect(aliasUserLine).to.include('anAlias');
31+
// verbose mode should display sractch org Id and dev hub org Id
32+
if (verbose) {
33+
expect(defaultUserLine.match(/00D/g)).to.have.lengthOf(2, defaultUserLine);
34+
expect(aliasUserLine.match(/00D/g)).to.have.lengthOf(2, aliasUserLine);
35+
} else {
36+
expect(defaultUserLine.match(/00D/g)).to.have.lengthOf(1, defaultUserLine);
37+
expect(aliasUserLine.match(/00D/g)).to.have.lengthOf(1, aliasUserLine);
38+
}
39+
};
40+
41+
describe('Org Command NUT', () => {
42+
let session: TestSession;
43+
let defaultUsername: string;
44+
let aliasedUsername: string;
45+
let defaultUserOrgId: string;
46+
let aliasUserOrgId: string;
47+
before(() => {
48+
session = TestSession.create({
49+
project: { name: 'forceOrgList' },
50+
setupCommands: [
51+
'sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --wait 10',
52+
'sfdx force:org:create -f config/project-scratch-def.json --setalias anAlias --wait 10',
53+
],
54+
});
55+
56+
if (isArray<AnyJson>(session.setup)) {
57+
defaultUsername = getString(session.setup[0], 'result.username');
58+
defaultUserOrgId = getString(session.setup[0], 'result.orgId');
59+
aliasedUsername = getString(session.setup[1], 'result.username');
60+
aliasUserOrgId = getString(session.setup[1], 'result.orgId');
61+
}
62+
});
63+
64+
after(async () => {
65+
await session?.clean();
66+
});
67+
68+
describe('List Orgs', () => {
69+
it('should list all orgs', () => {
70+
const listResult = execCmd<Dictionary>('force:org:list --json', { ensureExitCode: 0 }).jsonOutput.result;
71+
expect(listResult).to.have.property('nonScratchOrgs');
72+
expect(listResult.nonScratchOrgs).to.have.length(1);
73+
expect(listResult).to.have.property('scratchOrgs');
74+
expect(listResult.scratchOrgs).to.have.length(2);
75+
const nonScratchOrgs = asDictionary(listResult.nonScratchOrgs[0]);
76+
const scratchOrgs = listResult.scratchOrgs as unknown[];
77+
expect(scratchOrgs.map((scratchOrg) => getString(scratchOrg, 'username'))).to.deep.equal([
78+
defaultUsername,
79+
aliasedUsername,
80+
]);
81+
expect(scratchOrgs.map((org) => asDictionary(org)).find((org) => org.username === defaultUsername)).to.include({
82+
defaultMarker: '(U)',
83+
isDefaultUsername: true,
84+
});
85+
expect(scratchOrgs.map((org) => asDictionary(org)).find((org) => org.username === aliasedUsername)).to.include({
86+
alias: 'anAlias',
87+
});
88+
expect(nonScratchOrgs).to.include(
89+
{
90+
username: process.env.TESTKIT_HUB_USERNAME,
91+
defaultMarker: '(D)',
92+
isDevHub: true,
93+
connectedStatus: 'Connected',
94+
},
95+
JSON.stringify(nonScratchOrgs)
96+
);
97+
});
98+
it('should list orgs - skipconnectionstatus', () => {
99+
const listResult = execCmd<Dictionary>('force:org:list --skipconnectionstatus --json', { ensureExitCode: 0 })
100+
.jsonOutput.result;
101+
const nonScratchOrgs = asDictionary(listResult.nonScratchOrgs[0]);
102+
expect(nonScratchOrgs).to.include(
103+
{
104+
username: process.env.TESTKIT_HUB_USERNAME,
105+
defaultMarker: '(D)',
106+
isDevHub: true,
107+
},
108+
JSON.stringify(nonScratchOrgs)
109+
);
110+
});
111+
it('should list orgs in a human readable form', () => {
112+
const lines = (execCmd('force:org:list', { ensureExitCode: 0 }).shellOutput.stdout as string).split('\n');
113+
verifyHumanResults(lines, defaultUsername, aliasedUsername);
114+
});
115+
it('should list additional information with --verbose', () => {
116+
const lines = (execCmd('force:org:list --verbose', { ensureExitCode: 0 }).shellOutput.stdout as string).split(
117+
'\n'
118+
);
119+
verifyHumanResults(lines, defaultUsername, aliasedUsername, true);
120+
});
121+
});
122+
describe('Org Display', () => {
123+
it('should display org information for default username', () => {
124+
const result = execCmd<Dictionary>('force:org:display --json', { ensureExitCode: 0 }).jsonOutput.result;
125+
expect(result).to.be.ok;
126+
expect(result).to.include({
127+
devHubId: process.env.TESTKIT_HUB_USERNAME,
128+
username: defaultUsername,
129+
});
130+
});
131+
it('should display scratch org information for alias', () => {
132+
const result = execCmd<Dictionary>(`force:org:display -u ${aliasedUsername} --json`, { ensureExitCode: 0 })
133+
.jsonOutput.result;
134+
expect(result).to.be.ok;
135+
expect(result).to.include({
136+
devHubId: process.env.TESTKIT_HUB_USERNAME,
137+
username: aliasedUsername,
138+
});
139+
});
140+
it('should display human readable org information for default username', () => {
141+
const lines = (execCmd<Dictionary>('force:org:display', { ensureExitCode: 0 }).shellOutput
142+
.stdout as string).split('\n');
143+
expect(lines.length).to.have.greaterThan(0);
144+
const usernameLine = lines.find((line) => line.includes('Username'));
145+
expect(usernameLine).to.include(defaultUsername);
146+
});
147+
it('should display human readable scratch org information for alias', () => {
148+
const lines = (execCmd(`force:org:display -u ${aliasedUsername}`, { ensureExitCode: 0 }).shellOutput
149+
.stdout as string).split('\n');
150+
expect(lines.length).to.have.greaterThan(0);
151+
const usernameLine = lines.find((line) => line.includes('Username'));
152+
expect(usernameLine).to.include(aliasedUsername);
153+
});
154+
});
155+
describe('Org Open', () => {
156+
it('should produce the URL for an org in json', () => {
157+
const result = execCmd<Dictionary>(`force:org:open -u ${defaultUsername} --urlonly --json`, { ensureExitCode: 0 })
158+
.jsonOutput.result;
159+
expect(result).to.be.ok;
160+
expect(result).to.include({ orgId: defaultUserOrgId, username: defaultUsername });
161+
});
162+
it('should produce the URL with given path for an org in json', () => {
163+
const result = execCmd(`force:org:open -u ${aliasedUsername} --urlonly --path "foo/bar/baz" --json`, {
164+
ensureExitCode: 0,
165+
}).jsonOutput.result;
166+
expect(result).to.be.ok;
167+
expect(result).to.include({ orgId: aliasUserOrgId, username: aliasedUsername });
168+
expect(result)
169+
.to.property('url')
170+
.to.include(`retURL=${querystring.escape('foo/bar/baz')}`);
171+
});
172+
});
173+
});

test/shared/orgHighlighter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import { expect } from '@salesforce/command/lib/test';
8-
import chalk from 'chalk';
8+
import * as chalk from 'chalk';
99
import { getStyledObject, getStyledValue } from '../../src/shared/orgHighlighter';
1010

1111
describe('highlights value from key-value pair', () => {

0 commit comments

Comments
 (0)