Skip to content

Commit 4c4a90f

Browse files
committed
feat: enhance license detection tests for Premium P2 and related licenses
1 parent f79102a commit 4c4a90f

1 file changed

Lines changed: 228 additions & 8 deletions

File tree

Tests/Public/Test-IntunePrerequisites.Tests.ps1

Lines changed: 228 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ Describe 'Test-IntunePrerequisites' {
4646
return @{
4747
value = @(
4848
@{
49-
skuPartNumber = 'ENTERPRISEPACK'
50-
servicePlans = @(
49+
capabilityStatus = 'Enabled'
50+
skuPartNumber = 'ENTERPRISEPACK'
51+
servicePlans = @(
5152
@{
5253
servicePlanName = 'INTUNE_A'
5354
provisioningStatus = 'Success'
@@ -135,7 +136,8 @@ Describe 'Test-IntunePrerequisites' {
135136
elseif ($Uri -like '*subscribedSkus*') {
136137
return @{
137138
value = @(@{
138-
servicePlans = @(@{
139+
capabilityStatus = 'Enabled'
140+
servicePlans = @(@{
139141
servicePlanName = 'INTUNE_A'
140142
provisioningStatus = 'Success'
141143
})
@@ -157,7 +159,8 @@ Describe 'Test-IntunePrerequisites' {
157159
elseif ($Uri -like '*subscribedSkus*') {
158160
return @{
159161
value = @(@{
160-
servicePlans = @(@{
162+
capabilityStatus = 'Enabled'
163+
servicePlans = @(@{
161164
servicePlanName = 'INTUNE_EDU'
162165
provisioningStatus = 'Success'
163166
})
@@ -179,7 +182,8 @@ Describe 'Test-IntunePrerequisites' {
179182
elseif ($Uri -like '*subscribedSkus*') {
180183
return @{
181184
value = @(@{
182-
servicePlans = @(@{
185+
capabilityStatus = 'Enabled'
186+
servicePlans = @(@{
183187
servicePlanName = 'EMSPREMIUM'
184188
provisioningStatus = 'Success'
185189
})
@@ -201,7 +205,8 @@ Describe 'Test-IntunePrerequisites' {
201205
elseif ($Uri -like '*subscribedSkus*') {
202206
return @{
203207
value = @(@{
204-
servicePlans = @(@{
208+
capabilityStatus = 'Enabled'
209+
servicePlans = @(@{
205210
servicePlanName = 'SOME_OTHER_LICENSE'
206211
provisioningStatus = 'Success'
207212
})
@@ -223,7 +228,8 @@ Describe 'Test-IntunePrerequisites' {
223228
elseif ($Uri -like '*subscribedSkus*') {
224229
return @{
225230
value = @(@{
226-
servicePlans = @(@{
231+
capabilityStatus = 'Enabled'
232+
servicePlans = @(@{
227233
servicePlanName = 'INTUNE_A'
228234
provisioningStatus = 'Pending'
229235
})
@@ -247,7 +253,8 @@ Describe 'Test-IntunePrerequisites' {
247253
elseif ($Uri -like '*subscribedSkus*') {
248254
return @{
249255
value = @(@{
250-
servicePlans = @(@{
256+
capabilityStatus = 'Enabled'
257+
servicePlans = @(@{
251258
servicePlanName = 'INTUNE_A'
252259
provisioningStatus = 'Success'
253260
})
@@ -297,6 +304,219 @@ Describe 'Test-IntunePrerequisites' {
297304
}
298305
}
299306

307+
Context 'Premium P2 License Detection' {
308+
BeforeAll {
309+
Mock Get-MgContext {
310+
return @{
311+
Scopes = @(
312+
'DeviceManagementConfiguration.ReadWrite.All',
313+
'DeviceManagementServiceConfig.ReadWrite.All',
314+
'DeviceManagementManagedDevices.ReadWrite.All',
315+
'DeviceManagementScripts.ReadWrite.All',
316+
'DeviceManagementApps.ReadWrite.All',
317+
'Group.ReadWrite.All',
318+
'Policy.Read.All',
319+
'Policy.ReadWrite.ConditionalAccess',
320+
'Application.Read.All',
321+
'Directory.ReadWrite.All',
322+
'LicenseAssignment.Read.All',
323+
'Organization.Read.All'
324+
)
325+
}
326+
} -ModuleName IntuneHydrationKit
327+
}
328+
329+
It 'Should detect AAD_PREMIUM_P2 license' {
330+
Mock Invoke-MgGraphRequest {
331+
param($Method, $Uri)
332+
333+
if ($Uri -like '*organization*') {
334+
return @{ value = @(@{ displayName = 'Test' }) }
335+
}
336+
elseif ($Uri -like '*subscribedSkus*') {
337+
return @{
338+
value = @(@{
339+
capabilityStatus = 'Enabled'
340+
skuPartNumber = 'AAD_PREMIUM_P2'
341+
servicePlans = @(
342+
@{
343+
servicePlanName = 'INTUNE_A'
344+
provisioningStatus = 'Success'
345+
},
346+
@{
347+
servicePlanName = 'AAD_PREMIUM_P2'
348+
provisioningStatus = 'Success'
349+
}
350+
)
351+
})
352+
}
353+
}
354+
} -ModuleName IntuneHydrationKit
355+
356+
{ Test-IntunePrerequisites } | Should -Not -Throw
357+
}
358+
359+
It 'Should detect Microsoft 365 E5 license (SPE_E5)' {
360+
Mock Invoke-MgGraphRequest {
361+
param($Method, $Uri)
362+
363+
if ($Uri -like '*organization*') {
364+
return @{ value = @(@{ displayName = 'Test' }) }
365+
}
366+
elseif ($Uri -like '*subscribedSkus*') {
367+
return @{
368+
value = @(@{
369+
capabilityStatus = 'Enabled'
370+
skuPartNumber = 'SPE_E5'
371+
servicePlans = @(
372+
@{
373+
servicePlanName = 'INTUNE_A'
374+
provisioningStatus = 'Success'
375+
},
376+
@{
377+
servicePlanName = 'SPE_E5'
378+
provisioningStatus = 'Success'
379+
}
380+
)
381+
})
382+
}
383+
}
384+
} -ModuleName IntuneHydrationKit
385+
386+
{ Test-IntunePrerequisites } | Should -Not -Throw
387+
}
388+
389+
It 'Should detect Microsoft 365 Education A5 license' {
390+
Mock Invoke-MgGraphRequest {
391+
param($Method, $Uri)
392+
393+
if ($Uri -like '*organization*') {
394+
return @{ value = @(@{ displayName = 'Test' }) }
395+
}
396+
elseif ($Uri -like '*subscribedSkus*') {
397+
return @{
398+
value = @(@{
399+
capabilityStatus = 'Enabled'
400+
skuPartNumber = 'M365EDU_A5_FACULTY'
401+
servicePlans = @(
402+
@{
403+
servicePlanName = 'INTUNE_A'
404+
provisioningStatus = 'Success'
405+
},
406+
@{
407+
servicePlanName = 'M365EDU_A5_FACULTY'
408+
provisioningStatus = 'Success'
409+
}
410+
)
411+
})
412+
}
413+
}
414+
} -ModuleName IntuneHydrationKit
415+
416+
{ Test-IntunePrerequisites } | Should -Not -Throw
417+
}
418+
419+
It 'Should detect Identity & Threat Protection license' {
420+
Mock Invoke-MgGraphRequest {
421+
param($Method, $Uri)
422+
423+
if ($Uri -like '*organization*') {
424+
return @{ value = @(@{ displayName = 'Test' }) }
425+
}
426+
elseif ($Uri -like '*subscribedSkus*') {
427+
return @{
428+
value = @(@{
429+
capabilityStatus = 'Enabled'
430+
skuPartNumber = 'IDENTITY_THREAT_PROTECTION'
431+
servicePlans = @(
432+
@{
433+
servicePlanName = 'INTUNE_A'
434+
provisioningStatus = 'Success'
435+
},
436+
@{
437+
servicePlanName = 'IDENTITY_THREAT_PROTECTION'
438+
provisioningStatus = 'Success'
439+
}
440+
)
441+
})
442+
}
443+
}
444+
} -ModuleName IntuneHydrationKit
445+
446+
{ Test-IntunePrerequisites } | Should -Not -Throw
447+
}
448+
449+
It 'Should skip disabled SKUs when checking for P2 licenses' {
450+
Mock Invoke-MgGraphRequest {
451+
param($Method, $Uri)
452+
453+
if ($Uri -like '*organization*') {
454+
return @{ value = @(@{ displayName = 'Test' }) }
455+
}
456+
elseif ($Uri -like '*subscribedSkus*') {
457+
return @{
458+
value = @(
459+
@{
460+
capabilityStatus = 'Disabled'
461+
skuPartNumber = 'AAD_PREMIUM_P2'
462+
servicePlans = @(
463+
@{
464+
servicePlanName = 'AAD_PREMIUM_P2'
465+
provisioningStatus = 'Success'
466+
}
467+
)
468+
},
469+
@{
470+
capabilityStatus = 'Enabled'
471+
skuPartNumber = 'ENTERPRISEPACK'
472+
servicePlans = @(
473+
@{
474+
servicePlanName = 'INTUNE_A'
475+
provisioningStatus = 'Success'
476+
}
477+
)
478+
}
479+
)
480+
}
481+
}
482+
} -ModuleName IntuneHydrationKit
483+
484+
# Should not throw but should warn about missing P2
485+
{ Test-IntunePrerequisites -WarningAction SilentlyContinue } | Should -Not -Throw
486+
}
487+
488+
It 'Should warn when Premium P2 is not detected' {
489+
Mock Invoke-MgGraphRequest {
490+
param($Method, $Uri)
491+
492+
if ($Uri -like '*organization*') {
493+
return @{ value = @(@{ displayName = 'Test' }) }
494+
}
495+
elseif ($Uri -like '*subscribedSkus*') {
496+
return @{
497+
value = @(@{
498+
capabilityStatus = 'Enabled'
499+
skuPartNumber = 'ENTERPRISEPACK'
500+
servicePlans = @(@{
501+
servicePlanName = 'INTUNE_A'
502+
provisioningStatus = 'Success'
503+
})
504+
})
505+
}
506+
}
507+
} -ModuleName IntuneHydrationKit
508+
509+
# Capture warnings
510+
$warnings = @()
511+
Test-IntunePrerequisites -WarningVariable warnings -WarningAction SilentlyContinue
512+
513+
# Check that the warning was generated (first warning message)
514+
$warnings[0] | Should -BeLike '*No Azure AD Premium P2 license found*'
515+
# Verify the second warning about affected policies was also generated
516+
$warnings[1] | Should -BeLike '*Affected policies*'
517+
}
518+
}
519+
300520
Context 'API Error Handling' {
301521
BeforeAll {
302522
Mock Get-MgContext {

0 commit comments

Comments
 (0)