-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds command spp model remove
. Closes #6118
#6410
base: main
Are you sure you want to change the base?
Conversation
Thank you, well try to review it ASAP! |
5afaf7c
to
9a84d0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice stuff, I made a few comments along the way. Could you take a look at them, please?
private getCorrectRequestUrl(siteUrl: string, args: CommandArgs): string { | ||
if (args.options.id) { | ||
return `${siteUrl}/_api/machinelearning/models/getbyuniqueid('${args.options.id}')`; | ||
} | ||
|
||
return `${siteUrl}/_api/machinelearning/models/getbytitle('${formatting.encodeQueryParameter(args.options.title!)}')`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating a new function for this, let's just use an if/else statement with a variable.
this.validators.push( | ||
async (args: CommandArgs) => { | ||
if (args.options.id && !validation.isValidGuid(args.options.id)) { | ||
return `${args.options.id} is not a valid GUID`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's repeat the option name so the user knows exactly which option is failing.
return `${args.options.id} is not a valid GUID`; | |
return `${args.options.id} is not a valid GUID for option 'id'.`; |
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> { | ||
try { | ||
if (!args.options.force) { | ||
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove the model '${args.options.id || args.options.title}'?` }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove the model '${args.options.id || args.options.title}'?` }); | |
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove model '${args.options.id || args.options.title}'?` }); |
|
||
it('correctly handles an access denied error', async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web?$select=WebTemplateConfiguration`) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of throwing an error for this API, I think it's more useful to throw an error when a non existing name or title is passed when removing a model.
}); | ||
|
||
await command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/portal', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f' } }); | ||
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('9b1b1e42-794b-4c71-93ac-5ed92488b67f')`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use assert(stubDelete.calledOnce)
.
}); | ||
|
||
await command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/portal', id: '164720c8-35ee-4157-ba26-db6726264f9d', force: true } }); | ||
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('164720c8-35ee-4157-ba26-db6726264f9d')`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just check if the delete request was fired. If the URL doesn't match, it will throw an error anyway.
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('9b1b1e42-794b-4c71-93ac-5ed92488b67f')`); | ||
assert(confirmationStub.calledOnce); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbytitle('ModelName')`); | ||
assert(confirmationStub.calledOnce); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just check if the delete request was fired. If the URL doesn't match, it will throw an error anyway.
} | ||
}; | ||
|
||
await request.delete(requestOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kinda sad that when you specify a name that doesn't exist, it just succeeds. Is there a way for us to check if the request actually works?
After doing a quick test, seems like odata.null: true
is returned when the specified model doesn't exist. Is this something we can check and throw a custom error?
|
||
## Remarks | ||
|
||
Note that this model will be removed from all libraries before it can be deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird wording, shouldn't it be should be removed
? Maybe it's worth to put this in a note admonition.
9a84d0e
to
53f4c24
Compare
@mkm17 I added the |
Adds command
spp model remove
. Closes #6118