Skip to content

Commit 53a32b3

Browse files
authored
Fix broken commands in Sites module. (#574)
* Add directive to fix broken command in Sites module. * Replace AutoREST's loadenv.ps1 with ours when running tests.
1 parent 90838a0 commit 53a32b3

17 files changed

+879
-101
lines changed

src/Sites/Sites/readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ directive:
4949
- where:
5050
verb: Get
5151
subject: ^Site$
52-
variant: ^Get$|^GetViaIdentity$|^List$|^Get3$|^GetViaIdentity3$|^List2$
52+
variant: ^Get1$|^Get4$|^GetViaIdentity1$|^GetViaIdentity4$|^List$|^List2$
5353
set:
5454
subject: SubSite
5555
- where:
@@ -64,10 +64,16 @@ directive:
6464
variant: ^Create$|^CreateExpanded$|^CreateViaIdentity$|^CreateViaIdentityExpanded$|^Create2$|^CreateExpanded2$|^CreateViaIdentity1$|^CreateViaIdentityExpanded1$
6565
set:
6666
subject: SubSite
67+
- where:
68+
verb: Remove
69+
subject: ^Site$
70+
variant: ^Delete$|^DeleteViaIdentity$|^Delete2$|^DeleteViaIdentity2$
71+
set:
72+
subject: SubSite
6773
- where:
6874
verb: Get
6975
subject: (^Site$)
70-
variant: ^Get2$|^GetViaIdentity2$|^Get5$|^GetViaIdentity5$
76+
variant: ^Get$|^GetViaIdentity$|^Get3$|^GetViaIdentity3$
7177
set:
7278
subject: $1ByPath
7379
- where:

src/Sites/Sites/test/env.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ClientId": "56db239f-b87c-4dc0-9d9b-2ec0318e4ad9",
3+
"TenantId": "61fcf17f-000c-4ab8-a4dc-9e92405fc737",
4+
"Users": [
5+
{
6+
"Id": "85d17c69-6789-47c7-bf10-ad08ab4cd8da",
7+
"DisplayName": "John Doe",
8+
9+
}
10+
]
11+
}

src/Sites/Sites/test/loadEnv.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ $env = @{}
2525
if (Test-Path -Path $envFilePath) {
2626
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json
2727
$PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant}
28-
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"Get-MgSite+[NoContext]+ShouldGetACollectionOfSites+$GET+https://graph.microsoft.com/beta/sites+1": {
3+
"Request": {
4+
"Method": "GET",
5+
"RequestUri": "https://graph.microsoft.com/beta/sites",
6+
"Content": null,
7+
"Headers": {
8+
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
9+
"FeatureFlag": [ "00000047" ],
10+
"Cache-Control": [ "no-store, no-cache" ],
11+
"Authorization": [ "[Filtered]" ],
12+
"Accept-Encoding": [ "gzip" ]
13+
},
14+
"ContentHeaders": {
15+
}
16+
},
17+
"Response": {
18+
"StatusCode": 200,
19+
"Headers": {
20+
"Date": [ "Mon, 08 Mar 2021 20:30:41 GMT" ],
21+
"Cache-Control": [ "no-cache" ],
22+
"Transfer-Encoding": [ "chunked" ],
23+
"Vary": [ "Accept-Encoding" ],
24+
"Strict-Transport-Security": [ "max-age=31536000" ],
25+
"request-id": [ "5e29db13-a2c1-46b6-ad7e-d44e41a09d73" ],
26+
"client-request-id": [ "5e29db13-a2c1-46b6-ad7e-d44e41a09d73" ],
27+
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006AF8\"}}" ],
28+
"OData-Version": [ "4.0" ]
29+
},
30+
"ContentHeaders": {
31+
},
32+
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites\",\"value\":[]}"
33+
}
34+
},
35+
"Get-MgSite+[NoContext]+ShouldGetASingleSite+$GET+https://graph.microsoft.com/beta/sites/root+1": {
36+
"Request": {
37+
"Method": "GET",
38+
"RequestUri": "https://graph.microsoft.com/beta/sites/root",
39+
"Content": null,
40+
"Headers": {
41+
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
42+
"FeatureFlag": [ "00000047" ],
43+
"Cache-Control": [ "no-store, no-cache" ],
44+
"Authorization": [ "[Filtered]" ],
45+
"Accept-Encoding": [ "gzip" ]
46+
},
47+
"ContentHeaders": {
48+
}
49+
},
50+
"Response": {
51+
"StatusCode": 200,
52+
"Headers": {
53+
"Date": [ "Mon, 08 Mar 2021 20:30:41 GMT" ],
54+
"Cache-Control": [ "no-cache" ],
55+
"Transfer-Encoding": [ "chunked" ],
56+
"Vary": [ "Accept-Encoding" ],
57+
"Strict-Transport-Security": [ "max-age=31536000" ],
58+
"request-id": [ "5461e4e9-e1cf-4966-8171-103bd1812b00" ],
59+
"client-request-id": [ "5461e4e9-e1cf-4966-8171-103bd1812b00" ],
60+
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006B0E\"}}" ],
61+
"OData-Version": [ "4.0" ]
62+
},
63+
"ContentHeaders": {
64+
},
65+
"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\"}}"
66+
}
67+
},
68+
"Get-MgSite+[NoContext]+ShouldGetASingleSiteViaInputObject+$GET+https://graph.microsoft.com/beta/sites/root+1": {
69+
"Request": {
70+
"Method": "GET",
71+
"RequestUri": "https://graph.microsoft.com/beta/sites/root",
72+
"Content": null,
73+
"Headers": {
74+
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
75+
"FeatureFlag": [ "00000047" ],
76+
"Cache-Control": [ "no-store, no-cache" ],
77+
"Authorization": [ "[Filtered]" ],
78+
"Accept-Encoding": [ "gzip" ]
79+
},
80+
"ContentHeaders": {
81+
}
82+
},
83+
"Response": {
84+
"StatusCode": 200,
85+
"Headers": {
86+
"Date": [ "Mon, 08 Mar 2021 20:30:42 GMT" ],
87+
"Cache-Control": [ "no-cache" ],
88+
"Transfer-Encoding": [ "chunked" ],
89+
"Vary": [ "Accept-Encoding" ],
90+
"Strict-Transport-Security": [ "max-age=31536000" ],
91+
"request-id": [ "93a5e3d0-23e4-44bf-9bf5-368ce6c83e5c" ],
92+
"client-request-id": [ "93a5e3d0-23e4-44bf-9bf5-368ce6c83e5c" ],
93+
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"MW1PEPF00006AFC\"}}" ],
94+
"OData-Version": [ "4.0" ]
95+
},
96+
"ContentHeaders": {
97+
},
98+
"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\"}}"
99+
}
100+
}
101+
}
Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,62 @@
1-
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
2-
if (-Not (Test-Path -Path $loadEnvPath)) {
3-
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
4-
}
5-
. ($loadEnvPath)
6-
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSite.Recording.json'
7-
$currentPath = $PSScriptRoot
8-
while(-not $mockingPath) {
9-
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
10-
$currentPath = Split-Path -Path $currentPath -Parent
1+
BeforeAll {
2+
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
3+
if (-Not (Test-Path -Path $loadEnvPath)) {
4+
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
5+
}
6+
. ($loadEnvPath)
7+
# Set test mode to playback.
8+
$TestMode = 'playback'
9+
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSite.Recording.json'
10+
$currentPath = $PSScriptRoot
11+
while(-not $mockingPath) {
12+
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
13+
$currentPath = Split-Path -Path $currentPath -Parent
14+
}
15+
. ($mockingPath | Select-Object -First 1).FullName
16+
17+
Select-MgProfile 'beta'
1118
}
12-
. ($mockingPath | Select-Object -First 1).FullName
1319

1420
Describe 'Get-MgSite' {
15-
It 'List3' -skip {
16-
{ throw [System.NotImplementedException] } | Should -Not -Throw
21+
BeforeAll {
22+
$Mock.PushDescription('Get-MgSite')
1723
}
24+
25+
Context 'List3'{
26+
It 'ShouldGetACollectionOfSites' {
27+
$Mock.PushScenario('ShouldGetACollectionOfSites')
1828

19-
It 'Get4' -skip {
20-
{ throw [System.NotImplementedException] } | Should -Not -Throw
29+
# The API currently returns an empy collection.
30+
$Sites = Get-MgSite
31+
$Sites | Should -HaveCount 0
32+
}
2133
}
2234

23-
It 'GetViaIdentity4' -skip {
24-
{ throw [System.NotImplementedException] } | Should -Not -Throw
35+
Context 'Get5'{
36+
It 'ShouldGetASingleSite' {
37+
$Mock.PushScenario('ShouldGetASingleSite')
38+
39+
$SiteId = 'root'
40+
$Site = Get-MgSite -SiteId $SiteId
41+
$Site | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite'
42+
$Site | Should -HaveCount 1
43+
$Site.Id | Should -Be 'dummyRootId'
44+
$Site.SiteCollection.HostName | Should -Be 'dummyroot.sharepoint.com'
45+
$Site.AdditionalProperties | Should -HaveCount 1
46+
}
47+
}
48+
49+
Context 'GetViaIdentity5'{
50+
It 'ShouldGetASingleSiteViaInputObject' {
51+
$Mock.PushScenario('ShouldGetASingleSiteViaInputObject')
52+
53+
$SiteId = 'root'
54+
$Site = Get-MgSite -InputObject @{ SiteId = $SiteId }
55+
$Site | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite'
56+
$Site | Should -HaveCount 1
57+
$Site.Id | Should -Be 'dummyRootId'
58+
$Site.SiteCollection.HostName | Should -Be 'dummyroot.sharepoint.com'
59+
$Site.AdditionalProperties | Should -HaveCount 1
60+
}
2561
}
2662
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"Get-MgSiteByPath+[NoContext]+ShouldFailToGetSiteByPath+$GET+https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)+1": {
3+
"Request": {
4+
"Method": "GET",
5+
"RequestUri": "https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)",
6+
"Content": null,
7+
"Headers": {
8+
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
9+
"FeatureFlag": [ "00000047" ],
10+
"Cache-Control": [ "no-store, no-cache" ],
11+
"Authorization": [ "[Filtered]" ],
12+
"Accept-Encoding": [ "gzip" ]
13+
},
14+
"ContentHeaders": {
15+
}
16+
},
17+
"Response": {
18+
"StatusCode": 400,
19+
"Headers": {
20+
"Date": [ "Mon, 08 Mar 2021 21:12:55 GMT" ],
21+
"Cache-Control": [ "no-cache" ],
22+
"Transfer-Encoding": [ "chunked" ],
23+
"Vary": [ "Accept-Encoding" ],
24+
"Strict-Transport-Security": [ "max-age=31536000" ],
25+
"request-id": [ "b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d" ],
26+
"client-request-id": [ "b981dfd2-ac5e-4292-a3bc-9e1a276e0e9d" ],
27+
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF000031CA\"}}" ]
28+
},
29+
"ContentHeaders": {
30+
},
31+
"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}"
32+
}
33+
},
34+
"Get-MgSiteByPath+[NoContext]+ShouldFailToGetSiteByPathViaInputObject+$GET+https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)+1": {
35+
"Request": {
36+
"Method": "GET",
37+
"RequestUri": "https://graph.microsoft.com/beta/sites/root/microsoft.graph.getByPath(path=\u0027randomPath\u0027)",
38+
"Content": null,
39+
"Headers": {
40+
"SdkVersion": [ "Graph-powershell-Microsoft.Graph.Authentication-1.4.0", "Graph-dotnet-1.20.1" ],
41+
"FeatureFlag": [ "00000047" ],
42+
"Cache-Control": [ "no-store, no-cache" ],
43+
"Authorization": [ "[Filtered]" ],
44+
"Accept-Encoding": [ "gzip" ]
45+
},
46+
"ContentHeaders": {
47+
}
48+
},
49+
"Response": {
50+
"StatusCode": 400,
51+
"Headers": {
52+
"Date": [ "Mon, 08 Mar 2021 21:12:56 GMT" ],
53+
"Cache-Control": [ "no-cache" ],
54+
"Transfer-Encoding": [ "chunked" ],
55+
"Vary": [ "Accept-Encoding" ],
56+
"Strict-Transport-Security": [ "max-age=31536000" ],
57+
"request-id": [ "99d67929-240d-4173-81b4-935f6dfe28b4" ],
58+
"client-request-id": [ "99d67929-240d-4173-81b4-935f6dfe28b4" ],
59+
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF000031CD\"}}" ]
60+
},
61+
"ContentHeaders": {
62+
},
63+
"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}"
64+
}
65+
}
66+
}
Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1-
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
2-
if (-Not (Test-Path -Path $loadEnvPath)) {
3-
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
4-
}
5-
. ($loadEnvPath)
6-
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSiteByPath.Recording.json'
7-
$currentPath = $PSScriptRoot
8-
while(-not $mockingPath) {
9-
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
10-
$currentPath = Split-Path -Path $currentPath -Parent
1+
BeforeAll {
2+
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
3+
if (-Not (Test-Path -Path $loadEnvPath)) {
4+
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
5+
}
6+
. ($loadEnvPath)
7+
# Set test mode to playback.
8+
$TestMode = 'playback'
9+
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-MgSiteByPath.Recording.json'
10+
$currentPath = $PSScriptRoot
11+
12+
while(-not $mockingPath) {
13+
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
14+
$currentPath = Split-Path -Path $currentPath -Parent
15+
}
16+
. ($mockingPath | Select-Object -First 1).FullName
17+
18+
Select-MgProfile 'beta'
1119
}
12-
. ($mockingPath | Select-Object -First 1).FullName
1320

21+
# Skip because /sites/{site-id}/microsoft.graph.getByPath(path='{path}') returns a 400 and is not documented.
1422
Describe 'Get-MgSiteByPath' {
15-
It 'Get5' -skip {
16-
{ throw [System.NotImplementedException] } | Should -Not -Throw
23+
BeforeAll {
24+
$Mock.PushDescription('Get-MgSiteByPath')
25+
}
26+
27+
Context 'Get' {
28+
It 'ShouldFailToGetSiteByPath' {
29+
$Mock.PushScenario('ShouldFailToGetSiteByPath')
30+
31+
$SiteId = "root"
32+
{ 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>'
33+
}
1734
}
1835

19-
It 'GetViaIdentity5' -skip {
20-
{ throw [System.NotImplementedException] } | Should -Not -Throw
36+
Context 'GetViaIdentity' {
37+
It 'ShouldFailToGetSiteByPathViaInputObject' {
38+
$Mock.PushScenario('ShouldFailToGetSiteByPathViaInputObject')
39+
40+
$SiteId = "root"
41+
{ 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>'
42+
43+
}
2144
}
2245
}

0 commit comments

Comments
 (0)