From a4b0bdd59c925f488b7f85581f05aaed31639ab1 Mon Sep 17 00:00:00 2001 From: Shantha Kumar T Date: Sat, 21 Dec 2024 06:42:34 +0530 Subject: [PATCH] changes updated --- src/m365/spo/commands/field/field-get.spec.ts | 36 ++-- src/m365/spo/commands/field/field-get.ts | 5 +- .../spo/commands/field/field-remove.spec.ts | 173 ++++++++---------- src/m365/spo/commands/field/field-set.spec.ts | 34 ++-- 4 files changed, 111 insertions(+), 137 deletions(-) diff --git a/src/m365/spo/commands/field/field-get.spec.ts b/src/m365/spo/commands/field/field-get.spec.ts index 6226a37f65f..0521ff16064 100644 --- a/src/m365/spo/commands/field/field-get.spec.ts +++ b/src/m365/spo/commands/field/field-get.spec.ts @@ -86,7 +86,7 @@ describe(commands.FIELD_GET, () => { it('gets information about a site column', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid('5ee2dd25-d941-455a-9bdb-7f2c54aed11b')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('5ee2dd25-d941-455a-9bdb-7f2c54aed11b')`) { return { "AutoIndexed": false, "CanBeDeleted": true, @@ -177,7 +177,7 @@ describe(commands.FIELD_GET, () => { it('gets information about a list column', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { return { "AutoIndexed": false, "CanBeDeleted": false, @@ -262,7 +262,7 @@ describe(commands.FIELD_GET, () => { it('should call the correct GET url when id and list url specified', async () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2FLists%2FEvents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -270,14 +270,13 @@ describe(commands.FIELD_GET, () => { throw 'Invalid request'; }); - - await assert.rejects(command.action(logger, { options: { verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634', listUrl: 'Lists/Events' } })); + await command.action(logger, { options: { debug: true, verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634', listUrl: 'Lists/Events' } }); assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/GetList(\'%2Fsites%2Fportal%2FLists%2FEvents\')/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')'); }); it('should call the correct GET url when field title 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -292,7 +291,7 @@ describe(commands.FIELD_GET, () => { it('should call the correct GET url when field title and list title specified', async () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -306,8 +305,9 @@ describe(commands.FIELD_GET, () => { }); it('should call the correct GET url when field title and list url specified', async () => { + const webUrl = 'https://contoso.sharepoint.com/sites/portal'; const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `${webUrl}/_api/web/lists(guid'03e45e84-1992-4d42-9116-26f756012634')/fields/getbyinternalnameortitle('Title')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -321,8 +321,9 @@ describe(commands.FIELD_GET, () => { }); it('should call the correct GET url when field internalName and list title specified (verbose)', async () => { + const webUrl = 'https://contoso.sharepoint.com/sites/portal'; const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `${webUrl}/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -337,7 +338,7 @@ describe(commands.FIELD_GET, () => { 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { "Id": "03e45e84-1992-4d42-9116-26f756012634" }; @@ -351,10 +352,11 @@ describe(commands.FIELD_GET, () => { }); it('should call the correct GET url when field internalName and list url specified', async () => { + const webUrl = 'https://contoso.sharepoint.com/sites/portal'; const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `${webUrl}/_api/web/lists(guid'03e45e84-1992-4d42-9116-26f756012634')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -367,14 +369,14 @@ describe(commands.FIELD_GET, () => { 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw { error: { "odata.error": { "code": "-2147024809, System.ArgumentException", "message": { "lang": "en-US", - "value": "Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} https://m365x526922.sharepoint.com/sites/portal " + "value": "Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} https://contoso.sharepoint.com/sites/portal " } } } @@ -385,12 +387,12 @@ describe(commands.FIELD_GET, () => { }); await assert.rejects(command.action(logger, { options: { debug: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634' } } as any), - new CommandError('Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} https://m365x526922.sharepoint.com/sites/portal ')); + new CommandError('Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} https://contoso.sharepoint.com/sites/portal ')); }); it('correctly handles list column not found', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw { error: { "odata.error": { @@ -413,7 +415,7 @@ describe(commands.FIELD_GET, () => { it('correctly handles list not found', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw { error: { "odata.error": { diff --git a/src/m365/spo/commands/field/field-get.ts b/src/m365/spo/commands/field/field-get.ts index 2329b642e55..40e55719ea4 100644 --- a/src/m365/spo/commands/field/field-get.ts +++ b/src/m365/spo/commands/field/field-get.ts @@ -122,11 +122,8 @@ class SpoFieldGetCommand extends SpoCommand { if (args.options.id) { fieldRestUrl = `/getbyid('${formatting.encodeQueryParameter(args.options.id)}')`; } - else if (args.options.internalName) { - fieldRestUrl = `/getbyinternalnameortitle('${formatting.encodeQueryParameter(args.options.internalName as string)}')`; - } else { - fieldRestUrl = `/getbyinternalnameortitle('${formatting.encodeQueryParameter(args.options.title as string)}')`; + fieldRestUrl = `/getbyinternalnameortitle('${formatting.encodeQueryParameter((args.options.title || args.options.internalName) as string)}')`; } const requestOptions: CliRequestOptions = { diff --git a/src/m365/spo/commands/field/field-remove.spec.ts b/src/m365/spo/commands/field/field-remove.spec.ts index f8eab248ed2..a88bd3152c6 100644 --- a/src/m365/spo/commands/field/field-remove.spec.ts +++ b/src/m365/spo/commands/field/field-remove.spec.ts @@ -125,8 +125,7 @@ describe(commands.FIELD_REMOVE, () => { it('removes the field when prompt confirmed', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { requests.push(opts); - - if ((opts.url as string).indexOf(`/_api/web/fields(guid'`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields(guid'b2307a39-e878-458b-bc90-03bc578531d6')`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -154,7 +153,7 @@ describe(commands.FIELD_REMOVE, () => { it('command correctly handles field get reject request', async () => { const err = 'Invalid request'; sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf('/_api/web/fields/getbyinternalnameortitle(') > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyinternalnameortitle('field1')`) { throw err; } @@ -173,38 +172,18 @@ describe(commands.FIELD_REMOVE, () => { }), new CommandError(err)); }); - it('uses correct API url when id option is passed', async () => { - sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf('/_api/web/fields/getbyid(\'') > -1) { - return 'Correct Url'; - } - - throw 'Invalid request'; - }); - - const actionId: string = '0CD891EF-AFCE-4E55-B836-FCE03286CCCF'; - - await command.action(logger, { - options: { - id: actionId, - webUrl: 'https://contoso.sharepoint.com', - force: true - } - }); - }); - it('calls the correct remove url when id and list url specified', async () => { const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2FLists%2FEvents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } throw 'Invalid request'; }); - await assert.rejects(command.action(logger, { options: { verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634', listUrl: 'Lists/Events', force: true } })); + await command.action(logger, { options: { debug: true, verbose: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634', listUrl: 'Lists/Events', force: true } }); assert.strictEqual(getStub.lastCall.args[0].url, 'https://contoso.sharepoint.com/sites/portal/_api/web/GetList(\'%2Fsites%2Fportal%2FLists%2FEvents\')/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')'); }); @@ -215,17 +194,17 @@ describe(commands.FIELD_REMOVE, () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList(\'%2Fsites%2Fportal%2FLists%2FEvents\')/fields`) { return { - "value": [{ - "Id": "03e45e84-1992-4d42-9116-26f756012634", - "Group": "MyGroup" + 'value': [{ + 'Id': '03e45e84-1992-4d42-9116-26f756012634', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012635", - "Group": "MyGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012635', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012636", - "Group": "DifferentGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012636', + 'Group': 'DifferentGroup' }] }; } @@ -233,15 +212,14 @@ describe(commands.FIELD_REMOVE, () => { }); const deletion = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/GetList(\'%2Fsites%2Fportal%2FLists%2FEvents\')/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2FLists%2FEvents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } - - if ((opts.url as string).indexOf(`/_api/web/GetList(\'%2Fsites%2Fportal%2FLists%2FEvents\')/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012635\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2FLists%2FEvents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012635')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012635" + 'Id': '03e45e84-1992-4d42-9116-26f756012635' }; } @@ -259,17 +237,17 @@ describe(commands.FIELD_REMOVE, () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields`) { return { - "value": [{ - "Id": "03e45e84-1992-4d42-9116-26f756012634", - "Group": "MyGroup" + 'value': [{ + 'Id': '03e45e84-1992-4d42-9116-26f756012634', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012635", - "Group": "MyGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012635', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012636", - "Group": "DifferentGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012636', + 'Group': 'DifferentGroup' }] }; } @@ -277,15 +255,14 @@ describe(commands.FIELD_REMOVE, () => { }); const deletion = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } - - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012635\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012635')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012635" + 'Id': '03e45e84-1992-4d42-9116-26f756012635' }; } @@ -303,17 +280,17 @@ describe(commands.FIELD_REMOVE, () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields`) { return { - "value": [{ - "Id": "03e45e84-1992-4d42-9116-26f756012634", - "Group": "MyGroup" + 'value': [{ + 'Id': '03e45e84-1992-4d42-9116-26f756012634', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012635", - "Group": "MyGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012635', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012636", - "Group": "DifferentGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012636', + 'Group': 'DifferentGroup' }] }; } @@ -323,7 +300,7 @@ describe(commands.FIELD_REMOVE, () => { const deletion = sinon.stub(request, 'post').callsFake(async (opts) => { if ((opts.url as string).indexOf(`/_api/web/fields`) > -1) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -350,13 +327,12 @@ describe(commands.FIELD_REMOVE, () => { const getStub = sinon.stub(request, 'get').rejects(error); const deletion = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012635\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012635')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012635" + 'Id': '03e45e84-1992-4d42-9116-26f756012635' }; } - - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw error; } @@ -383,17 +359,17 @@ describe(commands.FIELD_REMOVE, () => { const getStub = sinon.stub(request, 'get').callsFake(async (opts) => { if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields`) { return { - "value": [{ - "Id": "03e45e84-1992-4d42-9116-26f756012634", - "Group": "MyGroup" + 'value': [{ + 'Id': '03e45e84-1992-4d42-9116-26f756012634', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012635", - "Group": "MyGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012635', + 'Group': 'MyGroup' }, { - "Id": "03e45e84-1992-4d42-9116-26f756012636", - "Group": "DifferentGroup" + 'Id': '03e45e84-1992-4d42-9116-26f756012636', + 'Group': 'DifferentGroup' }] }; } @@ -401,13 +377,12 @@ describe(commands.FIELD_REMOVE, () => { }); const deletion = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012635\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012635')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012635" + 'Id': '03e45e84-1992-4d42-9116-26f756012635' }; } - - if ((opts.url as string).indexOf(`/_api/web/fields/getbyid(\'03e45e84-1992-4d42-9116-26f756012634\')`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw error; } @@ -423,9 +398,9 @@ describe(commands.FIELD_REMOVE, () => { it('calls the correct get url when field title 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -438,9 +413,9 @@ describe(commands.FIELD_REMOVE, () => { it('calls the correct get url when field title and list title specified', async () => { const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -453,9 +428,9 @@ describe(commands.FIELD_REMOVE, () => { it('calls the correct get url when field title and list url specified', async () => { const getStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'03e45e84-1992-4d42-9116-26f756012634')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -468,9 +443,9 @@ describe(commands.FIELD_REMOVE, () => { 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -483,9 +458,9 @@ describe(commands.FIELD_REMOVE, () => { 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -498,9 +473,9 @@ describe(commands.FIELD_REMOVE, () => { 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) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'03e45e84-1992-4d42-9116-26f756012634')/fields/getbyinternalnameortitle('Title')`) { return { - "Id": "03e45e84-1992-4d42-9116-26f756012634" + 'Id': '03e45e84-1992-4d42-9116-26f756012634' }; } @@ -523,7 +498,7 @@ describe(commands.FIELD_REMOVE, () => { } }; sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf('/_api/web/fields/getbyinternalnameortitle(') > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/fields/getbyinternalnameortitle('actionTitle')`) { throw error; } throw 'Invalid request'; @@ -536,14 +511,14 @@ describe(commands.FIELD_REMOVE, () => { it('correctly handles list column not found', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists/getByTitle('Documents')/fields/getbyid(`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw { error: { - "odata.error": { - "code": "-2147024809, System.ArgumentException", - "message": { - "lang": "en-US", - "value": "Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} /sites/portal/Shared Documents" + 'odata.error': { + 'code': '-2147024809, System.ArgumentException', + 'message': { + 'lang': 'en-US', + 'value': 'Invalid field name. {03e45e84-1992-4d42-9116-26f756012634} /sites/portal/Shared Documents' } } } @@ -559,14 +534,14 @@ describe(commands.FIELD_REMOVE, () => { it('correctly handles list not found', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/lists/getByTitle('Documents')/fields/getbyid(`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/fields/getbyid('03e45e84-1992-4d42-9116-26f756012634')`) { throw { error: { - "odata.error": { - "code": "-1, System.ArgumentException", - "message": { - "lang": "en-US", - "value": "List 'Documents' does not exist at site with URL 'https://contoso.sharepoint.com/sites/portal'." + 'odata.error': { + 'code': '-1, System.ArgumentException', + 'message': { + 'lang': 'en-US', + 'value': 'List \'Documents\' does not exist at site with URL \'https://contoso.sharepoint.com/sites/portal\'.' } } } @@ -577,7 +552,7 @@ describe(commands.FIELD_REMOVE, () => { }); await assert.rejects(command.action(logger, { options: { debug: true, webUrl: 'https://contoso.sharepoint.com/sites/portal', id: '03e45e84-1992-4d42-9116-26f756012634', listTitle: 'Documents', force: true } } as any), - new CommandError("List 'Documents' does not exist at site with URL 'https://contoso.sharepoint.com/sites/portal'.")); + new CommandError('List \'Documents\' does not exist at site with URL \'https://contoso.sharepoint.com/sites/portal\'.')); }); it('supports specifying URL', () => { diff --git a/src/m365/spo/commands/field/field-set.spec.ts b/src/m365/spo/commands/field/field-set.spec.ts index 95ee86908da..4a87e64672c 100644 --- a/src/m365/spo/commands/field/field-set.spec.ts +++ b/src/m365/spo/commands/field/field-set.spec.ts @@ -76,7 +76,7 @@ describe(commands.FIELD_SET, () => { it('updates site column specified by title', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -114,7 +114,7 @@ describe(commands.FIELD_SET, () => { it('updates site column specified by internalName', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -152,7 +152,7 @@ describe(commands.FIELD_SET, () => { it('updates site column specified by id, pushing the changes to existing lists', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -189,7 +189,7 @@ describe(commands.FIELD_SET, () => { it('updates list column specified by id, list specified by id', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -242,7 +242,7 @@ describe(commands.FIELD_SET, () => { it('updates list column specified by title, list specified by title', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -294,7 +294,7 @@ describe(commands.FIELD_SET, () => { it('updates list column specified by internalName, list specified by title', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -456,7 +456,7 @@ describe(commands.FIELD_SET, () => { it('correctly escapes XML in list title', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -508,7 +508,7 @@ describe(commands.FIELD_SET, () => { it('ignores global options when creating request data', async () => { const postStub: Sinon.SinonStub = sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -561,7 +561,7 @@ describe(commands.FIELD_SET, () => { it('correctly escapes XML in field title', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'abc') { throw 'Invalid request'; @@ -599,7 +599,7 @@ describe(commands.FIELD_SET, () => { it('correctly escapes XML in field internalName', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'abc') { throw 'Invalid request'; @@ -637,7 +637,7 @@ describe(commands.FIELD_SET, () => { it('correctly escapes XML in field properties', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'abc') { throw 'Invalid request'; @@ -675,7 +675,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when the field specified by id doesn\'t exist', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -706,7 +706,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when the field specified by title doesn\'t exist', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -737,7 +737,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when the field specified by internalName doesn\'t exist', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -768,7 +768,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when the list specified by id doesn\'t exist', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -799,7 +799,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when the list specified by title doesn\'t exist', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request'; @@ -830,7 +830,7 @@ describe(commands.FIELD_SET, () => { it('correctly handles an error when updating the field failed', async () => { sinon.stub(request, 'post').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_vti_bin/client.svc/ProcessQuery`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_vti_bin/client.svc/ProcessQuery') { if (opts.headers && opts.headers['X-RequestDigest'] !== 'ABC') { throw 'Invalid request';