generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: no json connectedStatus on skipconnection #27
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5704c3f
fix: no connectStatus json
mshanemc 7889c4b
fix: no json connectedStatus on skipconnection
mshanemc de91ff5
test: assert no connectedStatus on orgs with --skip
mshanemc 5fbc1fb
test: fewer mocks, more assertions, unhappy path
mshanemc df45fd9
fix: org:list updates devhub status
mshanemc 7cf2dc5
perf: only check if Connected orgs are hub
mshanemc 3d12967
Merge branch 'sm/json-regression-fix' into sm/connectedstatus-should-…
mshanemc a952b12
test: additional tests for devhub checks
mshanemc ec03b9e
Merge branch 'main' into sm/json-regression-fix
WillieRuemmele 784998d
Merge branch 'main' into sm/json-regression-fix
WillieRuemmele 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 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 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
*/ | ||
import { $$, expect } from '@salesforce/command/lib/test'; | ||
|
||
import { AuthInfo, ConfigAggregator, fs, Aliases } from '@salesforce/core'; | ||
import { AuthInfo, ConfigAggregator, fs, Aliases, Org } from '@salesforce/core'; | ||
import { stubMethod } from '@salesforce/ts-sinon'; | ||
import { OrgListUtil } from '../../src/shared/orgListUtil'; | ||
import * as utils from '../../src/shared/utils'; | ||
|
@@ -46,8 +46,9 @@ const orgAuthConfig = { | |
|
||
const devHubConfigFields = { | ||
username: '[email protected]', | ||
isDevHub: true, | ||
isDevHub: false, // we want to simulate updating this as part of the flow | ||
}; | ||
|
||
const devHubConfig = { | ||
getFields: () => devHubConfigFields, | ||
getConnectionOptions: () => ({ accessToken: '00D!XX' }), | ||
|
@@ -59,40 +60,45 @@ const fileNames = ['[email protected]', '[email protected]']; | |
|
||
describe('orgListUtil tests', () => { | ||
const spies = new Map(); | ||
let readAuthFilesStub: sinon.SinonStub; | ||
let groupOrgsStub: sinon.SinonStub; | ||
let aliasListStub: sinon.SinonStub; | ||
let determineConnectedStatusForNonScratchOrg: sinon.SinonStub; | ||
let retrieveScratchOrgInfoFromDevHubStub: sinon.SinonStub; | ||
let checkNonScratchOrgIsDevHub: sinon.SinonStub; | ||
|
||
describe('readLocallyValidatedMetaConfigsGroupedByOrgType', () => { | ||
afterEach(() => spies.clear()); | ||
|
||
beforeEach(() => { | ||
readAuthFilesStub = stubMethod($$.SANDBOX, OrgListUtil, 'readAuthFiles').resolves([ | ||
orgAuthConfig, | ||
expiredAuthConfig, | ||
devHubConfig, | ||
]); | ||
$$.SANDBOX.stub(AuthInfo, 'create'); | ||
|
||
groupOrgsStub = stubMethod($$.SANDBOX, OrgListUtil, 'groupOrgs').resolves({ | ||
nonScratchOrgs: [devHubConfigFields], | ||
scratchOrgs: [orgAuthConfigFields, expiredAuthConfigFields], | ||
}); | ||
stubMethod($$.SANDBOX, OrgListUtil, 'readAuthFiles').resolves([orgAuthConfig, expiredAuthConfig, devHubConfig]); | ||
aliasListStub = stubMethod($$.SANDBOX, Aliases, 'fetch').resolves(); | ||
determineConnectedStatusForNonScratchOrg = stubMethod( | ||
$$.SANDBOX, | ||
OrgListUtil, | ||
'determineConnectedStatusForNonScratchOrg' | ||
).resolves({}); | ||
).resolves('Connected'); | ||
retrieveScratchOrgInfoFromDevHubStub = stubMethod( | ||
$$.SANDBOX, | ||
OrgListUtil, | ||
'retrieveScratchOrgInfoFromDevHub' | ||
).resolves([]); | ||
checkNonScratchOrgIsDevHub = stubMethod($$.SANDBOX, OrgListUtil, 'checkNonScratchOrgIsDevHub').resolves(true); | ||
|
||
spies.set('reduceScratchOrgInfo', $$.SANDBOX.spy(OrgListUtil, 'reduceScratchOrgInfo')); | ||
stubMethod($$.SANDBOX, ConfigAggregator, 'create').resolves({ | ||
getConfig: () => { | ||
return { | ||
defaultusername: orgAuthConfigFields.username, | ||
defaultdevhubusername: devHubConfigFields.username, | ||
}; | ||
}, | ||
}); | ||
|
||
$$.SANDBOX.stub(fs, 'readFileSync'); | ||
stubMethod($$.SANDBOX, fs, 'stat').resolves({ atime: 'test' }); | ||
|
||
$$.SANDBOX.stub(utils, 'getAliasByUsername').withArgs('[email protected]').resolves('gaz'); | ||
}); | ||
|
||
afterEach(async () => { | ||
|
@@ -101,21 +107,44 @@ describe('orgListUtil tests', () => { | |
|
||
it('readLocallyValidatedMetaConfigsGroupedByOrgType', async () => { | ||
const flags = {}; | ||
await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags); | ||
expect(readAuthFilesStub.calledOnce).to.be.true; | ||
expect(groupOrgsStub.calledOnce).to.be.true; | ||
const orgs = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags); | ||
expect(orgs.nonScratchOrgs.every((nonScratchOrg) => nonScratchOrg.connectedStatus !== undefined)).to.be.true; | ||
expect(orgs.scratchOrgs.length).to.equal(2); | ||
expect(orgs.scratchOrgs[0]).to.haveOwnProperty('username').to.equal('[email protected]'); | ||
expect(orgs.nonScratchOrgs.length).to.equal(1); | ||
|
||
// devhub is updated to be true | ||
expect(checkNonScratchOrgIsDevHub.called).to.be.true; | ||
expect(orgs.nonScratchOrgs[0].isDevHub).to.be.true; | ||
|
||
expect(aliasListStub.calledOnce).to.be.false; | ||
expect(determineConnectedStatusForNonScratchOrg.calledOnce).to.be.true; | ||
expect(retrieveScratchOrgInfoFromDevHubStub.calledOnce).to.be.true; | ||
}); | ||
|
||
it('skipconnectionstatus', async () => { | ||
const flags = { skipconnectionstatus: true }; | ||
await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags); | ||
expect(readAuthFilesStub.calledOnce).to.be.true; | ||
expect(groupOrgsStub.calledOnce).to.be.true; | ||
const orgs = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags); | ||
|
||
// we didn't check the status, so the hub is still not known to be a devhub | ||
expect(orgs.nonScratchOrgs[0].isDevHub).to.be.false; | ||
expect(checkNonScratchOrgIsDevHub.called).to.be.false; | ||
|
||
expect(orgs.nonScratchOrgs.every((nonScratchOrg) => nonScratchOrg.connectedStatus === undefined)).to.be.true; | ||
|
||
expect(aliasListStub.calledOnce).to.be.false; | ||
expect(determineConnectedStatusForNonScratchOrg.calledOnce).to.be.false; | ||
expect(aliasListStub.calledOnce).to.be.false; | ||
expect(determineConnectedStatusForNonScratchOrg.called).to.be.false; | ||
}); | ||
|
||
it('should omit sensitive information and catergorise active and non-active scracth orgs', async () => { | ||
const flags = {}; | ||
const orgs = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags); | ||
|
||
expect(orgs.scratchOrgs[0]).to.not.haveOwnProperty('clientSecret'); | ||
expect(orgs.scratchOrgs[1]).to.not.haveOwnProperty('clientSecret'); | ||
expect(orgs.scratchOrgs[0]).to.not.haveOwnProperty('refreshToken'); | ||
expect(orgs.scratchOrgs[1]).to.not.haveOwnProperty('refreshToken'); | ||
}); | ||
|
||
it('should execute queries to check for org information if --verbose is used', async () => { | ||
|
@@ -147,50 +176,42 @@ describe('orgListUtil tests', () => { | |
expect(retrieveScratchOrgInfoFromDevHubStub.calledOnce).to.be.true; | ||
expect(spies.get('reduceScratchOrgInfo').calledOnce).to.be.true; | ||
expect(orgGroups.scratchOrgs[0].signupUsername).to.equal(orgAuthConfigFields.username); | ||
}); | ||
}); | ||
|
||
describe('groupOrgs', () => { | ||
let contents; | ||
|
||
beforeEach(() => { | ||
$$.SANDBOX.stub(AuthInfo, 'create'); | ||
$$.SANDBOX.stub(utils, 'getAliasByUsername').withArgs('[email protected]').resolves('gaz'); | ||
readAuthFilesStub = stubMethod($$.SANDBOX, OrgListUtil, 'readAuthFiles').resolves([ | ||
orgAuthConfig, | ||
expiredAuthConfig, | ||
devHubConfig, | ||
// current default on every scratch org, warning in v51, deprecation in v52 | ||
expect(orgGroups.scratchOrgs[0].connectedStatus).to.equal('Unknown'); | ||
expect(orgGroups.scratchOrgs[0]).to.include.keys([ | ||
'signupUsername', | ||
'createdBy', | ||
'createdDate', | ||
'devHubOrgId', | ||
'orgName', | ||
'edition', | ||
'status', | ||
'expirationDate', | ||
'isExpired', | ||
]); | ||
stubMethod($$.SANDBOX, fs, 'stat').resolves({ atime: 'test' }); | ||
stubMethod($$.SANDBOX, ConfigAggregator, 'create').resolves({ | ||
getConfig: () => { | ||
return { | ||
defaultusername: orgAuthConfigFields.username, | ||
defaultdevhubusername: devHubConfigFields.username, | ||
}; | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
$$.SANDBOX.restore(); | ||
it('handles connection errors for non-scratch orgs', async () => { | ||
determineConnectedStatusForNonScratchOrg.restore(); | ||
stubMethod($$.SANDBOX, Org, 'create').returns(Org.prototype); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getField').returns(undefined); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getUsername').returns(devHubConfigFields.username); | ||
stubMethod($$.SANDBOX, Org.prototype, 'refreshAuth').rejects({ message: 'bad auth' }); | ||
|
||
const orgGroups = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, {}); | ||
expect(orgGroups.nonScratchOrgs).to.have.length(1); | ||
expect(orgGroups.nonScratchOrgs[0].connectedStatus).to.equal('bad auth'); | ||
expect(checkNonScratchOrgIsDevHub.called).to.be.false; | ||
}); | ||
|
||
it('ensure the auth infos are categorized into scratchOrgs, nonScratchOrgs', async () => { | ||
contents = await OrgListUtil.readAuthFiles(['[email protected]']); | ||
const orgs = await OrgListUtil.groupOrgs(contents); | ||
expect(orgs.scratchOrgs.length).to.equal(2); | ||
expect(orgs.scratchOrgs[0]).to.haveOwnProperty('username').to.equal('[email protected]'); | ||
expect(orgs.nonScratchOrgs.length).to.equal(1); | ||
}); | ||
it('handles auth file problems for non-scratch orgs', async () => { | ||
determineConnectedStatusForNonScratchOrg.restore(); | ||
stubMethod($$.SANDBOX, Org, 'create').rejects({ message: 'bad file' }); | ||
|
||
it('should omit sensitive information and catergorise active and non-active scracth orgs', async () => { | ||
const authInfos = await OrgListUtil.readAuthFiles(['[email protected]']); | ||
const orgs = await OrgListUtil.groupOrgs(authInfos); | ||
expect(orgs.scratchOrgs[0]).to.not.haveOwnProperty('clientSecret'); | ||
expect(orgs.scratchOrgs[1]).to.not.haveOwnProperty('clientSecret'); | ||
expect(orgs.scratchOrgs[0]).to.not.haveOwnProperty('refreshToken'); | ||
expect(orgs.scratchOrgs[1]).to.not.haveOwnProperty('refreshToken'); | ||
const orgGroups = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, {}); | ||
expect(orgGroups.nonScratchOrgs).to.have.length(1); | ||
expect(orgGroups.nonScratchOrgs[0].connectedStatus).to.equal('bad file'); | ||
expect(checkNonScratchOrgIsDevHub.called).to.be.false; | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mshanemc is there a test to cover this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin-org/test/shared/orgListUtil.test.ts
Line 112 in c53fba1
the command is just passing that flag to orgListUtil so the test is at that level instead of on the command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mshanemc that test verifies what happens when
skipconnectionstatus
is true. Is there an existing test that verifies results when it is false?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to put it, is there a way this bug could have been caught with a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that test now asserts that
--skipconnectionstatus
produces nonScratchOrgs with noconnectedStatus
in the jsonThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mshanemc Does the test below represent verification of the correct behavior when
flags.skipconnectionstatus
is false?plugin-org/test/shared/orgListUtil.test.ts
Line 102 in de91ff5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when migrating this command, I tried to keep the tests on orgListUtil as close to the original as possible.
I don't like the original either, so I'm gonna fix them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better?