Skip to content

Commit

Permalink
Correctly require Name rather than Email which is optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobFaie committed Mar 12, 2020
1 parent 1b25295 commit c72e24a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions functions/Set-User.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'
Expand Down
14 changes: 7 additions & 7 deletions tests/Routes-Users.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -296,36 +296,36 @@ Describe 'Users Routes' {

$context.User.role = 'admin'

{ Set-User -Context $context -Email '[email protected]' -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 '[email protected]' -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 '[email protected]' -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 '[email protected]' -Confirm:$false } | Should -Not -Throw
{ Set-User -Context $context -Name 'Bob Johnson' -Confirm:$false } | Should -Not -Throw
}

}

Context 'Create Or Update Many Users' {

$users = @(
[PSCustomObject]@{ email = '[email protected]' }
[PSCustomObject]@{ email = '[email protected]' }
[PSCustomObject]@{ email = '[email protected]' }
[PSCustomObject]@{ name = 'Rob' }
[PSCustomObject]@{ name = 'Ross' }
[PSCustomObject]@{ name = 'Russel' }
)

It 'Matches the endpoint' {
Expand Down

0 comments on commit c72e24a

Please sign in to comment.