From 26d923e5ec34efd9236675ef8c0290341da48c40 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Wed, 2 Aug 2023 13:37:06 -0600 Subject: [PATCH] fix: query devhubs, non-scratch orgs, and non-sandboxes to identify sandboxes --- src/org/authInfo.ts | 9 ++++--- test/unit/org/authInfoTest.ts | 44 ----------------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/src/org/authInfo.ts b/src/org/authInfo.ts index 190f433172..01517fb131 100644 --- a/src/org/authInfo.ts +++ b/src/org/authInfo.ts @@ -401,9 +401,9 @@ export class AuthInfo extends AsyncOptionalCreatable { // TODO: someday we make this easier by asking the org if it is a scratch org const hubAuthInfos = await AuthInfo.getDevHubAuthInfos(); - // Get a list of org auths that are known not to be devhubs, scratch orgs, or sandboxes. + // Get a list of org auths that are known not to be scratch orgs or sandboxes. const possibleProdOrgs = await AuthInfo.listAllAuthorizations( - (orgAuth) => orgAuth && !orgAuth.isDevHub && !orgAuth.isScratchOrg && !orgAuth.isSandbox + (orgAuth) => orgAuth && !orgAuth.isScratchOrg && !orgAuth.isSandbox ); logger.debug(`found ${hubAuthInfos.length} DevHubs`); @@ -435,9 +435,8 @@ export class AuthInfo extends AsyncOptionalCreatable { logger.debug(`error updating auth file for ${orgAuthInfo.getUsername()}`, error); } } catch (error) { - if (error instanceof Error && error.name === 'SingleRecordQuery_NoRecords' && fields.orgId) { - // Not a scratch org owned by this hub. Check if it's a sandbox. - await AuthInfo.identifyPossibleSandbox(hubAuthInfo, fields, orgAuthInfo, logger); + if (error instanceof Error && error.name === 'NoActiveScratchOrgFound') { + logger.error(`devhub ${hubAuthInfo.username} has no scratch orgs`, error); } else { logger.error(`Error connecting to devhub ${hubAuthInfo.username}`, error); } diff --git a/test/unit/org/authInfoTest.ts b/test/unit/org/authInfoTest.ts index 87c9b4ca9b..fe024a9d88 100644 --- a/test/unit/org/authInfoTest.ts +++ b/test/unit/org/authInfoTest.ts @@ -1869,50 +1869,6 @@ describe('AuthInfo', () => { expect(authInfoSaveStub.callCount).to.be.equal(1); }); - it('should update auth file as a sandbox from devhub', async () => { - adminTestData.makeDevHub(); - - await $$.stubAuths(adminTestData, user1); - - const authInfo = await AuthInfo.create({ - username: user1.username, - }); - - const stateAggregator = await StateAggregator.getInstance(); - const stateAggregatorStub = stubMethod($$.SANDBOX, StateAggregator, 'getInstance'); - const sandboxSetStub = stubMethod($$.SANDBOX, stateAggregator.sandboxes, 'set'); - const sandboxWriteStub = stubMethod($$.SANDBOX, stateAggregator.sandboxes, 'write'); - stateAggregatorStub.resolves(stateAggregator); - const devhubAuths = await AuthInfo.getDevHubAuthInfos(); - stubMethod($$.SANDBOX, AuthInfo, 'getDevHubAuthInfos').resolves(devhubAuths); - stubMethod($$.SANDBOX, AuthInfo, 'listAllAuthorizations').resolves([]); - const authInfoSaveStub = stubMethod($$.SANDBOX, AuthInfo.prototype, 'save').resolves(); - const queryScratchOrgStub = stubMethod($$.SANDBOX, AuthInfo, 'queryScratchOrg'); - const queryScratchOrgError = new Error('not a scratch org'); - queryScratchOrgError.name = 'SingleRecordQuery_NoRecords'; - queryScratchOrgStub.throws(queryScratchOrgError); - const sbxQueryStub = stubMethod($$.SANDBOX, Org.prototype, 'querySandboxProcessByOrgId'); - sbxQueryStub.resolves({ - Id: '0GRB0000000L0ZVOA0', - Status: 'Completed', - SandboxName: 'TestSandbox', - SandboxInfoId: '0GQB0000000PCOdOAO', - LicenseType: 'DEVELOPER', - CreatedDate: '2021-01-22T22:49:52.000+0000', - }); - - await AuthInfo.identifyPossibleScratchOrgs(authInfo.getFields(), authInfo); - - expect(authInfoSaveStub.callCount).to.be.equal(2); - expect(authInfoSaveStub.secondCall.args[0]).to.have.property('isSandbox', true); - expect(authInfoSaveStub.secondCall.args[0]).to.have.property('isScratch', false); - expect(sandboxSetStub.calledOnce).to.be.true; - expect(sandboxSetStub.firstCall.args[0]).to.equal(authInfo.getFields().orgId); - expect(sandboxSetStub.firstCall.args[1]).to.have.property('prodOrgUsername', adminTestData.username); - expect(sandboxWriteStub.calledOnce).to.be.true; - expect(sandboxWriteStub.firstCall.args[0]).to.equal(authInfo.getFields().orgId); - }); - it('should update auth file as a sandbox from possible prod orgs', async () => { adminTestData.makeDevHub();