forked from pspete/psPAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-PASAuthenticationMethod.Tests.ps1
More file actions
113 lines (70 loc) · 2.54 KB
/
Add-PASAuthenticationMethod.Tests.ps1
File metadata and controls
113 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Describe $($PSCommandPath -Replace '.Tests.ps1') {
BeforeAll {
#Get Current Directory
$Here = Split-Path -Parent $PSCommandPath
#Assume ModuleName from Repository Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf
#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"
#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"
if ( -not (Get-Module -Name $ModuleName -All)) {
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop
}
$Script:RequestBody = $null
$psPASSession = [ordered]@{
BaseURI = 'https://SomeURL/SomeApp'
User = $null
ExternalVersion = [System.Version]'0.0'
WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
StartTime = $null
ElapsedTime = $null
LastCommand = $null
LastCommandTime = $null
LastCommandResults = $null
}
New-Variable -Name psPASSession -Value $psPASSession -Scope Script -Force
}
AfterAll {
$Script:RequestBody = $null
}
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) {
BeforeEach {
Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{'Prop1' = 'Val1'; 'Prop2' = 'Val2' }
}
$response = Add-PASAuthenticationMethod -id SomeID
}
Context 'Input' {
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:psPASSession.BaseURI)/api/Configuration/AuthenticationMethods"
} -Times 1 -Exactly -Scope It
}
It 'uses expected method' {
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It
}
It 'sends request with expected body' {
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {
$($Body | ConvertFrom-Json | Select-Object -ExpandProperty id) -eq 'SomeID'
} -Times 1 -Exactly -Scope It
}
It 'throws error if version requirement not met' {
$psPASSession.ExternalVersion = '1.0'
{ Add-PASAuthenticationMethod -id SomeID } | Should -Throw
$psPASSession.ExternalVersion = '0.0'
}
}
Context 'Output' {
It 'provides output' {
$response | Should -Not -BeNullOrEmpty
}
It 'has output with expected number of properties' {
($response | Get-Member -MemberType NoteProperty).length | Should -Be 2
}
}
}
}