Skip to content

Commit

Permalink
Correct issues caught by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jan 19, 2021
1 parent be91d72 commit d5b95c0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/parts/TssVersionObject.ps1
Expand Up @@ -51,7 +51,7 @@ process {
}
}

switch ($source) {
switch ($source.Name) {
'Get-TssVersion' {
$returnProps = 'Version'
}
Expand Down
11 changes: 4 additions & 7 deletions tests/reports/New-TssReport.Tests.ps1
@@ -1,8 +1,6 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot,'..','constants.ps1'))

$PSDefaultParameterValues.Remove("*:TssSession")
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
Expand All @@ -29,9 +27,8 @@ Describe "$commandName works" {
BeforeDiscovery {
$reportName = ("TssTestReport$(Get-Random)")
$session = New-TssSession -SecretServer $ss -Credential $ssCred
$PSDefaultParameterValues.Add("*:TssSession",$session)

$categoryId = (Get-TssReportCategory -All).Where({$_.Name -eq 'tssModuleTest'}).CategoryId
$categoryId = (Get-TssReportCategory -TssSession $session -All).Where({$_.Name -eq 'tssModuleTest'}).CategoryId
if ($null -eq $categoryId) {
$bodData = @{
data = @{
Expand All @@ -41,10 +38,11 @@ Describe "$commandName works" {
} | ConvertTo-Json
# bug in endpoint where it won't return the Category ID properly
Invoke-TssRestApi -Uri "$($session.ApiUrl)/reports/categories" -Method 'POST' -Body $bodData -PersonalAccessToken $session.AccessToken > $null
$categoryId = (Get-TssReportCategory -All).Where({$_.Name -eq 'tssModuleTest'}).CategoryId
$categoryId = (Get-TssReportCategory -TssSession $session -All).Where({$_.Name -eq 'tssModuleTest'}).CategoryId
}

$newReport = @{
TssSession = $session
ReportName = $reportName
CategoryId = $categoryId
Description = "Tss Module Test report"
Expand All @@ -55,9 +53,8 @@ Describe "$commandName works" {

# delete report created
Invoke-TssRestApi -Uri "$($session.ApiUrl)/reports/$($object.Id)" -Method DELETE -PersonalAccessToken $session.AccessToken > $null
Remove-TssReportCategory -ReportCategoryId $categoryId -Confirm:$false > $null
Remove-TssReportCategory -TssSession $session -ReportCategoryId $categoryId -Confirm:$false > $null
$session.SessionExpire()
$PSDefaultParameterValues.Remove("*:TssSession")
}
Context "Checking" -Foreach @{object = $object} {
It "Should not be empty" {
Expand Down
14 changes: 7 additions & 7 deletions tests/reports/Remove-TssReportCategory.Tests.ps1
@@ -1,8 +1,6 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))

$PSDefaultParameterValues.Remove("*:TssSession")
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
Expand All @@ -28,7 +26,6 @@ Describe "$commandName verify parameters" {
Describe "$commandName works" {
BeforeDiscovery {
$session = New-TssSession -SecretServer $ss -Credential $ssCred
$PSDefaultParameterValues.Add("*:TssSession",$session)

$reportCatName = "tssModuleTest$(Get-Random)"
$bodData = @{
Expand All @@ -39,12 +36,15 @@ Describe "$commandName works" {
} | ConvertTo-Json
# bug in endpoint where it won't return the Category ID properly
Invoke-TssRestApi -Uri "$($session.ApiUrl)/reports/categories" -Method 'POST' -Body $bodData -PersonalAccessToken $session.AccessToken > $null
$categoryId = (Get-TssReportCategory -All).Where({$_.Name -eq $reportCatName}).CategoryId
$categoryId = (Get-TssReportCategory -TssSession $session -All).Where({$_.Name -eq $reportCatName}).CategoryId
}
Context "Checking" -Foreach @{categoryId = $categoryId} {
Context "Checking" -Foreach @{categoryId = $categoryId; session = $session} {
AfterAll {
$session.SessionExpire()
}
It "Should delete the category" {
Remove-TssReportCategory -ReportCategoryId $categoryId -Confirm:$false
$cat = Get-TssReportCategory -ReportCategoryId $categoryId -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
Remove-TssReportCategory -TssSession $session -ReportCategoryId $categoryId -Confirm:$false
$cat = Get-TssReportCategory -TssSession $session -ReportCategoryId $categoryId -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$cat | Should -BeNullOrEmpty
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/secrets/Set-TssSecret.Tests.ps1
@@ -1,8 +1,6 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))

$PSDefaultParameterValues.Remove("*:TssSession")
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
Expand Down

0 comments on commit d5b95c0

Please sign in to comment.