Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ambiguity of parameter sets in VSTeamUserEntitlement cmdlets #400

Merged
merged 3 commits into from
Jul 13, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 7.3.1

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/400) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:

- Fixes ambiguity of parameter sets in VSTeamUserEntitlement cmdlets [#393](https://github.com/DarqueWarrior/vsteam/issues/393)

## 7.3.0

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/396) from [Markus Blaschke](https://github.com/mblaschke) which included the following:
Expand Down
38 changes: 17 additions & 21 deletions Source/Public/Update-VSTeamUserEntitlement.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
function Update-VSTeamUserEntitlement {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'ByEmailLicenseOnly',
HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Update-VSTeamUserEntitlement')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'ByEmail',
HelpUri = 'https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Update-VSTeamUserEntitlement')]
param (
[Parameter(ParameterSetName = 'ByIdLicenseOnly', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByIdWithSource', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ById', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Alias('UserId')]
[string]$Id,

[Parameter(ParameterSetName = 'ByEmailLicenseOnly', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByEmailWithSource', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByEmail', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Alias('UserEmail')]
[string]$Email,

[Parameter(ParameterSetName = 'ByIdLicenseOnly', Mandatory = $true)]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailLicenseOnly', Mandatory = $true)]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[Parameter(ParameterSetName = 'ById', Mandatory = $false)]
[Parameter(ParameterSetName = 'ByEmail', Mandatory = $false)]
[ValidateSet('Advanced', 'EarlyAdopter', 'Express', 'None', 'Professional', 'StakeHolder')]
[string]$License,

[ValidateSet('account', 'auto', 'msdn', 'none', 'profile', 'trial')]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[Parameter(ParameterSetName = 'ById', Mandatory = $false)]
[Parameter(ParameterSetName = 'ByEmail')]
[string]$LicensingSource,

[ValidateSet('eligible', 'enterprise', 'none', 'platforms', 'premium', 'professional', 'testProfessional', 'ultimate')]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[Parameter(ParameterSetName = 'ById', Mandatory = $false)]
[Parameter(ParameterSetName = 'ByEmail')]
[string]$MSDNLicenseType,

[switch]$Force
Expand Down Expand Up @@ -54,9 +50,9 @@ function Update-VSTeamUserEntitlement {
$licenseSourceOriginal = $user.accessLevel.licensingSource
$msdnLicenseTypeOriginal = $user.accessLevel.msdnLicenseType

$newLicenseType = if ($License) { $License } else { $licenseTypeOriginal }
$newLicenseSource = if ($LicensingSource) { $LicensingSource } else { $licenseSourceOriginal }
$newMSDNLicenseType = if ($MSDNLicenseType) { $MSDNLicenseType } else { $msdnLicenseTypeOriginal }
$newLicenseType = if ($false -eq [string]::IsNullOrEmpty($License)) { $License } else { $licenseTypeOriginal }
$newLicenseSource = if ($false -eq [string]::IsNullOrEmpty($LicensingSource)) { $LicensingSource } else { $licenseSourceOriginal }
$newMSDNLicenseType = if ($false -eq [string]::IsNullOrEmpty($MSDNLicenseType)) { $MSDNLicenseType } else { $msdnLicenseTypeOriginal }

$obj = @{
from = ""
Expand All @@ -69,7 +65,7 @@ function Update-VSTeamUserEntitlement {
}
}

$body = ConvertTo-Json -InputObject @($obj) -Depth 100
$body = ConvertTo-Json -InputObject @($obj) -Depth 100 -Compress
SebastianSchuetze marked this conversation as resolved.
Show resolved Hide resolved

$msg = "$( $user.userName ) ($( $user.email ))"

Expand All @@ -82,9 +78,9 @@ function Update-VSTeamUserEntitlement {
-Body $body `
-Version $(_getApiVersion MemberEntitlementManagement) | Out-Null

Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseType: ($licenseTypeOriginal) to ($newLicenseType)"
Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseSource: ($licenseSourceOriginal) to ($newLicenseSource)"
Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from MSDNLicenseType: ($msdnLicenseTypeOriginal) to ($newMSDNLicenseType)"
Write-Information "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseType: ($licenseTypeOriginal) to ($newLicenseType)"
Write-Information "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseSource: ($licenseSourceOriginal) to ($newLicenseSource)"
Write-Information "Updated user license for $( $user.userName ) ($( $user.email )) from MSDNLicenseType: ($msdnLicenseTypeOriginal) to ($newMSDNLicenseType)"
}
}
}
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '7.3.0'
ModuleVersion = '7.3.1'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down
38 changes: 36 additions & 2 deletions Tests/function/tests/Update-VSTeamUserEntitlement.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ Describe "VSTeamUserEntitlement" -Tag 'VSTeamUserEntitlement' {
}
}

It 'by email should update a user' {
It 'by email without license should update a user' {
Update-VSTeamUserEntitlement `
-LicensingSource msdn `
-MSDNLicenseType enterprise `
-Email '[email protected]' `
-Force

Should -Invoke _callAPI -Exactly -Times 1 -Scope It -ParameterFilter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three values that are being passed up to the API in each of these requests. The only thing the function does is determine if there's a new value to apply or just pass back the current value.

This test should assert that the submitted update object has the expected license type since that isn't changing per the update call.

Copy link
Collaborator Author

@SebastianSchuetze SebastianSchuetze Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smurawski I really tried to understand what you are saying. But I don't get what I should test in your opinion. The licenses are asserted, arent't they?

the cdmdlet does not have return so I can't test the correct return values. I will go ahead with the bug fix, but maybe you could still comment on this and I can improve the test later.

$Method -eq 'Patch' -and
$subDomain -eq 'vsaex' -and
$id -eq '00000000-0000-0000-0000-000000000000' -and
$body -like '*"licensingSource":"msdn"*' -and
$body -like '*"msdnLicenseType":"enterprise"*' -and
$resource -eq 'userentitlements' -and
$version -eq $(_getApiVersion MemberEntitlementManagement)
}
}

It 'by email with license should update a user' {
Update-VSTeamUserEntitlement -License 'Stakeholder' `
-LicensingSource msdn `
-MSDNLicenseType enterprise `
Expand All @@ -35,12 +53,15 @@ Describe "VSTeamUserEntitlement" -Tag 'VSTeamUserEntitlement' {
$Method -eq 'Patch' -and
$subDomain -eq 'vsaex' -and
$id -eq '00000000-0000-0000-0000-000000000000' -and
$body -like '*"accountLicenseType":"Stakeholder"*' -and
$body -like '*"licensingSource":"msdn"*' -and
$body -like '*"msdnLicenseType":"enterprise"*' -and
$resource -eq 'userentitlements' -and
$version -eq $(_getApiVersion MemberEntitlementManagement)
}
}

It 'by id should update a user' {
It 'by id without license should update a user' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is missing similar validations to by email without a license.

Update-VSTeamUserEntitlement -Id '00000000-0000-0000-0000-000000000000' -Force

Should -Invoke _callAPI -Exactly -Times 1 -Scope It -ParameterFilter {
Expand All @@ -52,6 +73,19 @@ Describe "VSTeamUserEntitlement" -Tag 'VSTeamUserEntitlement' {
}
}

It 'by id with license should update a user' {
Update-VSTeamUserEntitlement -Id '00000000-0000-0000-0000-000000000000' -License EarlyAdopter -Force

Should -Invoke _callAPI -Exactly -Times 1 -Scope It -ParameterFilter {
$Method -eq 'Patch' -and
$subDomain -eq 'vsaex' -and
$id -eq '00000000-0000-0000-0000-000000000000' -and
$body -like '*"accountLicenseType":"EarlyAdopter"*' -and
$resource -eq 'userentitlements' -and
$version -eq $(_getApiVersion MemberEntitlementManagement)
}
}

It 'with wrong email should update user with invalid email should throw' {
{ Update-VSTeamUserEntitlement -Email '[email protected]' -License 'Express' -Force } | Should -Throw
}
Expand Down