Skip to content

Commit

Permalink
♻️ ✅ UPDATE Set-PASUser
Browse files Browse the repository at this point in the history
Updated function to support API functionality introduced in 11.1
  • Loading branch information
pspete committed Nov 29, 2019
1 parent c036e16 commit 768add8
Show file tree
Hide file tree
Showing 2 changed files with 727 additions and 55 deletions.
123 changes: 100 additions & 23 deletions Tests/Set-PASUser.Tests.ps1
Expand Up @@ -38,56 +38,111 @@ Describe $FunctionName {

InModuleScope $ModuleName {

Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Detail1" = "Detail"; "Detail2" = "Detail" }
}
Context "Mandatory Parameters" {

It "specifies parameter UserName as mandatory for ParameterSet legacy" {

(Get-Command Set-PASUser).Parameters["UserName"].ParameterSets["legacy"].IsMandatory | Should be $true

}

$InputObj = [pscustomobject]@{
"UserName" = "SomeUser"
"NewPassword" = $("P_Password" | ConvertTo-SecureString -AsPlainText -Force)
"FirstName" = "Some"
"LastName" = "User"
"ExpiryDate" = "10/31/2018"
It "specifies parameter UserName as mandatory for ParameterSet 11_1" {

(Get-Command Set-PASUser).Parameters["UserName"].ParameterSets["11_1"].IsMandatory | Should be $true

}

}

Context "Mandatory Parameters" {
Context "Input - legacy" {

BeforeEach {

$Parameters = @{Parameter = 'UserName' }
Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Detail1" = "Detail"; "Detail2" = "Detail" }
}

It "specifies parameter <Parameter> as mandatory" -TestCases $Parameters {
$InputObj = [pscustomobject]@{
"UserName" = "SomeUser"
"NewPassword" = $("P_Password" | ConvertTo-SecureString -AsPlainText -Force)
"FirstName" = "Some"
"LastName" = "User"
"ExpiryDate" = "10/31/2018"

param($Parameter)
}

(Get-Command Set-PASUser).Parameters["$Parameter"].Attributes.Mandatory | Should Be $true
$response = $InputObj | Set-PASUser -NewPassword $("P_Password" | ConvertTo-SecureString -AsPlainText -Force) -ExpiryDate "10/31/2018" -UseClassicAPI

}

It "sends request" {

Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/WebServices/PIMServices.svc/Users/SomeUser"

} -Times 1 -Exactly -Scope It

}

It "uses expected method" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'PUT' } -Times 1 -Exactly -Scope It

}

}

$response = $InputObj | Set-PASUser -NewPassword $("P_Password" | ConvertTo-SecureString -AsPlainText -Force) -ExpiryDate "10/31/2018"
Context "Input - V11" {

BeforeEach {

Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Detail1" = "Detail"; "Detail2" = "Detail" }
}

$InputObj = [pscustomobject]@{
"id" = 1234
"UserName" = "SomeUser"
"NewPassword" = $("P_Password" | ConvertTo-SecureString -AsPlainText -Force)
"FirstName" = "Some"
"LastName" = "User"
"ExpiryDate" = "10/31/2018"
"workStreet" = "SomeStreet"
"homePage" = "www.geocities.com"
"faxNumber" = "1979"

}

Context "Input" {
$response = $InputObj | Set-PASUser

}

It "sends request" {

Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope Describe
Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/WebServices/PIMServices.svc/Users/SomeUser"
$URI -eq "$($Script:BaseURI)/api/Users/1234"

} -Times 1 -Exactly -Scope Describe
} -Times 1 -Exactly -Scope It

}

It "uses expected method" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'PUT' } -Times 1 -Exactly -Scope Describe
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'PUT' } -Times 1 -Exactly -Scope It

}

Expand All @@ -99,20 +154,42 @@ Describe $FunctionName {

($Script:RequestBody) -ne $null

} -Times 1 -Exactly -Scope Describe
} -Times 1 -Exactly -Scope It

}

It "has a request body with expected number of properties" {
It "throws error if version requirement not met" {
$Script:ExternalVersion = "1.0"

($Script:RequestBody | Get-Member -MemberType NoteProperty).length | Should Be 2
{ $InputObj | Set-PASUser } | Should Throw
$Script:ExternalVersion = "0.0"

}


}

Context "Output" {

BeforeEach {

Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Detail1" = "Detail"; "Detail2" = "Detail" }
}

$InputObj = [pscustomobject]@{
"UserName" = "SomeUser"
"NewPassword" = $("P_Password" | ConvertTo-SecureString -AsPlainText -Force)
"FirstName" = "Some"
"LastName" = "User"
"ExpiryDate" = "10/31/2018"

}

$response = $InputObj | Set-PASUser -NewPassword $("P_Password" | ConvertTo-SecureString -AsPlainText -Force) -ExpiryDate "10/31/2018" -UseClassicAPI

}

it "provides output" {

$response | Should not BeNullOrEmpty
Expand Down

0 comments on commit 768add8

Please sign in to comment.