Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions private/Alias-Helper.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
. $PSScriptRoot\..\classes\AliasPathMapping.ps1

function Get-Script-Path {
$moduleName = "quickpath"
$modulePath = (Get-Module -Name $moduleName -ListAvailable | Select-Object -First 1 -ExpandProperty Path)
$rootPath = Split-Path $modulePath -Parent
$rootPath = Split-Path $rootPath -Parent

"$rootPath\aliases.json"
$appData = Join-Path $env:LOCALAPPDATA 'quickpath'
if (-not (Test-Path $appData)) {
New-Item -Path $appData -ItemType Directory -Force | Out-Null
}

$file = Join-Path $appData 'aliases.json'

if (-not (Test-Path $file)) {
'[]' | New-Item -Path $file -ItemType File -Force | Out-Null
}

return $file
}


Expand Down
2 changes: 1 addition & 1 deletion quickpath.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'quickpath.psm1'

# Version number of this module.
ModuleVersion = '0.0.0'
ModuleVersion = '0.0.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
23 changes: 20 additions & 3 deletions tests/Alias-Helper.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Describe 'Alias-Helper' {
$script:JSON_FILE_PATH = "$PSScriptRoot\aliases-test.json"
$script:JSON_CONTENT = Get-Content -Path $script:JSON_FILE_PATH | ConvertFrom-Json

$env:LOCALAPPDATA = "localappdata"

Mock New-Item
Mock Test-Path { return $true }
}
Expand Down Expand Up @@ -61,11 +63,26 @@ Describe 'Alias-Helper' {
}
}
context 'Get-Script-Path' {
It 'Returns correct path' {
Mock Get-Module { @{Path = "moduleinstallfolder/moduleversion/modulepath" } }
It 'Creates directory and file if not exist' {
Mock Test-Path { return $false }
Mock New-Item

Get-Script-Path
| Should -Be "moduleinstallfolder\aliases.json"

Assert-MockCalled -CommandName New-Item -Times 2 -Exactly -Scope It
Assert-MockCalled -CommandName New-Item -Times 1 -Exactly -Scope It -ParameterFilter {
$Path -eq (Join-Path $env:LOCALAPPDATA 'quickpath') -and $ItemType -eq 'Directory'
}
Assert-MockCalled -CommandName New-Item -Times 1 -Exactly -Scope It -ParameterFilter {
$Path -eq (Join-Path (Join-Path $env:LOCALAPPDATA 'quickpath') 'aliases.json') -and $ItemType -eq 'File'
}
}
It 'Returns correct file path' {
$expectedPath = Join-Path (Join-Path $env:LOCALAPPDATA 'quickpath') 'aliases.json'

$result = Get-Script-Path

$result | Should -Be $expectedPath
}
}
context 'Get-Alias' {
Expand Down