Skip to content

Commit

Permalink
Merge pull request #149 from khogan18/feature/SandboxOrgConfig
Browse files Browse the repository at this point in the history
feat: do not throw error on org.remove if sandbox config doesn't exist
  • Loading branch information
tnoonan-salesforce authored Jul 3, 2019
2 parents 6662590 + 3912993 commit 745291b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ export class Org extends AsyncCreatable<Org.Options> {

await aliases.write();

// Delete the sandbox org config file if it exists
// Delete the sandbox org config file if it exists.
// This is an optional file so don't throw an error when the file doesn't exist.
const sandboxOrgConfig = await this.retrieveSandboxOrgConfig();
await this.manageDelete(
async () => await sandboxOrgConfig.unlink(),
sandboxOrgConfig.getPath(),
throwWhenRemoveFails
);
if (await sandboxOrgConfig.exists()) {
await this.manageDelete(
async () => await sandboxOrgConfig.unlink(),
sandboxOrgConfig.getPath(),
throwWhenRemoveFails
);
}
}

/**
Expand Down
33 changes: 32 additions & 1 deletion test/unit/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ describe('Org Tests', () => {
stubMethod($$.SANDBOX, fs, 'remove').callsFake(() => {
return Promise.resolve({});
});
await org.setSandboxOrgConfigField(SandboxOrgConfig.Fields.PROD_ORG_USERNAME, 'foo@sandbox.com');

stubMethod($$.SANDBOX, ConfigFile.prototype, 'exists').callsFake(async () => {
return Promise.resolve(true);
});

await org.remove();

Expand Down Expand Up @@ -313,6 +316,34 @@ describe('Org Tests', () => {
alias = await Aliases.fetch('foo');
expect(alias).eq(undefined);
});

it('should not fail when no sandboxOrgConfig', async () => {
const org: Org = await Org.create({
connection: await Connection.create({
authInfo: await AuthInfo.create({ username: testData.username })
})
});

const deletedPaths: string[] = [];
stubMethod($$.SANDBOX, ConfigFile.prototype, 'unlink').callsFake(function(this: ConfigFile<ConfigFile.Options>) {
deletedPaths.push(this.getPath());
return Promise.resolve({});
});

stubMethod($$.SANDBOX, fs, 'remove').callsFake(() => {
return Promise.resolve({});
});

await org.remove();

expect(deletedPaths).includes(
pathJoin(await $$.globalPathRetriever($$.id), Global.STATE_FOLDER, `${testData.orgId}.json`)
);

expect(deletedPaths).not.includes(
pathJoin(await $$.globalPathRetriever($$.id), Global.STATE_FOLDER, `${testData.orgId}.sandbox.json`)
);
});
});

describe('with multiple scratch org users', () => {
Expand Down

0 comments on commit 745291b

Please sign in to comment.