Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoonan-salesforce committed Aug 13, 2019
1 parent a6a77c6 commit 7c1f630
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class Org extends AsyncCreatable<Org.Options> {
* @param {value} The value to save
*/
public async setSandboxOrgConfigField(field: SandboxOrgConfig.Fields, value: string): Promise<Org> {
const sandboxOrgConfig: SandboxOrgConfig = await this.retrieveSandboxOrgConfig();
const sandboxOrgConfig = await this.retrieveSandboxOrgConfig();
sandboxOrgConfig.set(field, value);
await sandboxOrgConfig.write();
return this;
Expand Down Expand Up @@ -449,25 +449,6 @@ export class Org extends AsyncCreatable<Org.Options> {
return this.connection;
}

/**
* Returns a promise to delete an auth info file from the local file system and any related cache information for
* this Org.. You don't want to call this method directly. Instead consider calling Org.remove()
*/
public async removeAuth(): Promise<void> {
const username = ensure(this.getUsername());
this.logger.debug(`Removing auth for user: ${username}`);
const config = await AuthInfoConfig.create({
...AuthInfoConfig.getOptions(username),
throwOnNotFound: false
});

this.logger.debug(`Clearing auth cache for user: ${username}`);
AuthInfo.clearCache(username);
if (await config.exists()) {
await config.unlink();
}
}

/**
* Initialize async components.
*/
Expand Down Expand Up @@ -504,6 +485,25 @@ export class Org extends AsyncCreatable<Org.Options> {
throw new SfdxError('Not Supported');
}

/**
* Returns a promise to delete an auth info file from the local file system and any related cache information for
* this Org.. You don't want to call this method directly. Instead consider calling Org.remove()
*/
private async removeAuth(): Promise<void> {
const username = ensure(this.getUsername());
this.logger.debug(`Removing auth for user: ${username}`);
const config = await AuthInfoConfig.create({
...AuthInfoConfig.getOptions(username),
throwOnNotFound: false
});

this.logger.debug(`Clearing auth cache for user: ${username}`);
AuthInfo.clearCache(username);
if (await config.exists()) {
await config.unlink();
}
}

/**
* Deletes the users config file
*/
Expand Down
9 changes: 9 additions & 0 deletions test/unit/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,15 @@ describe('Org Tests', () => {

describe('sandbox org config', () => {
it('set field', async () => {
const org: Org = await Org.create({ aliasOrUsername: testData.username });
expect(await org.getSandboxOrgConfigField(SandboxOrgConfig.Fields.PROD_ORG_USERNAME)).to.be.undefined;

await org.setSandboxOrgConfigField(SandboxOrgConfig.Fields.PROD_ORG_USERNAME, 'user@sandbox.org');

expect(await org.getSandboxOrgConfigField(SandboxOrgConfig.Fields.PROD_ORG_USERNAME)).to.eq('user@sandbox.org');
});

it('Test sandbox config removal.', async () => {
// Stub exists so only the auth file and sandbox config file exist. No users config file.
stubMethod($$.SANDBOX, ConfigFile.prototype, 'exists').callsFake(async function() {
if (this.path && this.path.endsWith(`${testData.orgId}.json`)) {
Expand Down

0 comments on commit 7c1f630

Please sign in to comment.