diff --git a/functions/Set-User.ps1 b/functions/Set-User.ps1 index d066496..46b13fe 100644 --- a/functions/Set-User.ps1 +++ b/functions/Set-User.ps1 @@ -13,14 +13,14 @@ function Set-User { $User, # The user's primary email address. - [Parameter(Mandatory = $true, + [Parameter(Mandatory = $false, ParameterSetName = 'Properties')] [ValidatePattern('@')] [String] $Email, # The user's name. - [Parameter(Mandatory = $false, + [Parameter(Mandatory = $true, ParameterSetName = 'Properties')] [ValidateNotNullOrEmpty()] [String] @@ -188,12 +188,12 @@ function Set-User { $path = '/api/v2/users/create_or_update.json' $body = @{ user = @{ - email = $Email + name = $Name } } $map = @{ - name = 'Name' + email = 'Email' alias = 'Alias' custom_role_id = 'CustomRoleId' details = 'Details' diff --git a/tests/Routes-Users.tests.ps1 b/tests/Routes-Users.tests.ps1 index 3b74f09..c6c58a1 100644 --- a/tests/Routes-Users.tests.ps1 +++ b/tests/Routes-Users.tests.ps1 @@ -296,26 +296,26 @@ Describe 'Users Routes' { $context.User.role = 'admin' - { Set-User -Context $context -Email 'name@company.net' -Confirm:$false } | Should -Not -Throw + { Set-User -Context $context -Name 'Bob Johnson' -Confirm:$false } | Should -Not -Throw Assert-MockCalled Invoke-RestMethod -Exactly 1 -ParameterFilter { $Method -eq 'Post' -and $Uri -match '/api/v2/users/create_or_update\.json' } -Scope It } It 'Does not allow end users to call' { $context.User.role = 'end-user' - { Set-User -Context $context -Email 'name@company.net' -Confirm:$false } | Should -Throw 'Authenticated user must have role' + { Set-User -Context $context -Name 'Bob Johnson' -Confirm:$false } | Should -Throw 'Authenticated user must have role' } It 'Allows agents to call' { $context.User.role = 'agent' - { Set-User -Context $context -Email 'name@company.net' -Confirm:$false } | Should -Not -Throw + { Set-User -Context $context -Name 'Bob Johnson' -Confirm:$false } | Should -Not -Throw } It 'Allows admins to call' { $context.User.role = 'admin' - { Set-User -Context $context -Email 'name@company.net' -Confirm:$false } | Should -Not -Throw + { Set-User -Context $context -Name 'Bob Johnson' -Confirm:$false } | Should -Not -Throw } } @@ -323,9 +323,9 @@ Describe 'Users Routes' { Context 'Create Or Update Many Users' { $users = @( - [PSCustomObject]@{ email = 'rob@company.net' } - [PSCustomObject]@{ email = 'ross@company.net' } - [PSCustomObject]@{ email = 'russel@company.net' } + [PSCustomObject]@{ name = 'Rob' } + [PSCustomObject]@{ name = 'Ross' } + [PSCustomObject]@{ name = 'Russel' } ) It 'Matches the endpoint' {