Skip to content

Commit 1040142

Browse files
committed
fix: update the features to string[] and schemas
1 parent 0b45f63 commit 1040142

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

schemas/org-create-sandbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
"type": "string"
4747
},
4848
"Features": {
49-
"type": "string"
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
5053
}
5154
},
5255
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]

schemas/org-refresh-sandbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
"type": "string"
4747
},
4848
"Features": {
49-
"type": "string"
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
5053
}
5154
},
5255
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]

schemas/org-resume-sandbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
"type": "string"
4747
},
4848
"Features": {
49-
"type": "string"
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
5053
}
5154
},
5255
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]

src/commands/org/create/sandbox.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
174174
delete sandboxReq.ActivationUserGroupName;
175175
}
176176

177+
const nameOrId = srcSandboxName ?? srcId;
178+
177179
// Get source sandbox features if cloning
178-
if (srcSandboxName ?? srcId) {
179-
const sourceFeatures = await this.getSandboxFeatures(srcSandboxName ?? srcId);
180+
if (nameOrId) {
181+
const sourceFeatures = await this.getSandboxFeatures(nameOrId);
180182
if (sourceFeatures) {
181-
(sandboxReq as SandboxRequest & { Features?: string }).Features = sourceFeatures;
183+
(sandboxReq as SandboxRequest & { Features?: string[] }).Features = sourceFeatures;
182184
}
183185
}
184186

@@ -193,26 +195,25 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
193195
};
194196
}
195197

196-
private async getSandboxFeatures(sandboxName: string): Promise<string | undefined> {
198+
private async getSandboxFeatures(sandboxName: string): Promise<string[] | undefined> {
197199
const prodOrg = this.flags['target-org'];
198200

199201
try {
200202
if (sandboxName?.startsWith('0GQ')) {
201-
const sbxId = await prodOrg.querySandboxInfo({ id: sandboxName, name: '' });
203+
const sbxId = await prodOrg.querySandboxInfo({ id: sandboxName, name: undefined });
202204
if (sbxId?.Features) {
203205
return sbxId.Features;
204206
}
205-
const sandboxProcess = await prodOrg.querySandboxProcessBySandboxInfoId(sandboxName);
206-
return sandboxProcess?.Features;
207+
208+
return (await prodOrg.querySandboxProcessBySandboxInfoId(sandboxName)).Features;
207209
}
208210

209-
const sbxName = await prodOrg.querySandboxInfo({ id: '', name: sandboxName });
211+
const sbxName = await prodOrg.querySandboxInfo({ id: undefined, name: sandboxName });
210212
if (sbxName?.Features) {
211213
return sbxName.Features;
212214
}
213215

214-
const sandboxProcess = await prodOrg.querySandboxProcessBySandboxName(sandboxName);
215-
return sandboxProcess?.Features;
216+
return (await prodOrg.querySandboxProcessBySandboxName(sandboxName)).Features;
216217
} catch (err) {
217218
if (err instanceof SfError && (err.name.includes('AUTH') ?? err.name.includes('CONNECTION'))) {
218219
this.warn(`Warning: Could not retrieve sandbox features due to ${err.name}.`);

src/shared/sandboxRequest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function readSandboxDefFile(
5555
export async function createSandboxRequest(
5656
definitionFile: string | undefined,
5757
logger?: Logger | undefined,
58-
properties?: Record<string, string | undefined>
58+
properties?: Record<string, string | undefined | string[]>
5959
): Promise<{
6060
sandboxReq: SandboxRequest & {
6161
ApexClassName: string | undefined;
@@ -67,7 +67,7 @@ export async function createSandboxRequest(
6767
export async function createSandboxRequest(
6868
definitionFile: string | undefined,
6969
logger?: Logger | undefined,
70-
properties?: Record<string, string | undefined>
70+
properties?: Record<string, string | undefined | string[]>
7171
): Promise<{
7272
sandboxReq: SandboxRequest & {
7373
ApexClassName: string | undefined;
@@ -77,7 +77,7 @@ export async function createSandboxRequest(
7777
export async function createSandboxRequest(
7878
definitionFile: string | undefined,
7979
logger?: Logger | undefined,
80-
properties?: Record<string, string | undefined>
80+
properties?: Record<string, string | undefined | string[]>
8181
): Promise<{ sandboxReq: SandboxRequest; srcSandboxName?: string; srcId?: string }> {
8282
if (!logger) {
8383
logger = await Logger.child('createSandboxRequest');
@@ -88,7 +88,7 @@ export async function createSandboxRequest(
8888

8989
const capitalizedVarArgs = properties ? lowerToUpper(properties) : {};
9090
// varargs override file input
91-
const sandboxReqWithName: (SandboxRequest & { Features?: string }) & {
91+
const sandboxReqWithName: (SandboxRequest & { Features?: string[] }) & {
9292
SourceSandboxName?: string;
9393
SourceId?: string;
9494
} = {

test/shared/sandboxRequest.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,24 @@ describe('sandboxRequest builder', () => {
101101
const res = await createSandboxRequest(undefined, $$.TEST_LOGGER, {
102102
SourceSandboxName: 'sbox',
103103
SandboxName: 'foo',
104-
Features: JSON.stringify(['DataStorage']),
104+
Features: ['DataStorage'],
105105
});
106106
assert(res);
107107
expect(res.sandboxReq.SandboxName).equals('foo');
108108
expect(res.srcSandboxName).equals('sbox');
109-
expect(res.sandboxReq.Features).equals(JSON.stringify(['DataStorage']));
109+
expect(res.sandboxReq.Features).deep.equals(['DataStorage']);
110110
});
111111

112112
it('srcId with features', async () => {
113113
const res = await createSandboxRequest(undefined, $$.TEST_LOGGER, {
114114
SourceId: '0GQ000000000001',
115115
SandboxName: 'foo',
116-
Features: JSON.stringify(['DataStorage']),
116+
Features: ['DataStorage'],
117117
});
118118
assert(res);
119119
expect(res.sandboxReq.SandboxName).equals('foo');
120120
expect(res.srcId).equals('0GQ000000000001');
121-
expect(res.sandboxReq.Features).equals(JSON.stringify(['DataStorage']));
121+
expect(res.sandboxReq.Features).deep.equals(['DataStorage']);
122122
});
123123
});
124124
describe('not clone', () => {

0 commit comments

Comments
 (0)