File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11. $PSScriptRoot \..\classes\AliasPathMapping.ps1
22
33function Get-Script-Path {
4- $moduleName = " quickpath"
5- $modulePath = (Get-Module - Name $moduleName - ListAvailable | Select-Object - First 1 - ExpandProperty Path)
6- $rootPath = Split-Path $modulePath - Parent
7- $rootPath = Split-Path $rootPath - Parent
8-
9- " $rootPath \aliases.json"
4+ $appData = Join-Path $env: LOCALAPPDATA ' quickpath'
5+ if (-not (Test-Path $appData )) {
6+ New-Item - Path $appData - ItemType Directory - Force | Out-Null
7+ }
8+
9+ $file = Join-Path $appData ' aliases.json'
10+
11+ if (-not (Test-Path $file )) {
12+ ' []' | New-Item - Path $file - ItemType File - Force | Out-Null
13+ }
14+
15+ return $file
1016}
1117
1218
Original file line number Diff line number Diff line change 1212 RootModule = ' quickpath.psm1'
1313
1414 # Version number of this module.
15- ModuleVersion = ' 0.0.0 '
15+ ModuleVersion = ' 0.0.3 '
1616
1717 # Supported PSEditions
1818 # CompatiblePSEditions = @()
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ Describe 'Alias-Helper' {
1111 $script :JSON_FILE_PATH = " $PSScriptRoot \aliases-test.json"
1212 $script :JSON_CONTENT = Get-Content - Path $script :JSON_FILE_PATH | ConvertFrom-Json
1313
14+ $env: LOCALAPPDATA = " localappdata"
15+
1416 Mock New-Item
1517 Mock Test-Path { return $true }
1618 }
@@ -61,11 +63,26 @@ Describe 'Alias-Helper' {
6163 }
6264 }
6365 context ' Get-Script-Path' {
64- It ' Returns correct path' {
65- Mock Get-Module { @ {Path = " moduleinstallfolder/moduleversion/modulepath" } }
66+ It ' Creates directory and file if not exist' {
67+ Mock Test-Path { return $false }
68+ Mock New-Item
6669
6770 Get-Script - Path
68- | Should - Be " moduleinstallfolder\aliases.json"
71+
72+ Assert-MockCalled - CommandName New-Item - Times 2 - Exactly - Scope It
73+ Assert-MockCalled - CommandName New-Item - Times 1 - Exactly - Scope It - ParameterFilter {
74+ $Path -eq (Join-Path $env: LOCALAPPDATA ' quickpath' ) -and $ItemType -eq ' Directory'
75+ }
76+ Assert-MockCalled - CommandName New-Item - Times 1 - Exactly - Scope It - ParameterFilter {
77+ $Path -eq (Join-Path (Join-Path $env: LOCALAPPDATA ' quickpath' ) ' aliases.json' ) -and $ItemType -eq ' File'
78+ }
79+ }
80+ It ' Returns correct file path' {
81+ $expectedPath = Join-Path (Join-Path $env: LOCALAPPDATA ' quickpath' ) ' aliases.json'
82+
83+ $result = Get-Script - Path
84+
85+ $result | Should - Be $expectedPath
6986 }
7087 }
7188 context ' Get-Alias' {
You can’t perform that action at this time.
0 commit comments