tests/Get-DFToolSetupState.Tests.ps1
|
BeforeAll { . "$PSScriptRoot/TestSupport.ps1" foreach ($f in Get-DFTestModuleFile) { . $f } } Describe 'Get-DFToolSetupState' { BeforeEach { Set-DFTestXdg } AfterEach { Restore-DFTestXdg } It 'returns an empty object when the state file does not exist' { $state = Get-DFToolSetupState @($state.PSObject.Properties).Count | Should -Be 0 } It 'returns an empty object when the state file is corrupt JSON' { $stateDir = Join-Path $Env:XDG_STATE_HOME 'dotforge' New-Item -ItemType Directory -Force -Path $stateDir | Out-Null Set-Content -Path (Join-Path $stateDir 'setup-state.json') -Value '{ not valid json' -Encoding UTF8 $state = Get-DFToolSetupState @($state.PSObject.Properties).Count | Should -Be 0 } It 'parses an existing state file' { $stateDir = Join-Path $Env:XDG_STATE_HOME 'dotforge' New-Item -ItemType Directory -Force -Path $stateDir | Out-Null @' { "delta": { "ranAt": "2026-09-04T10:22:00Z", "actions": [] } } '@ | Set-Content -Path (Join-Path $stateDir 'setup-state.json') -Encoding UTF8 $state = Get-DFToolSetupState $state.PSObject.Properties['delta'] | Should -Not -BeNullOrEmpty ([datetime]$state.delta.ranAt).ToUniversalTime() | Should -Be ([datetime]'2026-09-04T10:22:00Z').ToUniversalTime() } } |