Skip to content

Commit cdfdd13

Browse files
authored
fix: add recipe ids W-11157722 (#118)
* fix: add recipe ids W-11157722 * fix: updates per code review W-11157722
1 parent a474bf8 commit cdfdd13

7 files changed

Lines changed: 102 additions & 11 deletions

File tree

command-snapshot.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
{
239239
"command": "analytics:template:create",
240240
"plugin": "@salesforce/analytics",
241-
"flags": ["apiversion", "description", "folderid", "json", "label", "loglevel", "targetusername"]
241+
"flags": ["apiversion", "description", "folderid", "json", "label", "loglevel", "targetusername", "recipeids"]
242242
},
243243
{
244244
"command": "analytics:template:delete",
@@ -273,7 +273,8 @@
273273
"loglevel",
274274
"targetusername",
275275
"templateid",
276-
"templatename"
276+
"templatename",
277+
"recipeids"
277278
]
278279
}
279280
]

messages/template.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@
4444
"displayDetailHeader": "Template Details",
4545
"missingRequiredField": "Missing Required Field: templateid or templatename",
4646
"assetVersionFlagDescription": "version number for upgrading the template (available in api version 54.0)",
47-
"assetVersionFlagLongDescription": "Version number for upgrading the template."
47+
"assetVersionFlagLongDescription": "Version number for upgrading the template.",
48+
"recipeidsFlagDescription": "comma-separated list of recipe IDs",
49+
"recipeidsFlagLongDescription": "comma-separated list of recipe IDs to be included with the template. "
4850
}

src/commands/analytics/template/create.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export default class Create extends SfdxCommand {
1717
public static description = messages.getMessage('createCommandDescription');
1818
public static longDescription = messages.getMessage('createCommandLongDescription');
1919

20-
public static examples = ['$ sfdx analytics:template:create -f folderid'];
20+
public static examples = [
21+
'$ sfdx analytics:template:create -f folderid',
22+
'$ sfdx analytics:template:create -f folderid -r "recipeid1, recipeid2"'
23+
];
2124

2225
protected static flagsConfig = {
2326
folderid: flags.id({
@@ -26,7 +29,14 @@ export default class Create extends SfdxCommand {
2629
description: messages.getMessage('folderidFlagDescription'),
2730
longDescription: messages.getMessage('folderidFlagLongDescription')
2831
}),
29-
// label & description only work in 232+, they are sliently ignored on the server in 230
32+
// recipeids only work in 238+, they are silently ignored on the server in 236-
33+
recipeids: flags.array({
34+
char: 'r',
35+
required: false,
36+
description: messages.getMessage('recipeidsFlagDescription'),
37+
longDescription: messages.getMessage('recipeidsFlagLongDescription')
38+
}),
39+
// label & description only work in 232+, they are silently ignored on the server in 230
3040
label: flags.string({
3141
char: 'l',
3242
description: messages.getMessage('templateLabelFlagDescription'),
@@ -46,7 +56,8 @@ export default class Create extends SfdxCommand {
4656
// Create the wave template from an app/folder id
4757
const waveTemplateId = await template.create(this.flags.folderid as string, {
4858
label: this.flags.label as string | undefined,
49-
description: this.flags.description as string | undefined
59+
description: this.flags.description as string | undefined,
60+
recipeIds: this.flags.recipeids as string[] | undefined
5061
});
5162
this.ux.log(messages.getMessage('createSuccess', [waveTemplateId]));
5263
return waveTemplateId;

src/commands/analytics/template/update.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export default class Update extends SfdxCommand {
1818
public static description = messages.getMessage('updateCommandDescription');
1919
public static longDescription = messages.getMessage('updateCommandLongDescription');
2020

21-
public static examples = ['$ sfdx analytics:template:update -t templateid -f folderid'];
21+
public static examples = [
22+
'$ sfdx analytics:template:update -t templateid -f folderid',
23+
'$ sfdx analytics:template:update -t templateid -f folderid -r "recipeid1, recipeid2"'
24+
];
2225

2326
protected static flagsConfig = {
2427
templateid: flags.id({
@@ -38,6 +41,13 @@ export default class Update extends SfdxCommand {
3841
description: messages.getMessage('folderidFlagDescription'),
3942
longDescription: messages.getMessage('folderidFlagLongDescription')
4043
}),
44+
// recipeids only work in 238+, they are silently ignored on the server in 236-
45+
recipeids: flags.array({
46+
char: 'r',
47+
required: false,
48+
description: messages.getMessage('recipeidsFlagDescription'),
49+
longDescription: messages.getMessage('recipeidsFlagLongDescription')
50+
}),
4151
assetversion: flags.integer({
4252
char: 'v',
4353
description: messages.getMessage('assetVersionFlagDescription'),
@@ -66,6 +76,7 @@ export default class Update extends SfdxCommand {
6676
}
6777
let folderid = this.flags.folderid as string | undefined;
6878
const assetversion = this.flags.assetversion as number | undefined;
79+
const recipeIds = this.flags.recipeids as string[] | undefined;
6980

7081
const template = new WaveTemplate(this.org as Org);
7182

@@ -102,7 +113,7 @@ export default class Update extends SfdxCommand {
102113
return;
103114
}
104115
}
105-
const result = await template.update(folderid, templateInput, assetversion);
116+
const result = await template.update(folderid, templateInput, assetversion, recipeIds);
106117
this.ux.log(messages.getMessage('updateSuccess', [result?.name, result?.id, folderid]));
107118
return templateInput;
108119
}

src/lib/analytics/template/wavetemplate.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type TemplateType = Record<string, unknown> & {
1919
};
2020
templateType?: string;
2121
assetVersion?: string;
22+
recipeIds?: string[];
2223
};
2324

2425
export default class WaveTemplate {
@@ -46,9 +47,9 @@ export default class WaveTemplate {
4647

4748
public async create(
4849
folderid: string,
49-
{ label, description }: { label?: string; description?: string } = {}
50+
{ label, description, recipeIds }: { label?: string; description?: string; recipeIds?: string[] } = {}
5051
): Promise<string | undefined> {
51-
const body = JSON.stringify({ folderSource: { id: folderid }, label, description });
52+
const body = JSON.stringify({ folderSource: { id: folderid }, label, description, recipeIds });
5253
const response = await connectRequest<TemplateType>(this.connection, {
5354
method: 'POST',
5455
url: this.templatesUrl,
@@ -64,12 +65,16 @@ export default class WaveTemplate {
6465
public async update(
6566
folderid: string,
6667
templateIdOrName: string,
67-
templateAssetVersion: number | unknown
68+
templateAssetVersion: number | unknown,
69+
recipeIds: string[] | unknown
6870
): Promise<{ id: string | undefined; name: string | undefined } | undefined> {
6971
const opts: Record<string, unknown> = { folderSource: { id: folderid } };
7072
if (templateAssetVersion && this.serverVersion >= 54.0) {
7173
opts.assetVersion = templateAssetVersion;
7274
}
75+
if (recipeIds && this.serverVersion >= 55.0) {
76+
opts.recipeIds = recipeIds;
77+
}
7378

7479
const body = JSON.stringify(opts);
7580
const wtUrl = this.templatesUrl + encodeURIComponent(templateIdOrName);

test/commands/template/create.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,33 @@ describe('analytics:template:create', () => {
113113
description: 'test description'
114114
});
115115
});
116+
117+
test
118+
.withOrg({ username: 'test@org.com' }, true)
119+
.withConnectionRequest(request => {
120+
request = ensureJsonMap(request);
121+
if (request.method === 'POST') {
122+
saveOffRequestBody(ensureString(request.body));
123+
return Promise.resolve({ id: templateId });
124+
}
125+
return Promise.reject();
126+
})
127+
.stdout()
128+
.command([
129+
'analytics:template:create',
130+
'--folderid',
131+
'00lxx000000000zCAA',
132+
'-r',
133+
'05vxx0000004CAeAAM, 05vxx0000004CAeAAM'
134+
])
135+
.it(
136+
'runs analytics:template:create --folderid 00lxx000000000zCAA, -r "05vxx0000004CAeAAM, 05vxx0000004CAeAAM"',
137+
ctx => {
138+
expect(ctx.stdout).to.contain(messages.getMessage('createSuccess', [templateId]));
139+
expect(requestBody, 'requestBody').to.deep.equal({
140+
folderSource: { id: '00lxx000000000zCAA' },
141+
recipeIds: ['05vxx0000004CAeAAM', '05vxx0000004CAeAAM']
142+
});
143+
}
144+
);
116145
});

test/commands/template/update.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,36 @@ describe('analytics:template:update', () => {
142142
.it('runs analytics:template::update --templatename myTemplate', ctx => {
143143
expect(ctx.stdout).to.contain(messages.getMessage('errorNoFolderFound', [templateName]));
144144
});
145+
146+
test
147+
.withOrg({ username: 'test@org.com' }, true)
148+
.withConnectionRequest(request => {
149+
request = ensureJsonMap(request);
150+
if (request.method === 'PUT') {
151+
saveOffRequestBody(ensureString(request.body));
152+
return Promise.resolve({ name: templateName, id: templateId });
153+
}
154+
return Promise.reject();
155+
})
156+
.stdout()
157+
.command([
158+
'analytics:template:update',
159+
'--folderid',
160+
'00lxx000000000zCAA',
161+
'--templateid',
162+
'0Nkxx000000000zCAA',
163+
'-r',
164+
'05vxx0000004CAeAAM, 05vxx0000004CAeAAM'
165+
])
166+
.it(
167+
'runs analytics:template:update --templateid 0Nkxx000000000zCAA --folderid 00lxx000000000zCAA -r "05vxx0000004CAeAAM, 05vxx0000004CAeAAM"',
168+
ctx => {
169+
expect(ctx.stdout).to.contain(
170+
messages.getMessage('updateSuccess', [templateName, templateId, '00lxx000000000zCAA'])
171+
);
172+
expect(requestBody, 'requestBody').to.deep.equal({
173+
folderSource: { id: '00lxx000000000zCAA' }
174+
});
175+
}
176+
);
145177
});

0 commit comments

Comments
 (0)