Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/Sites/Sites/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ directive:
- where:
verb: Get
subject: ^Site$
variant: ^Get$|^GetViaIdentity$|^List$|^Get3$|^GetViaIdentity3$|^List2$
variant: ^Get1$|^Get4$|^GetViaIdentity1$|^GetViaIdentity4$|^List$|^List2$
set:
subject: SubSite
- where:
Expand All @@ -64,10 +64,16 @@ directive:
variant: ^Create$|^CreateExpanded$|^CreateViaIdentity$|^CreateViaIdentityExpanded$|^Create2$|^CreateExpanded2$|^CreateViaIdentity1$|^CreateViaIdentityExpanded1$
set:
subject: SubSite
- where:
verb: Remove
subject: ^Site$
variant: ^Delete$|^DeleteViaIdentity$|^Delete2$|^DeleteViaIdentity2$
set:
subject: SubSite
- where:
verb: Get
subject: (^Site$)
variant: ^Get2$|^GetViaIdentity2$|^Get5$|^GetViaIdentity5$
variant: ^Get$|^GetViaIdentity$|^Get3$|^GetViaIdentity3$
set:
subject: $1ByPath
- where:
Expand Down
11 changes: 11 additions & 0 deletions src/Sites/Sites/test/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ClientId": "56db239f-b87c-4dc0-9d9b-2ec0318e4ad9",
"TenantId": "61fcf17f-000c-4ab8-a4dc-9e92405fc737",
"Users": [
{
"Id": "85d17c69-6789-47c7-bf10-ad08ab4cd8da",
"DisplayName": "John Doe",
"Mail": "johndoe@testtenant.onmicrosoft.com"
}
]
}
1 change: 0 additions & 1 deletion src/Sites/Sites/test/loadEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ $env = @{}
if (Test-Path -Path $envFilePath) {
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json
$PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant}
}
101 changes: 101 additions & 0 deletions src/Sites/Sites/test/v1.0-beta/Get-MgSite.Recording.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"Get-MgSite+[NoContext]+ShouldGetACollectionOfSites+$GET+https://graph.microsoft.com/beta/sites+1": {
"Request": {
"Method": "GET",
"RequestUri": "https://graph.microsoft.com/beta/sites",
"Content": null,
"Headers": {
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
"FeatureFlag": [ "00000047" ],
"Cache-Control": [ "no-store, no-cache" ],
"Authorization": [ "[Filtered]" ],
"Accept-Encoding": [ "gzip" ]
},
"ContentHeaders": {
}
},
"Response": {
"StatusCode": 200,
"Headers": {
"Date": [ "Mon, 08 Mar 2021 20:30:41 GMT" ],
"Cache-Control": [ "no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "5e29db13-a2c1-46b6-ad7e-d44e41a09d73" ],
"client-request-id": [ "5e29db13-a2c1-46b6-ad7e-d44e41a09d73" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006AF8\"}}" ],
"OData-Version": [ "4.0" ]
},
"ContentHeaders": {
},
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites\",\"value\":[]}"
}
},
"Get-MgSite+[NoContext]+ShouldGetASingleSite+$GET+https://graph.microsoft.com/beta/sites/root+1": {
"Request": {
"Method": "GET",
"RequestUri": "https://graph.microsoft.com/beta/sites/root",
"Content": null,
"Headers": {
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
"FeatureFlag": [ "00000047" ],
"Cache-Control": [ "no-store, no-cache" ],
"Authorization": [ "[Filtered]" ],
"Accept-Encoding": [ "gzip" ]
},
"ContentHeaders": {
}
},
"Response": {
"StatusCode": 200,
"Headers": {
"Date": [ "Mon, 08 Mar 2021 20:30:41 GMT" ],
"Cache-Control": [ "no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "5461e4e9-e1cf-4966-8171-103bd1812b00" ],
"client-request-id": [ "5461e4e9-e1cf-4966-8171-103bd1812b00" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006B0E\"}}" ],
"OData-Version": [ "4.0" ]
},
"ContentHeaders": {
},
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites/$entity\",\"createdDateTime\":\"2020-02-13T19:06:48.53Z\",\"description\":\"\",\"id\":\"dummyRootId\",\"lastModifiedDateTime\":\"2021-02-26T16:43:51Z\",\"name\":\"\",\"webUrl\":\"https://dummyroot.sharepoint.com\",\"displayName\":\"Communication site\",\"root\":{},\"siteCollection\":{\"hostname\":\"dummyroot.sharepoint.com\"}}"
}
},
"Get-MgSite+[NoContext]+ShouldGetASingleSiteViaInputObject+$GET+https://graph.microsoft.com/beta/sites/root+1": {
"Request": {
"Method": "GET",
"RequestUri": "https://graph.microsoft.com/beta/sites/root",
"Content": null,
"Headers": {
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
"FeatureFlag": [ "00000047" ],
"Cache-Control": [ "no-store, no-cache" ],
"Authorization": [ "[Filtered]" ],
"Accept-Encoding": [ "gzip" ]
},
"ContentHeaders": {
}
},
"Response": {
"StatusCode": 200,
"Headers": {
"Date": [ "Mon, 08 Mar 2021 20:30:42 GMT" ],
"Cache-Control": [ "no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "93a5e3d0-23e4-44bf-9bf5-368ce6c83e5c" ],
"client-request-id": [ "93a5e3d0-23e4-44bf-9bf5-368ce6c83e5c" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006AFC\"}}" ],
"OData-Version": [ "4.0" ]
},
"ContentHeaders": {
},
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites/$entity\",\"createdDateTime\":\"2020-02-13T19:06:48.53Z\",\"description\":\"\",\"id\":\"dummyRootId\",\"lastModifiedDateTime\":\"2021-02-26T16:43:51Z\",\"name\":\"\",\"webUrl\":\"https://dummyroot.sharepoint.com\",\"displayName\":\"Communication site\",\"root\":{},\"siteCollection\":{\"hostname\":\"dummyroot.sharepoint.com\"}}"
}
}
}
70 changes: 53 additions & 17 deletions src/Sites/Sites/test/v1.0-beta/Get-MgSite.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,62 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSite.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
BeforeAll {
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
# Set test mode to playback.
$TestMode = 'playback'
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSite.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName

Select-MgProfile 'beta'
}
. ($mockingPath | Select-Object -First 1).FullName

Describe 'Get-MgSite' {
It 'List3' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
BeforeAll {
$Mock.PushDescription('Get-MgSite')
}

Context 'List3'{
It 'ShouldGetACollectionOfSites' {
$Mock.PushScenario('ShouldGetACollectionOfSites')

It 'Get4' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
# The API currently returns an empy collection.
$Sites = Get-MgSite
$Sites | Should -HaveCount 0
}
}

It 'GetViaIdentity4' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
Context 'Get5'{
It 'ShouldGetASingleSite' {
$Mock.PushScenario('ShouldGetASingleSite')

$SiteId = 'root'
$Site = Get-MgSite -SiteId $SiteId
$Site | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite'
$Site | Should -HaveCount 1
$Site.Id | Should -Be 'dummyRootId'
$Site.SiteCollection.HostName | Should -Be 'dummyroot.sharepoint.com'
$Site.AdditionalProperties | Should -HaveCount 1
}
}

Context 'GetViaIdentity5'{
It 'ShouldGetASingleSiteViaInputObject' {
$Mock.PushScenario('ShouldGetASingleSiteViaInputObject')

$SiteId = 'root'
$Site = Get-MgSite -InputObject @{ SiteId = $SiteId }
$Site | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite'
$Site | Should -HaveCount 1
$Site.Id | Should -Be 'dummyRootId'
$Site.SiteCollection.HostName | Should -Be 'dummyroot.sharepoint.com'
$Site.AdditionalProperties | Should -HaveCount 1
}
}
}
66 changes: 66 additions & 0 deletions src/Sites/Sites/test/v1.0-beta/Get-MgSiteByPath.Recording.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"Get-MgSiteByPath+[NoContext]+ShouldFailToGetSiteByPath+$GET+https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)+1": {
"Request": {
"Method": "GET",
"RequestUri": "https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)",
"Content": null,
"Headers": {
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
"FeatureFlag": [ "00000047" ],
"Cache-Control": [ "no-store, no-cache" ],
"Authorization": [ "[Filtered]" ],
"Accept-Encoding": [ "gzip" ]
},
"ContentHeaders": {
}
},
"Response": {
"StatusCode": 400,
"Headers": {
"Date": [ "Mon, 08 Mar 2021 21:12:55 GMT" ],
"Cache-Control": [ "no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d" ],
"client-request-id": [ "b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF000031CA\"}}" ]
},
"ContentHeaders": {
},
"Content": "{\r\n \"error\": {\r\n \"code\": \"invalidRequest\",\r\n \"message\": \"Invalid request\",\r\n \"innerError\": {\r\n \"date\": \"2021-03-08T21:12:55\",\r\n \"request-id\": \"b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d\",\r\n \"client-request-id\": \"b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d\"\r\n }\r\n }\r\n}"
}
},
"Get-MgSiteByPath+[NoContext]+ShouldFailToGetSiteByPathViaInputObject+$GET+https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)+1": {
"Request": {
"Method": "GET",
"RequestUri": "https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)",
"Content": null,
"Headers": {
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
"FeatureFlag": [ "00000047" ],
"Cache-Control": [ "no-store, no-cache" ],
"Authorization": [ "[Filtered]" ],
"Accept-Encoding": [ "gzip" ]
},
"ContentHeaders": {
}
},
"Response": {
"StatusCode": 400,
"Headers": {
"Date": [ "Mon, 08 Mar 2021 21:12:56 GMT" ],
"Cache-Control": [ "no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "99d67929-240d-4173-81b4-935f6dfe28b4" ],
"client-request-id": [ "99d67929-240d-4173-81b4-935f6dfe28b4" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF000031CD\"}}" ]
},
"ContentHeaders": {
},
"Content": "{\r\n \"error\": {\r\n \"code\": \"invalidRequest\",\r\n \"message\": \"Invalid request\",\r\n \"innerError\": {\r\n \"date\": \"2021-03-08T21:12:56\",\r\n \"request-id\": \"99d67929-240d-4173-81b4-935f6dfe28b4\",\r\n \"client-request-id\": \"99d67929-240d-4173-81b4-935f6dfe28b4\"\r\n }\r\n }\r\n}"
}
}
}
53 changes: 38 additions & 15 deletions src/Sites/Sites/test/v1.0-beta/Get-MgSiteByPath.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSiteByPath.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
BeforeAll {
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
# Set test mode to playback.
$TestMode = 'playback'
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSiteByPath.Recording.json'
$currentPath = $PSScriptRoot

while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName

Select-MgProfile 'beta'
}
. ($mockingPath | Select-Object -First 1).FullName

# Skip because /sites/{site-id}/microsoft.graph.getByPath(path='{path}') returns a 400 and is not documented.
Describe 'Get-MgSiteByPath' {
It 'Get5' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
BeforeAll {
$Mock.PushDescription('Get-MgSiteByPath')
}

Context 'Get' {
It 'ShouldFailToGetSiteByPath' {
$Mock.PushScenario('ShouldFailToGetSiteByPath')

$SiteId = "root"
{ Get-MgSiteByPath -SiteId $SiteId -Path "randomPath" -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_Get' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'
}
}

It 'GetViaIdentity5' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
Context 'GetViaIdentity' {
It 'ShouldFailToGetSiteByPathViaInputObject' {
$Mock.PushScenario('ShouldFailToGetSiteByPathViaInputObject')

$SiteId = "root"
{ Get-MgSiteByPath -InputObject @{ SiteId = $SiteId; Path = "randomPath" } -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_GetViaIdentity' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'

}
}
}
Loading