Skip to content
Open
53 changes: 53 additions & 0 deletions SteamPS/Private/API/Test-SteamAPIKey.ps1
Original file line number Diff line number Diff line change
@@ -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)"
}
}
25 changes: 25 additions & 0 deletions Tests/Unit/Private/Test-SteamAPIKey.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
}