generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 19
chore: add nut tests for plugin-org #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cf8ddd6
chore: initial org nuts
peternhale 6fc5ede
test: nuts run on circle
mshanemc 34165e8
test: modify open nuts for dynamic username and fix url
mshanemc 32049a6
chore: test changes
peternhale 47da2db
chore: revert unneeded changes
peternhale 8206a4f
chore: improve assertion message
peternhale 37687b5
chore: apply review comments
peternhale be4f5ce
chore: suppres unsafe call lint errors
peternhale f36c2ff
chore: improve assertion message
peternhale e84ddd9
chore: correct lint errors
peternhale f875263
chore: replace os.EOL with newline
peternhale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as querystring from 'querystring'; | ||
| import { expect } from '@salesforce/command/lib/test'; | ||
| import { TestSession } from '@salesforce/cli-plugins-testkit'; | ||
| import { execCmd } from '@salesforce/cli-plugins-testkit'; | ||
| import { asDictionary, AnyJson, Dictionary, getString, isArray } from '@salesforce/ts-types'; | ||
|
|
||
| const verifyHumanResults = ( | ||
| lines: string[], | ||
| defaultUsername: string, | ||
| aliasedUsername: string, | ||
| verbose = false | ||
| ): void => { | ||
| expect(lines.length).to.have.greaterThan(0); | ||
| const devHubLine = lines.find((line) => line.includes(process.env.TESTKIT_HUB_USERNAME)); | ||
| expect(devHubLine).to.be.ok; | ||
| expect(devHubLine).to.include('(D)'); | ||
| expect(devHubLine).to.include('Connected'); | ||
| const defaultUserLine = lines.find((line) => line.includes(defaultUsername)); | ||
| expect(defaultUserLine).to.be.ok; | ||
| expect(defaultUserLine).to.include('(U)'); | ||
| const aliasUserLine = lines.find((line) => line.includes(aliasedUsername)); | ||
| expect(aliasUserLine).to.be.ok; | ||
| expect(aliasUserLine).to.include('anAlias'); | ||
| // verbose mode should display sractch org Id and dev hub org Id | ||
| if (verbose) { | ||
| expect(defaultUserLine.match(/00D/g)).to.have.lengthOf(2, defaultUserLine); | ||
| expect(aliasUserLine.match(/00D/g)).to.have.lengthOf(2, aliasUserLine); | ||
| } else { | ||
| expect(defaultUserLine.match(/00D/g)).to.have.lengthOf(1, defaultUserLine); | ||
| expect(aliasUserLine.match(/00D/g)).to.have.lengthOf(1, aliasUserLine); | ||
| } | ||
| }; | ||
|
|
||
| describe('Org Command NUT', () => { | ||
| let session: TestSession; | ||
| let defaultUsername: string; | ||
| let aliasedUsername: string; | ||
| let defaultUserOrgId: string; | ||
| let aliasUserOrgId: string; | ||
| before(() => { | ||
| session = TestSession.create({ | ||
| project: { name: 'forceOrgList' }, | ||
| setupCommands: [ | ||
| 'sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --wait 10', | ||
| 'sfdx force:org:create -f config/project-scratch-def.json --setalias anAlias --wait 10', | ||
| ], | ||
| }); | ||
|
|
||
| if (isArray<AnyJson>(session.setup)) { | ||
| defaultUsername = getString(session.setup[0], 'result.username'); | ||
| defaultUserOrgId = getString(session.setup[0], 'result.orgId'); | ||
| aliasedUsername = getString(session.setup[1], 'result.username'); | ||
| aliasUserOrgId = getString(session.setup[1], 'result.orgId'); | ||
| } | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await session?.clean(); | ||
| }); | ||
|
|
||
| describe('List Orgs', () => { | ||
| it('should list all orgs', () => { | ||
| const listResult = execCmd<Dictionary>('force:org:list --json', { ensureExitCode: 0 }).jsonOutput.result; | ||
| expect(listResult).to.have.property('nonScratchOrgs'); | ||
| expect(listResult.nonScratchOrgs).to.have.length(1); | ||
| expect(listResult).to.have.property('scratchOrgs'); | ||
| expect(listResult.scratchOrgs).to.have.length(2); | ||
| const nonScratchOrgs = asDictionary(listResult.nonScratchOrgs[0]); | ||
| const scratchOrgs = listResult.scratchOrgs as unknown[]; | ||
| expect(scratchOrgs.map((scratchOrg) => getString(scratchOrg, 'username'))).to.deep.equal([ | ||
| defaultUsername, | ||
| aliasedUsername, | ||
| ]); | ||
| expect(scratchOrgs.map((org) => asDictionary(org)).find((org) => org.username === defaultUsername)).to.include({ | ||
| defaultMarker: '(U)', | ||
| isDefaultUsername: true, | ||
| }); | ||
| expect(scratchOrgs.map((org) => asDictionary(org)).find((org) => org.username === aliasedUsername)).to.include({ | ||
| alias: 'anAlias', | ||
| }); | ||
| expect(nonScratchOrgs).to.include( | ||
| { | ||
| username: process.env.TESTKIT_HUB_USERNAME, | ||
| defaultMarker: '(D)', | ||
| isDevHub: true, | ||
| connectedStatus: 'Connected', | ||
| }, | ||
| JSON.stringify(nonScratchOrgs) | ||
| ); | ||
| }); | ||
| it('should list orgs - skipconnectionstatus', () => { | ||
| const listResult = execCmd<Dictionary>('force:org:list --skipconnectionstatus --json', { ensureExitCode: 0 }) | ||
| .jsonOutput.result; | ||
| const nonScratchOrgs = asDictionary(listResult.nonScratchOrgs[0]); | ||
| expect(nonScratchOrgs).to.include( | ||
| { | ||
| username: process.env.TESTKIT_HUB_USERNAME, | ||
| defaultMarker: '(D)', | ||
| isDevHub: true, | ||
| }, | ||
| JSON.stringify(nonScratchOrgs) | ||
| ); | ||
| }); | ||
| it('should list orgs in a human readable form', () => { | ||
| const lines = (execCmd('force:org:list', { ensureExitCode: 0 }).shellOutput.stdout as string).split('\n'); | ||
| verifyHumanResults(lines, defaultUsername, aliasedUsername); | ||
| }); | ||
| it('should list additional information with --verbose', () => { | ||
| const lines = (execCmd('force:org:list --verbose', { ensureExitCode: 0 }).shellOutput.stdout as string).split( | ||
| '\n' | ||
| ); | ||
| verifyHumanResults(lines, defaultUsername, aliasedUsername, true); | ||
| }); | ||
| }); | ||
| describe('Org Display', () => { | ||
| it('should display org information for default username', () => { | ||
| const result = execCmd<Dictionary>('force:org:display --json', { ensureExitCode: 0 }).jsonOutput.result; | ||
| expect(result).to.be.ok; | ||
| expect(result).to.include({ | ||
| devHubId: process.env.TESTKIT_HUB_USERNAME, | ||
| username: defaultUsername, | ||
| }); | ||
| }); | ||
| it('should display scratch org information for alias', () => { | ||
| const result = execCmd<Dictionary>(`force:org:display -u ${aliasedUsername} --json`, { ensureExitCode: 0 }) | ||
| .jsonOutput.result; | ||
| expect(result).to.be.ok; | ||
| expect(result).to.include({ | ||
| devHubId: process.env.TESTKIT_HUB_USERNAME, | ||
| username: aliasedUsername, | ||
| }); | ||
| }); | ||
| it('should display human readable org information for default username', () => { | ||
| const lines = (execCmd<Dictionary>('force:org:display', { ensureExitCode: 0 }).shellOutput | ||
| .stdout as string).split('\n'); | ||
| expect(lines.length).to.have.greaterThan(0); | ||
| const usernameLine = lines.find((line) => line.includes('Username')); | ||
| expect(usernameLine).to.include(defaultUsername); | ||
| }); | ||
| it('should display human readable scratch org information for alias', () => { | ||
| const lines = (execCmd(`force:org:display -u ${aliasedUsername}`, { ensureExitCode: 0 }).shellOutput | ||
| .stdout as string).split('\n'); | ||
| expect(lines.length).to.have.greaterThan(0); | ||
| const usernameLine = lines.find((line) => line.includes('Username')); | ||
| expect(usernameLine).to.include(aliasedUsername); | ||
| }); | ||
| }); | ||
| describe('Org Open', () => { | ||
| it('should produce the URL for an org in json', () => { | ||
| const result = execCmd<Dictionary>(`force:org:open -u ${defaultUsername} --urlonly --json`, { ensureExitCode: 0 }) | ||
| .jsonOutput.result; | ||
| expect(result).to.be.ok; | ||
| expect(result).to.include({ orgId: defaultUserOrgId, username: defaultUsername }); | ||
| }); | ||
| it('should produce the URL with given path for an org in json', () => { | ||
| const result = execCmd(`force:org:open -u ${aliasedUsername} --urlonly --path "foo/bar/baz" --json`, { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result).to.be.ok; | ||
| expect(result).to.include({ orgId: aliasUserOrgId, username: aliasedUsername }); | ||
| expect(result) | ||
| .to.property('url') | ||
| .to.include(`retURL=${querystring.escape('foo/bar/baz')}`); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.