-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be25214
commit 05eccca
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Hawk/tests/internal/functions/Test-HawkDateParameter.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
Describe 'Test-HawkDateParameter' { | ||
BeforeAll { | ||
# Mock Stop-PSFFunction to intercept and throw the error message directly | ||
Mock -ModuleName Hawk Stop-PSFFunction { | ||
param($Message) | ||
throw $Message | ||
} | ||
} | ||
|
||
Context 'Parameter combination validation' { | ||
It 'Should throw when neither StartDate nor DaysToLookBack is provided' { | ||
# Arrange | ||
$PSBoundParameters = @{} | ||
|
||
# Act & Assert | ||
{ Test-HawkDateParameter -PSBoundParameters $PSBoundParameters } | | ||
Should -Throw "Either StartDate or DaysToLookBack must be specified in non-interactive mode" | ||
} | ||
|
||
It 'Should process valid StartDate and EndDate combination' { | ||
# Arrange | ||
$currentDate = Get-Date | ||
$startDate = $currentDate.AddDays(-30) | ||
$endDate = $currentDate | ||
$PSBoundParameters = @{ | ||
StartDate = $startDate | ||
EndDate = $endDate | ||
} | ||
|
||
# Act | ||
$result = Test-HawkDateParameter -PSBoundParameters $PSBoundParameters -StartDate $startDate -EndDate $endDate | ||
|
||
# Assert | ||
$result.StartDate | Should -Be $startDate.ToUniversalTime().Date | ||
$result.EndDate | Should -Be $endDate.ToUniversalTime().Date.AddDays(1) | ||
} | ||
} | ||
|
||
Context 'DaysToLookBack processing' { | ||
It 'Should correctly process DaysToLookBack with specified EndDate' { | ||
# Arrange | ||
$currentDate = Get-Date | ||
$endDate = $currentDate | ||
$daysToLook = 30 | ||
$PSBoundParameters = @{ | ||
DaysToLookBack = $daysToLook | ||
EndDate = $endDate | ||
} | ||
|
||
# Act | ||
$result = Test-HawkDateParameter -PSBoundParameters $PSBoundParameters -DaysToLookBack $daysToLook -EndDate $endDate | ||
|
||
# Assert | ||
$result.StartDate | Should -Be $endDate.ToUniversalTime().Date.AddDays(-$daysToLook) | ||
$result.EndDate | Should -Be $endDate.ToUniversalTime().Date.AddDays(1) | ||
} | ||
|
||
It 'Should calculate correct dates when only DaysToLookBack is provided' { | ||
# Arrange | ||
$currentDate = Get-Date | ||
$daysToLook = 30 | ||
$PSBoundParameters = @{ | ||
DaysToLookBack = $daysToLook | ||
} | ||
|
||
# Act | ||
$result = Test-HawkDateParameter -PSBoundParameters $PSBoundParameters -DaysToLookBack $daysToLook | ||
|
||
# Assert | ||
$result.EndDate | Should -Be $currentDate.ToUniversalTime().Date.AddDays(1) | ||
$result.StartDate | Should -Be $currentDate.ToUniversalTime().Date.AddDays(-$daysToLook) | ||
} | ||
} | ||
|
||
Context 'UTC conversion' { | ||
It 'Should convert dates to UTC and handle end date adjustment' { | ||
# Arrange | ||
$currentDate = Get-Date | ||
$startDate = $currentDate.AddDays(-30) | ||
$endDate = $currentDate | ||
$PSBoundParameters = @{ | ||
StartDate = $startDate | ||
EndDate = $endDate | ||
} | ||
|
||
# Act | ||
$result = Test-HawkDateParameter -PSBoundParameters $PSBoundParameters -StartDate $startDate -EndDate $endDate | ||
|
||
# Assert | ||
$result.StartDate | Should -Be $startDate.ToUniversalTime().Date | ||
$result.EndDate | Should -Be $endDate.ToUniversalTime().Date.AddDays(1) | ||
} | ||
} | ||
|
||
|
||
} |