-
Notifications
You must be signed in to change notification settings - Fork 328
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
Added internalName option for spo field commands #6379
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,51 @@ describe(commands.FIELD_GET, () => { | |
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid\'03e45e84-1992-4d42-9116-26f756012634\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('should call the correct GET url when field internalName and list title specified (verbose)', async () => { | ||
const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { debug: true, verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listTitle: 'Documents' } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle(\'Documents\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('should call the correct GET url when field internalName and list title specified', async () => { | ||
const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listTitle: 'Documents' } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle(\'Documents\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('should call the correct GET url when field internalName and list url specified', async () => { | ||
const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we please use full URL's instead of using indexOf please? Please do this for all your tests |
||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let's use single quotes |
||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { debug: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listId: '03e45e84-1992-4d42-9116-26f756012634' } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid\'03e45e84-1992-4d42-9116-26f756012634\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('correctly handles site column not found', async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) > -1) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ interface Options extends GlobalOptions { | |||||||||
listUrl?: string; | ||||||||||
id?: string; | ||||||||||
title?: string; | ||||||||||
internalName?: string; | ||||||||||
} | ||||||||||
|
||||||||||
class SpoFieldGetCommand extends SpoCommand { | ||||||||||
|
@@ -45,7 +46,8 @@ class SpoFieldGetCommand extends SpoCommand { | |||||||||
listTitle: typeof args.options.listTitle !== 'undefined', | ||||||||||
listUrl: typeof args.options.listUrl !== 'undefined', | ||||||||||
id: typeof args.options.id !== 'undefined', | ||||||||||
title: typeof args.options.title !== 'undefined' | ||||||||||
title: typeof args.options.title !== 'undefined', | ||||||||||
internalName: typeof args.options.internalName !== 'undefined' | ||||||||||
}); | ||||||||||
}); | ||||||||||
} | ||||||||||
|
@@ -69,6 +71,9 @@ class SpoFieldGetCommand extends SpoCommand { | |||||||||
}, | ||||||||||
{ | ||||||||||
option: '-t, --title [title]' | ||||||||||
}, | ||||||||||
{ | ||||||||||
option: '--internalName [internalName]' | ||||||||||
} | ||||||||||
); | ||||||||||
} | ||||||||||
|
@@ -95,7 +100,7 @@ class SpoFieldGetCommand extends SpoCommand { | |||||||||
} | ||||||||||
|
||||||||||
#initOptionSets(): void { | ||||||||||
this.optionSets.push({ options: ['id', 'title'] }); | ||||||||||
this.optionSets.push({ options: ['id', 'title', 'internalName'] }); | ||||||||||
} | ||||||||||
|
||||||||||
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> { | ||||||||||
|
@@ -117,6 +122,9 @@ class SpoFieldGetCommand extends SpoCommand { | |||||||||
if (args.options.id) { | ||||||||||
fieldRestUrl = `/getbyid('${formatting.encodeQueryParameter(args.options.id)}')`; | ||||||||||
} | ||||||||||
else if (args.options.internalName) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we not do something like:
Suggested change
|
||||||||||
fieldRestUrl = `/getbyinternalnameortitle('${formatting.encodeQueryParameter(args.options.internalName as string)}')`; | ||||||||||
} | ||||||||||
else { | ||||||||||
fieldRestUrl = `/getbyinternalnameortitle('${formatting.encodeQueryParameter(args.options.title as string)}')`; | ||||||||||
} | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,18 @@ describe(commands.FIELD_REMOVE, () => { | |
assert(promptIssued); | ||
}); | ||
|
||
it('prompts before removing field when confirmation argument not passed (internalName)', async () => { | ||
await command.action(logger, { options: { internalName: 'myfield1', webUrl: 'https://contoso.sharepoint.com' } }); | ||
|
||
assert(promptIssued); | ||
}); | ||
|
||
it('prompts before removing list column when confirmation argument not passed (internalName)', async () => { | ||
await command.action(logger, { options: { internalName: 'myfield1', webUrl: 'https://contoso.sharepoint.com', listTitle: 'My List' } }); | ||
|
||
assert(promptIssued); | ||
}); | ||
|
||
it('aborts removing field when prompt not confirmed', async () => { | ||
sinonUtil.restore(cli.promptForConfirmation); | ||
sinon.stub(cli, 'promptForConfirmation').resolves(false); | ||
|
@@ -454,6 +466,51 @@ describe(commands.FIELD_REMOVE, () => { | |
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid\'03e45e84-1992-4d42-9116-26f756012634\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('calls the correct get url when field internalName and list title specified (verbose)', async () => { | ||
const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, let's use full URLs |
||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { debug: true, verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listTitle: 'Documents', force: true } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle(\'Documents\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('calls the correct get url when field internalName and list title specified', async () => { | ||
const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listTitle: 'Documents', force: true } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle(\'Documents\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('calls the correct get url when field internalName and list url specified', async () => { | ||
const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { | ||
return { | ||
"Id": "03e45e84-1992-4d42-9116-26f756012634" | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { debug: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', internalName: 'Title', listId: '03e45e84-1992-4d42-9116-26f756012634', force: true } }); | ||
assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid\'03e45e84-1992-4d42-9116-26f756012634\')/fields/getbyinternalnameortitle(\'Title\')'); | ||
}); | ||
|
||
it('correctly handles site column not found', async () => { | ||
const error = { | ||
error: { | ||
|
@@ -534,7 +591,7 @@ describe(commands.FIELD_REMOVE, () => { | |
assert(containsTypeOption); | ||
}); | ||
|
||
it('fails validation if both id and title options are not passed', async () => { | ||
it('fails validation if either of id, title and internalName options are not passed', async () => { | ||
sinon.stub(cli, 'getSettingWithDefaultValue').callsFake((settingName, defaultValue) => { | ||
if (settingName === settingsNames.prompt) { | ||
return false; | ||
|
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 here, let's use full url's