Skip to content

Commit

Permalink
fix: remove namespace if nonamespace option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 3, 2024
1 parent 20646c3 commit 80246cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/org/scratchOrgInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type ScratchOrgInfoPayload = {
package2AncestorIds: string;
features: string | string[];
connectedAppConsumerKey: string;
namespace: string;
namespace?: string;
connectedAppCallbackUrl: string;
durationDays: number;
} & PartialScratchOrgInfo;
Expand Down Expand Up @@ -216,12 +216,16 @@ export const generateScratchOrgInfo = async ({
// project is not required
}

const { namespace: originalNamespace, ...payload } = scratchOrgInfoPayload;

const namespace = originalNamespace ?? sfProject?.get('namespace');

return {
...scratchOrgInfoPayload,
...payload,
orgName: scratchOrgInfoPayload.orgName ?? 'Company',
// we already have the info, and want to get rid of configApi, so this doesn't use that
connectedAppCallbackUrl: `http://localhost:${await WebOAuthServer.determineOauthPort()}/OauthRedirect`,
...(!nonamespace && sfProject?.get('namespace') ? { namespace: sfProject.get('namespace') as string } : {}),
...(!nonamespace && namespace ? { namespace } : {}),
// Use the Hub org's client ID value, if one wasn't provided to us, or the default
connectedAppConsumerKey:
scratchOrgInfoPayload.connectedAppConsumerKey ??
Expand Down
41 changes: 39 additions & 2 deletions test/unit/org/scratchOrgInfoGeneratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ describe('scratchOrgInfoGenerator', () => {
});
});

describe('generateScratchOrgInfo no nonamespace', () => {
describe('generateScratchOrgInfo with nonamespace', () => {
const sandbox = sinon.createSandbox();
beforeEach(() => {
stubMethod(sandbox, Org, 'create').resolves(Org.prototype);
Expand All @@ -753,7 +753,7 @@ describe('scratchOrgInfoGenerator', () => {
after(() => {
sandbox.restore();
});
it('calls generateScratchOrgInfo with no nonamespace but SfProjectJson.get("name") is true', async () => {
it('calls generateScratchOrgInfo with nonamespace=false but SfProjectJson.get("namespace") returns a value', async () => {
expect(
await generateScratchOrgInfo({
hubOrg: await Org.create({}),
Expand All @@ -769,6 +769,43 @@ describe('scratchOrgInfoGenerator', () => {
connectedAppCallbackUrl: 'http://localhost:1717/OauthRedirect',
});
});

it('calls generateScratchOrgInfo with nonamespace=false with provided namespace and SfProjectJson.get("namespace") returns a value', async () => {
expect(
await generateScratchOrgInfo({
hubOrg: await Org.create({}),
scratchOrgInfoPayload: {
namespace: 'this-namespace-should-win',
} as ScratchOrgInfoPayload,
nonamespace: false,
ignoreAncestorIds: false,
})
).to.deep.equal({
orgName: 'Company',
namespace: 'this-namespace-should-win',
package2AncestorIds: '',
connectedAppConsumerKey: '1234',
connectedAppCallbackUrl: 'http://localhost:1717/OauthRedirect',
});
});

it('calls generateScratchOrgInfo with nonamespace=true but a namespace is provided in payload', async () => {
expect(
await generateScratchOrgInfo({
hubOrg: await Org.create({}),
scratchOrgInfoPayload: {
namespace: 'my-namespace',
} as ScratchOrgInfoPayload,
nonamespace: true,
ignoreAncestorIds: false,
})
).to.deep.equal({
orgName: 'Company',
package2AncestorIds: '',
connectedAppConsumerKey: '1234',
connectedAppCallbackUrl: 'http://localhost:1717/OauthRedirect',
});
});
});

describe('getScratchOrgInfoPayload', () => {
Expand Down

2 comments on commit 80246cd

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 80246cd Previous: 01cf9e7 Ratio
Child logger creation 481998 ops/sec (±1.47%) 469123 ops/sec (±1.40%) 0.97
Logging a string on root logger 815132 ops/sec (±13.10%) 800500 ops/sec (±12.96%) 0.98
Logging an object on root logger 601616 ops/sec (±6.61%) 580714 ops/sec (±8.11%) 0.97
Logging an object with a message on root logger 8110 ops/sec (±206.28%) 8712 ops/sec (±205.13%) 1.07
Logging an object with a redacted prop on root logger 485479 ops/sec (±8.78%) 455852 ops/sec (±8.42%) 0.94
Logging a nested 3-level object on root logger 371132 ops/sec (±7.69%) 361439 ops/sec (±7.33%) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 80246cd Previous: 01cf9e7 Ratio
Child logger creation 327859 ops/sec (±0.65%) 308613 ops/sec (±2.03%) 0.94
Logging a string on root logger 747832 ops/sec (±5.68%) 800307 ops/sec (±6.96%) 1.07
Logging an object on root logger 600381 ops/sec (±4.66%) 566873 ops/sec (±6.64%) 0.94
Logging an object with a message on root logger 10089 ops/sec (±190.05%) 6631 ops/sec (±207.86%) 0.66
Logging an object with a redacted prop on root logger 505630 ops/sec (±6.86%) 426747 ops/sec (±17.67%) 0.84
Logging a nested 3-level object on root logger 337643 ops/sec (±5.19%) 327272 ops/sec (±3.51%) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.