diff --git a/SteamPS/Private/API/Test-SteamAPIKey.ps1 b/SteamPS/Private/API/Test-SteamAPIKey.ps1 new file mode 100644 index 0000000..04d7296 --- /dev/null +++ b/SteamPS/Private/API/Test-SteamAPIKey.ps1 @@ -0,0 +1,53 @@ +function Test-SteamAPIKey { + <# + .SYNOPSIS + Tests whether a Steam API key file exists. + + .DESCRIPTION + The `Test-SteamAPIKey` cmdlet checks if a Steam API key file exists in the specified path. + It returns a boolean value indicating whether the key file is present. + + .OUTPUTS + System.Boolean + Returns `$true` if the Steam API key file exists; otherwise, returns `$false`. + + .EXAMPLE + PS C:\> Test-SteamAPIKey + True + + Description: + This example checks if the Steam API key file exists and returns `True`. + + .EXAMPLE + PS C:\> Test-SteamAPIKey + False + + Description: + This example checks if the Steam API key file exists and returns `False`. + + .NOTES + Author: Frederik Hjorslev Nylander + #> + + [CmdletBinding()] + [OutputType('System.Boolean')] + param ( + ) + + begin { + Write-Verbose -Message "[BEGIN ] Starting: $($MyInvocation.MyCommand)" + $SteamPSKey = Test-Path -Path "$env:AppData\SteamPS\SteamPSKey.json" + } + + process { + if ($SteamPSKey -eq $true) { + return [bool]$true + } elseif ($SteamPSKey -eq $false) { + return [bool]$false + } + } + + end { + Write-Verbose -Message "[END ] Ending: $($MyInvocation.MyCommand)" + } +} \ No newline at end of file diff --git a/Tests/Unit/Private/Test-SteamAPIKey.Tests.ps1 b/Tests/Unit/Private/Test-SteamAPIKey.Tests.ps1 new file mode 100644 index 0000000..65f69ef --- /dev/null +++ b/Tests/Unit/Private/Test-SteamAPIKey.Tests.ps1 @@ -0,0 +1,25 @@ +BeforeAll { + . $SteamPSModulePath\Private\API\Test-SteamAPIKey.ps1 +} + +Describe 'Test-SteamAPIKey Tests' { + Context 'When the Steam API key file exists' { + BeforeAll { + Mock -CommandName Test-Path -ModuleName SteamPS -MockWith { return $true } + } + + It 'Returns $true' { + Test-SteamAPIKey | Should -BeTrue + } + } + + Context 'When the Steam API key file does not exist' { + BeforeEach { + Mock -CommandName Test-Path -ModuleName SteamPS -MockWith { return $false } + } + + It 'Returns $false' { + Test-SteamAPIKey | Should -BeFalse + } + } +}