Skip to content

Commit

Permalink
fix: do not query server if cached
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Jan 29, 2019
1 parent 586d7ba commit d7ccf99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,20 @@ export class Org extends AsyncCreatable<Org.Options> {
*
* Use a cached value. If the cached value is not set, then check access to the
* ScratchOrgInfo object to determine if the org is a dev hub.
*
* @param forceServerCheck Ignore the cached value and go straight to the server
* which will be required if the org flips on the dev hub after the value is already
* cached locally.
*/
public async determineIfDevHubOrg() {
public async determineIfDevHubOrg(forceServerCheck = false) {
const cachedIsDevHub = this.getField(Org.Fields.IS_DEV_HUB);
if (!forceServerCheck && isBoolean(cachedIsDevHub)) {
return cachedIsDevHub;
}
if (this.isDevHubOrg()) {
return true;
}

this.logger.debug('isDevHub is not cached - querying server...');
const conn = this.getConnection();
let isDevHub = false;
try {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,28 @@ describe('Org Tests', () => {
expect(await org.determineIfDevHubOrg()).to.be.false;
expect(org.isDevHubOrg()).to.be.false;
});
it('should not call server is cached', async () => {
$$.configStubs.AuthInfoConfig.contents = {
isDevHub: false
};
const org: Org = await Org.create({ aliasOrUsername: testData.username });
const spy = $$.SANDBOX.spy();
$$.fakeConnectionRequest = spy;
expect(org.isDevHubOrg()).to.be.false;
expect(await org.determineIfDevHubOrg()).to.be.false;
expect(spy.called).to.be.false;
});
it('should call server is cached but forced', async () => {
$$.configStubs.AuthInfoConfig.contents = {
isDevHub: false
};
const org: Org = await Org.create({ aliasOrUsername: testData.username });
const spy = $$.SANDBOX.stub().returns(Promise.resolve({ records: [] }));
$$.fakeConnectionRequest = spy;
expect(org.isDevHubOrg()).to.be.false;
expect(await org.determineIfDevHubOrg(true)).to.be.true;
expect(spy.called).to.be.true;
expect(org.isDevHubOrg()).to.be.true;
});
});
});

0 comments on commit d7ccf99

Please sign in to comment.