forked from pnp/cli-microsoft365
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command: spo page default get. Closes pnp#6493
- Loading branch information
1 parent
63210ca
commit a81f464
Showing
5 changed files
with
385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import Global from '/docs/cmd/_global.mdx'; | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# spo page default get | ||
|
||
Gets the home page for a specific site | ||
|
||
## Usage | ||
|
||
```sh | ||
m365 spo page default get [options] | ||
``` | ||
|
||
## Options | ||
|
||
```md definition-list | ||
`-u, --siteUrl <siteUrl>` | ||
: URL of the SharePoint site. | ||
``` | ||
|
||
<Global /> | ||
|
||
## Examples | ||
|
||
Get the home page of a specific site | ||
|
||
```sh | ||
m365 spo page default get --siteUrl https://contoso.sharepoint.com/sites/Marketing | ||
``` | ||
|
||
## Response | ||
|
||
<Tabs> | ||
<TabItem value="JSON"> | ||
|
||
```json | ||
{ | ||
"ListItemAllFields": { | ||
"CommentsDisabled": true, | ||
"FileSystemObjectType": 0, | ||
"Id": 1, | ||
"ServerRedirectedEmbedUri": null, | ||
"ServerRedirectedEmbedUrl": "", | ||
"ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800DE13AFD7BD1A9847A5DEB2C981024CB6", | ||
"OData__ColorTag": null, | ||
"ComplianceAssetId": null, | ||
"WikiField": null, | ||
"Title": "Home", | ||
"ClientSideApplicationId": "b6917cb1-93a0-4b97-a84d-7cf49975d4ec", | ||
"PageLayoutType": "Home", | ||
"CanvasContent1": null, | ||
"BannerImageUrl": null, | ||
"Description": null, | ||
"PromotedState": null, | ||
"FirstPublishedDate": null, | ||
"LayoutWebpartsContent": null, | ||
"OData__AuthorBylineId": null, | ||
"_AuthorBylineStringId": null, | ||
"OData__TopicHeader": null, | ||
"OData__SPSitePageFlags": null, | ||
"OData__SPCallToAction": null, | ||
"OData__OriginalSourceUrl": null, | ||
"OData__OriginalSourceSiteId": null, | ||
"OData__OriginalSourceWebId": null, | ||
"OData__OriginalSourceListId": null, | ||
"OData__OriginalSourceItemId": null, | ||
"ID": 1, | ||
"Created": "2023-05-20T17:37:33", | ||
"AuthorId": 1073741823, | ||
"Modified": "2023-05-20T17:37:33", | ||
"EditorId": 1073741823, | ||
"OData__CopySource": null, | ||
"CheckoutUserId": null, | ||
"OData__UIVersionString": "1.0", | ||
"GUID": "25af1202-addb-4f3a-ab69-f14d5630796a" | ||
}, | ||
"CheckInComment": "", | ||
"CheckOutType": 2, | ||
"ContentTag": "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1", | ||
"CustomizedPageStatus": 1, | ||
"ETag": "\"{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4\"", | ||
"Exists": true, | ||
"ExistsAllowThrowForPolicyFailures": true, | ||
"ExistsWithException": true, | ||
"IrmEnabled": false, | ||
"Length": "805", | ||
"Level": 1, | ||
"LinkingUri": null, | ||
"LinkingUrl": "", | ||
"MajorVersion": 1, | ||
"MinorVersion": 0, | ||
"Name": "Home.aspx", | ||
"ServerRelativeUrl": "/teams/Marketing/SitePages/Home.aspx", | ||
"TimeCreated": "2023-05-21T00:37:33Z", | ||
"TimeLastModified": "2023-05-21T00:37:33Z", | ||
"Title": "Home", | ||
"UIVersion": 512, | ||
"UIVersionLabel": "1.0", | ||
"UniqueId": "2f6cf80c-e4cc-4fcc-a424-8d36770ac481" | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Text"> | ||
|
||
```text | ||
CheckInComment : | ||
CheckOutType : 2 | ||
ContentTag : {2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1 | ||
CustomizedPageStatus : 1 | ||
ETag : "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4" | ||
Exists : true | ||
ExistsAllowThrowForPolicyFailures: true | ||
ExistsWithException : true | ||
IrmEnabled : false | ||
Length : 805 | ||
Level : 1 | ||
LinkingUri : null | ||
LinkingUrl : | ||
ListItemAllFields : {"CommentsDisabled":true,"FileSystemObjectType":0,"Id":1,"ServerRedirectedEmbedUri":null,"ServerRedirectedEmbedUrl":"","ContentTypeId":"0x0101009D1CB255DA76424F860D91F20E6C411800DE13AFD7BD1A9847A5DEB2C981024CB6","OData__ColorTag":null,"ComplianceAssetId":null,"WikiField":null,"Title":"Home","ClientSideApplicationId":"b6917cb1-93a0-4b97-a84d-7cf49975d4ec","PageLayoutType":"Home","CanvasContent1":null,"BannerImageUrl":null,"Description":null,"PromotedState":null,"FirstPublishedDate":null,"LayoutWebpartsContent":null,"OData__AuthorBylineId":null,"_AuthorBylineStringId":null,"OData__TopicHeader":null,"OData__SPSitePageFlags":null,"OData__SPCallToAction":null,"OData__OriginalSourceUrl":null,"OData__OriginalSourceSiteId":null,"OData__OriginalSourceWebId":null,"OData__OriginalSourceListId":null,"OData__OriginalSourceItemId":null,"ID":1,"Created":"2023-05-20T17:37:33","AuthorId":1073741823,"Modified":"2023-05-20T17:37:33","EditorId":1073741823,"OData__CopySource":null,"CheckoutUserId":null,"OData__UIVersionString":"1.0","GUID":"25af1202-addb-4f3a-ab69-f14d5630796a"} | ||
MajorVersion : 1 | ||
MinorVersion : 0 | ||
Name : Home.aspx | ||
ServerRelativeUrl : /teams/Marketing/SitePages/Home.aspx | ||
TimeCreated : 2023-05-21T00:37:33Z | ||
TimeLastModified : 2023-05-21T00:37:33Z | ||
Title : Home | ||
UIVersion : 512 | ||
UIVersionLabel : 1.0 | ||
UniqueId : 2f6cf80c-e4cc-4fcc-a424-8d36770ac481 | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="CSV"> | ||
|
||
```csv | ||
CheckInComment,CheckOutType,ContentTag,CustomizedPageStatus,ETag,Exists,ExistsAllowThrowForPolicyFailures,ExistsWithException,IrmEnabled,Length,Level,LinkingUri,LinkingUrl,MajorVersion,MinorVersion,Name,ServerRelativeUrl,TimeCreated,TimeLastModified,Title,UIVersion,UIVersionLabel,UniqueId | ||
,2,"{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1",1,"""{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4""",1,1,1,0,805,1,,,1,0,Home.aspx,/teams/Marketing/SitePages/Home.aspx,2023-05-21T00:37:33Z,2023-05-21T00:37:33Z,Home,512,1.0,2f6cf80c-e4cc-4fcc-a424-8d36770ac481 | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Markdown"> | ||
|
||
```md | ||
# spo page default get --debug "false" --verbose "false" --siteUrl "https://contoso.sharepoint.com/teams/Marketing" | ||
|
||
Date: 28/11/2024 | ||
|
||
## Home (2f6cf80c-e4cc-4fcc-a424-8d36770ac481) | ||
|
||
Property | Value | ||
---------|------- | ||
CheckInComment | | ||
CheckOutType | 2 | ||
ContentTag | {2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1 | ||
CustomizedPageStatus | 1 | ||
ETag | "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4" | ||
Exists | true | ||
ExistsAllowThrowForPolicyFailures | true | ||
ExistsWithException | true | ||
IrmEnabled | false | ||
Length | 805 | ||
Level | 1 | ||
LinkingUrl | | ||
MajorVersion | 1 | ||
MinorVersion | 0 | ||
Name | Home.aspx | ||
ServerRelativeUrl | /teams/Marketing/SitePages/Home.aspx | ||
TimeCreated | 2023-05-21T00:37:33Z | ||
TimeLastModified | 2023-05-21T00:37:33Z | ||
Title | Home | ||
UIVersion | 512 | ||
UIVersionLabel | 1.0 | ||
UniqueId | 2f6cf80c-e4cc-4fcc-a424-8d36770ac481 | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import { z } from 'zod'; | ||
import auth from '../../../../Auth.js'; | ||
import { cli } from '../../../../cli/cli.js'; | ||
import { CommandInfo } from '../../../../cli/CommandInfo.js'; | ||
import { Logger } from '../../../../cli/Logger.js'; | ||
import { CommandError } from '../../../../Command.js'; | ||
import request from '../../../../request.js'; | ||
import { telemetry } from '../../../../telemetry.js'; | ||
import { pid } from '../../../../utils/pid.js'; | ||
import { session } from '../../../../utils/session.js'; | ||
import { sinonUtil } from '../../../../utils/sinonUtil.js'; | ||
import commands from '../../commands.js'; | ||
import command from './page-default-get.js'; | ||
import { urlUtil } from '../../../../utils/urlUtil.js'; | ||
import { formatting } from '../../../../utils/formatting.js'; | ||
import { pageListItemMock } from './page-get.mock.js'; | ||
|
||
describe(commands.PAGE_DEFAULT_GET, () => { | ||
let log: string[]; | ||
let logger: Logger; | ||
let loggerLogSpy: sinon.SinonSpy; | ||
let commandInfo: CommandInfo; | ||
let commandOptionsSchema: z.ZodTypeAny; | ||
|
||
const siteUrl = 'https://contoso.sharepoint.com/sites/Marketing'; | ||
const serverRelativeUrl = urlUtil.getServerRelativeSiteUrl(siteUrl); | ||
const page = { | ||
WelcomePage: '/SitePages/Home.aspx' | ||
}; | ||
|
||
before(() => { | ||
sinon.stub(auth, 'restoreAuth').resolves(); | ||
sinon.stub(telemetry, 'trackEvent').returns(); | ||
sinon.stub(pid, 'getProcessName').returns(''); | ||
sinon.stub(session, 'getId').returns(''); | ||
auth.connection.active = true; | ||
commandInfo = cli.getCommandInfo(command); | ||
commandOptionsSchema = commandInfo.command.getSchemaToParse()!; | ||
}); | ||
|
||
beforeEach(() => { | ||
log = []; | ||
logger = { | ||
log: async (msg: string) => { | ||
log.push(msg); | ||
}, | ||
logRaw: async (msg: string) => { | ||
log.push(msg); | ||
}, | ||
logToStderr: async (msg: string) => { | ||
log.push(msg); | ||
} | ||
}; | ||
loggerLogSpy = sinon.spy(logger, 'log'); | ||
}); | ||
|
||
afterEach(() => { | ||
sinonUtil.restore([ | ||
request.get | ||
]); | ||
}); | ||
|
||
after(() => { | ||
sinon.restore(); | ||
auth.connection.active = false; | ||
}); | ||
|
||
it('has correct name', () => { | ||
assert.strictEqual(command.name, commands.PAGE_DEFAULT_GET); | ||
}); | ||
|
||
it('has a description', () => { | ||
assert.notStrictEqual(command.description, null); | ||
}); | ||
|
||
it('fails validation if siteUrl is not a valid SharePoint URL', async () => { | ||
const actual = commandOptionsSchema.safeParse({ siteUrl: 'foo' }); | ||
assert.strictEqual(actual.success, false); | ||
}); | ||
|
||
it('passes validation when the siteUrl is a valid SharePoint URL and name is specified', async () => { | ||
const actual = commandOptionsSchema.safeParse({ siteUrl: siteUrl }); | ||
assert.strictEqual(actual.success, true); | ||
}); | ||
|
||
it('gets the home page details for a specific site', async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if (opts.url === `${siteUrl}/_api/Web/RootFolder?$select=WelcomePage`) { | ||
return page; | ||
} | ||
|
||
if (opts.url === `${siteUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${serverRelativeUrl}/${formatting.encodeQueryParameter(page.WelcomePage)}')?$expand=ListItemAllFields/ClientSideApplicationId,ListItemAllFields/PageLayoutType,ListItemAllFields/CommentsDisabled`) { | ||
return pageListItemMock; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { options: { siteUrl: siteUrl, verbose: true } }); | ||
assert(loggerLogSpy.calledWith({ ...pageListItemMock })); | ||
}); | ||
|
||
it('correctly handles API error', async () => { | ||
const errorMessage = 'The file /sites/Marketing/SitePages/Welcome.aspx does not exist.'; | ||
|
||
sinon.stub(request, 'get').rejects({ | ||
error: { | ||
'odata.error': { | ||
message: { | ||
lang: 'en-US', | ||
value: errorMessage | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await assert.rejects(command.action(logger, { options: { siteUrl: siteUrl } }), | ||
new CommandError(errorMessage)); | ||
}); | ||
}); |
Oops, something went wrong.