Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/cmd/spo/tenant/tenant-commandset-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ m365 spo tenant commandset get --clientSideComponentId 7096cded-b83d-4eab-96f0-d
<TabItem value="Markdown">

```md
# spo tenant applicationcustomizer get --id "2" --tenantWideExtensionComponentProperties "true"
# spo tenant commandset get --id "2" --tenantWideExtensionComponentProperties "true"

Date: 17/05/2024

Expand Down
27 changes: 15 additions & 12 deletions src/m365/spo/commands/hubsite/hubsite-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import { pid } from '../../../../utils/pid.js';
import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
import commands from '../../commands.js';
import spoListItemListCommand from '../listitem/listitem-list.js';
import command from './hubsite-get.js';
import { settingsNames } from '../../../../settingsNames.js';
import { ListItemListOptions, spoListItem } from '../../../../utils/spoListItem.js';
import { spo } from '../../../../utils/spo.js';

describe(commands.HUBSITE_GET, () => {
const validId = '9ff01368-1183-4cbb-82f2-92e7e9a3f4ce';
const validTitle = 'Hub Site';
const validUrl = 'https://contoso.sharepoint.com';
const spoAdminUrl = 'https://contoso-admin.sharepoint.com';

const hubsiteResponse = {
"ID": validId,
Expand All @@ -38,7 +40,8 @@ describe(commands.HUBSITE_GET, () => {
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
auth.connection.spoUrl = 'https://contoso.sharepoint.com';
auth.connection.spoUrl = validUrl;
sinon.stub(spo, 'getSpoAdminUrl').resolves(spoAdminUrl);
commandInfo = cli.getCommandInfo(command);
sinon.stub(cli, 'getSettingWithDefaultValue').callsFake((settingName: string, defaultValue: any) => {
if (settingName === 'prompt') {
Expand Down Expand Up @@ -68,7 +71,7 @@ describe(commands.HUBSITE_GET, () => {
afterEach(() => {
sinonUtil.restore([
request.get,
cli.executeCommandWithOutput,
spoListItem.getListItems,
cli.getSettingWithDefaultValue,
cli.handleMultipleResultsFound
]);
Expand Down Expand Up @@ -260,13 +263,13 @@ describe(commands.HUBSITE_GET, () => {
};
}

throw 'Invalid request';
throw 'Invalid request: ' + JSON.stringify(opts);
});

sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise<any> => {
if (command === spoListItemListCommand) {
return {
stdout: JSON.stringify([
sinon.stub(spoListItem, 'getListItems').callsFake(async (options: ListItemListOptions) => {
if (options.webUrl === spoAdminUrl) {
if (options.listTitle === 'DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS') {
return [
{
Title: "Lucky Charms",
SiteId: "c08c7be1-4b97-4caa-b88f-ec91100d7774",
Expand All @@ -287,11 +290,11 @@ describe(commands.HUBSITE_GET, () => {
SiteId: "ee8b42c3-3e6f-4822-87c1-c21ad666046b",
SiteUrl: "https://contoso.sharepoint.com/sites/leadership-connection"
}
]
)
};
] as any[];
}
}
throw 'Invalid request';

throw 'Invalid request: ' + JSON.stringify(options);
});

await command.action(logger, { options: { id: 'ee8b42c3-3e6f-4822-87c1-c21ad666046b', includeAssociatedSites: true, output: 'json' } });
Expand Down
22 changes: 9 additions & 13 deletions src/m365/spo/commands/hubsite/hubsite-get.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { cli, CommandOutput } from '../../../../cli/cli.js';
import { cli } from '../../../../cli/cli.js';
import { Logger } from '../../../../cli/Logger.js';
import Command from '../../../../Command.js';
import GlobalOptions from '../../../../GlobalOptions.js';
import request, { CliRequestOptions } from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import { spo } from '../../../../utils/spo.js';
import { ListItemListOptions, spoListItem } from '../../../../utils/spoListItem.js';
import { validation } from '../../../../utils/validation.js';
import SpoCommand from '../../../base/SpoCommand.js';
import commands from '../../commands.js';
import spoListItemListCommand, { Options as SpoListItemListCommandOptions } from '../listitem/listitem-list.js';
import { AssociatedSite } from './AssociatedSite.js';
import { HubSite } from './HubSite.js';

Expand Down Expand Up @@ -92,8 +91,7 @@ class SpoHubSiteGetCommand extends SpoCommand {

if (args.options.includeAssociatedSites === true && args.options.output && !cli.shouldTrimOutput(args.options.output)) {
const spoAdminUrl = await spo.getSpoAdminUrl(logger, this.debug);
const associatedSitesCommandOutput = await this.getAssociatedSites(spoAdminUrl, hubSite.SiteId, logger, args);
const associatedSites: AssociatedSite[] = JSON.parse((associatedSitesCommandOutput as CommandOutput).stdout) as AssociatedSite[];
const associatedSites = await this.getAssociatedSites(spoAdminUrl, hubSite.SiteId, logger);
hubSite.AssociatedSites = associatedSites.filter(s => s.SiteId !== hubSite.SiteId);
}

Expand All @@ -104,18 +102,16 @@ class SpoHubSiteGetCommand extends SpoCommand {
}
}

private async getAssociatedSites(spoAdminUrl: string, hubSiteId: string, logger: Logger, args: CommandArgs): Promise<CommandOutput> {
const options: SpoListItemListCommandOptions = {
output: 'json',
debug: args.options.debug,
verbose: args.options.verbose,
listTitle: 'DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS',
private async getAssociatedSites(spoAdminUrl: string, hubSiteId: string, logger: Logger): Promise<AssociatedSite[]> {
const options: ListItemListOptions = {
webUrl: spoAdminUrl,
listTitle: 'DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS',
filter: `HubSiteId eq '${hubSiteId}'`,
fields: 'Title,SiteUrl,SiteId'
fields: ['Title', 'SiteUrl', 'SiteId']
};

return cli.executeCommandWithOutput(spoListItemListCommand as Command, { options: { ...options, _: [] } });
const listItems = await spoListItem.getListItems(options, logger, this.verbose);
return listItems as any as AssociatedSite[];
}

private async getHubSiteById(spoUrl: string, options: Options): Promise<HubSite> {
Expand Down
Loading