Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4a512dd
refactor(database): cache databaseRoot to avoid calling so much integ…
rulasg Oct 27, 2025
65d7155
fix(database): allow force on Get-DatabaseStore for reset
rulasg Oct 27, 2025
b021f1e
style(database): format code for consistency and readability
rulasg Oct 27, 2025
8f5917c
refactor(test): update Get-ProjectItemList references to Get-ProjectI…
rulasg Oct 27, 2025
c83289e
fix(test): update error message for unsaved changes in project item r…
rulasg Oct 27, 2025
ca150a8
refactor(project): update Search-ProjectItem to Get-ProjectItems with…
rulasg Oct 27, 2025
a53de42
refactor(item): remove Get-ProjectItemList
rulasg Oct 31, 2025
3f69a63
refactor(include): sync with include modules
rulasg Oct 31, 2025
d71c084
faet(test_loging): add traceInvoke and mockfiles
rulasg Oct 31, 2025
a833744
style(invokeCommand): improve debug message formatting
rulasg Nov 5, 2025
737faf2
refactor(MyWrite): rename functions for clarity and consistency
rulasg Nov 5, 2025
ad2cb9d
fix(ConvertTo-SingleSelect, ConvertFrom-SingleSelect, ConvertTo-Numbe…
rulasg Nov 5, 2025
d46d489
refactor(GetProjectItemByUrl): enhance functionality with PassThru pa…
rulasg Nov 5, 2025
30a9f3c
refactor(Set-Project): update parameter attributes for pipeline compa…
rulasg Nov 5, 2025
d648c9b
refactor(Show-ProjectItem): enhance addJumpLine calls with descriptiv…
rulasg Nov 5, 2025
548c292
fix(Get-ProjectIssue): update Get-ProjectItemByUrl call to include Pa…
rulasg Nov 5, 2025
9139e82
fix(Test_SearchProjectItem_AND_Filter): update title string formattin…
rulasg Nov 5, 2025
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
48 changes: 48 additions & 0 deletions Test/include/InvokeMockList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

$MockCommandFile = $testRootPath | Join-Path -ChildPath "mockfiles.log"

function Trace-MockCommandFile{
[CmdletBinding()]
param(
[string] $Command,
[string] $FileName
)

# read content
$content = readMockCommandFile

# Check that the entry is already there
$result = $content | Where-Object{$_.command -eq $command}
if($null -ne $result) {return}

# add entry
$new = @{
Command = $command
FileName = $fileName
}

$ret = @()
$ret += $content
$ret += $new

# Save list
writeMockCommandFile -Content $ret
}

function readMockCommandFile{
$ret = Get-Content -Path $MockCommandFile | ConvertFrom-Json

# return an empty aray if content does not exists
$ret = $ret ?? @()

return $ret
}

function writeMockCommandFile($Content){

$list = $Content | ConvertTo-Json

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$sorted = $list | Sort-Object fileName

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$sorted | Out-File -FilePath $MockCommandFile
}
40 changes: 40 additions & 0 deletions Test/include/invokeCommand.mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#
# This includes help commands to mock invokes in a test module
#
# Set $env:TraceInvokeMock to trave Invoke dependencies
# "traceInvoke.log" | %{touch $_ ; $env:TraceInvokeMock = $_ | Resolve-Path}
#
# THIS INCLUDE REQURED module.helper.ps1
if(-not $MODULE_NAME){ throw "Missing MODULE_NAME varaible initialization. Check for module.helerp.ps1 file." }
if(-not $MODULE_ROOT_PATH){ throw "Missing MODULE_ROOT_PATH varaible initialization. Check for module.helerp.ps1 file." }
Expand All @@ -14,6 +17,30 @@ $MOCK_PATH = $testRootPath | Join-Path -ChildPath 'private' -AdditionalChildPath
$MODULE_INVOKATION_TAG = "$($MODULE_NAME)Module"
$MODULE_INVOKATION_TAG_MOCK = "$($MODULE_INVOKATION_TAG)_Mock"

$TraceInvokeMock = $testRootPath | Join-Path -ChildPath "traceInvoke.log"

function Trace-InvokeCommandAlias{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)][string]$Alias
)

$filePath = $TraceInvokeMock

if(! $filePath){ return }

# if(! (Test-Path $filePath)) {return}

$content = Get-Content $filePath

$content = $content ?? @()

if($content.Contains($Alias)) { return}

$alias | Out-File $filePath -Append -Force

}

function Set-InvokeCommandMock{
[CmdletBinding()]
param(
Expand All @@ -22,6 +49,8 @@ function Set-InvokeCommandMock{
)

InvokeHelper\Set-InvokeCommandAlias -Alias $Alias -Command $Command -Tag $MODULE_INVOKATION_TAG_MOCK

Trace-InvokeCommandAlias $alias
}

function Reset-InvokeCommandMock{
Expand Down Expand Up @@ -54,6 +83,8 @@ function MockCall{

Assert-MockFileNotfound $fileName

Trace-MockCommandFile -Command $command -Filename $filename

Set-InvokeCommandMock -Alias $command -Command "Get-MockFileContent -filename $filename"
}

Expand All @@ -65,6 +96,8 @@ function MockCallAsync{

Assert-MockFileNotfound $fileName

Trace-MockCommandFile -Command $command -Filename $filename

$moduleTest = $PSScriptRoot | Split-Path -Parent | Convert-Path

Set-InvokeCommandMock -Alias $command -Command "Import-Module $moduleTest ; Get-MockFileContent -filename $filename"
Expand All @@ -79,6 +112,9 @@ function MockCallJson{
)

Assert-MockFileNotfound $fileName

Trace-MockCommandFile -Command $command -Filename $filename

$asHashTableString = $AsHashtable ? '$true' : '$false'

$commandstr ='Get-MockFileContentJson -filename {filename} -AsHashtable:{asHashTableString}'
Expand All @@ -97,6 +133,8 @@ function MockCallJsonAsync{

Assert-MockFileNotfound $fileName

Trace-MockCommandFile -Command $command -Filename $filename

$moduleTest = $PSScriptRoot | Split-Path -Parent | Convert-Path

Set-InvokeCommandMock -Alias $command -Command "Import-Module $moduleTest ; Get-MockFileContentJson -filename $filename"
Expand Down Expand Up @@ -258,3 +296,5 @@ function Assert-MockFileNotfound{





154 changes: 154 additions & 0 deletions Test/mockfiles.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
[
{
"FileName": "invoke-GitHubOrgProjectWithFields-octodemo-700-skipitems.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 700 -afterFields \"\" -afterItems \"\" -firstItems 0"
},
{
"FileName": "invoke-addcomment-I_kwDOPrRnkc7KkwSq.json",
"Command": "Invoke-AddComment -SubjectId I_kwDOPrRnkc7KkwSq -Comment \"sample comment 1\""
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4BCe3Vzgeio4o.json",
"Command": "Invoke-GetItem -ItemId PVTI_lADOAlIw4c4BCe3Vzgeio4o"
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4BCe3VzgeioBY.json",
"Command": "Invoke-GetItem -ItemId PVTI_lADOAlIw4c4BCe3VzgeioBY"
},
{
"FileName": "invoke-addcomment-PR_kwDOPrRnkc6nndcE.json",
"Command": "Invoke-AddComment -SubjectId PR_kwDOPrRnkc6nndcE -Comment \"sample comment 1\""
},
{
"FileName": "invoke-GitHubOrgProjectWithFields-octodemo-700.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 700 -afterFields \"\" -afterItems \"\""
},
{
"FileName": "invoke-addSubIssue-I_kwDOPrRnkc7KkwSq-9.json",
"Command": "Invoke-AddSubIssue -IssueId I_kwDOPrRnkc7KkwSq -SubIssueUrl https://github.com/octodemo/rulasg-dev-1/issues/9 -ReplaceParent False"
},
{
"FileName": "invoke-addSubIssue-I_kwDOPrRnkc7KkwSq-5.json",
"Command": "Invoke-AddSubIssue -IssueId I_kwDOPrRnkc7KkwSq -SubIssueUrl https://github.com/octodemo/rulasg-dev-1/issues/5 -ReplaceParent False"
},
{
"FileName": "invoke-GitHubOrgProjectWithFields-octodemo-625.2-skipitems.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 625 -afterFields \"\" -afterItems \"\" -firstItems 0"
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4A0Lf4zgYNTc0.json",
"Command": "Invoke-GetItem -itemid PVTI_lADOAlIw4c4A0Lf4zgYNTc0"
},
{
"FileName": "invoke-addcomment-I_kwDOPrRnkc7KkwSq.json",
"Command": "Invoke-AddComment -SubjectId I_kwDOPrRnkc7KkwSq -Comment \"New comment\""
},
{
"FileName": "invoke-addcomment-I_kwDOPrRnkc7KkwSq.json",
"Command": "Invoke-AddComment -SubjectId I_kwDOPrRnkc7KkwSq -Comment \"Another comment2\""
},
{
"FileName": "findprojectempty.json",
"Command": "Invoke-FindProject -Owner github -Pattern \"emptylistpattern\" -firstProject 100 -afterProject \"\""
},
{
"FileName": "findprojectwithlist.json",
"Command": "Invoke-FindProject -Owner github -Pattern \"kk\" -firstProject 100 -afterProject \"\""
},
{
"FileName": "invoke-getitem-PVTI_lADNJr_OADU3Ys4GAgVO.json",
"Command": "Invoke-GetItem -itemid PVTI_lADNJr_OADU3Ys4GAgVO"
},
{
"FileName": "projectV2-skipitems.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner SomeOrg -ProjectNumber 164 -afterFields \"\" -afterItems \"\" -firstItems 0"
},
{
"FileName": "invoke-getitem-id1.json",
"Command": "Invoke-GetItem -itemid id1"
},
{
"FileName": "invoke-getitem-id2.json",
"Command": "Invoke-GetItem -itemid id2"
},
{
"FileName": "invoke-GetIssueOrPullRequest-26.json",
"Command": "Invoke-GetIssueOrPullRequest -Url https://github.com/octodemo/rulasg-dev-1/issues/26"
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4BCe3Vzgeiodc-updated.json",
"Command": "Invoke-GetItem -itemid PVTI_lADOAlIw4c4BCe3Vzgeiodc"
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4BCe3Vzgec8p8.json",
"Command": "Invoke-GetItem -ItemId PVTI_lADOAlIw4c4BCe3Vzgec8p8"
},
{
"FileName": "invoke-repository-rulasg-dev-1.json",
"Command": "Invoke-Repository -Owner octodemo -Name rulasg-dev-1"
},
{
"FileName": "invoke-getitem-PVTI_lADOAlIw4c4A0Lf4zgYNTxI.json",
"Command": "Invoke-GetItem -itemid PVTI_lADOAlIw4c4A0Lf4zgYNTxI"
},
{
"FileName": "invoke-createDraftItem.json",
"Command": "Invoke-CreateDraftItem -ProjectId PVT_kwDOAlIw4c4BCe3V -Title \"DraftIssue created for test \" -Body \"Body of draftissue\""
},
{
"FileName": "invoke-createissue-R_kgDOPrRnkQ.json",
"Command": "Invoke-CreateIssue -RepositoryId R_kgDOPrRnkQ -Title \"Random value title\" -Body \"Random value body\""
},
{
"FileName": "invoke-getissueorpullrequest-46.json",
"Command": "Invoke-GetIssueOrPullRequest -Url https://github.com/octodemo/rulasg-dev-1/issues/46"
},
{
"FileName": "invoke-additemtoproject-PVT_kwDOAlIw4c4BCe3V-I_kwDOPrRnkc7T2Al2.json",
"Command": "Invoke-AddItemToProject -ProjectId PVT_kwDOAlIw4c4BCe3V -ContentId I_kwDOPrRnkc7T2Al2"
},
{
"FileName": "invoke-removeitemfromproject-PVT_kwDOAlIw4c4BCe3V-PVTI_lADOAlIw4c4BCe3VzggVZH8.json",
"Command": "Invoke-RemoveItemFromProject -ProjectId PVT_kwDOAlIw4c4BCe3V -ItemId PVTI_lADOAlIw4c4BCe3VzggVZH8"
},
{
"FileName": "invoke-removeissue-any.json",
"Command": "Invoke-RemoveIssue -IssueId I_kwDOPrRnkc7T2Al2"
},
{
"FileName": "projectV2.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner SomeOrg -ProjectNumber 164 -afterFields \"\" -afterItems \"\""
},
{
"FileName": "invoke-addcomment-I_kwDOPrRnkc7KkwSq.json",
"Command": "Import-Module /Users/rulasg/code/ProjectHelper ; Invoke-AddComment -SubjectId I_kwDOPrRnkc7KkwSq -Comment \"new comment added\""
},
{
"FileName": "invoke-addcomment-PR_kwDOPrRnkc6nndcE.json",
"Command": "Import-Module /Users/rulasg/code/ProjectHelper ; Invoke-AddComment -SubjectId PR_kwDOPrRnkc6nndcE -Comment \"new comment added\""
},
{
"FileName": "invoke-clearProjectV2ItemFieldValue-PVT_kwDOAlIw4c4BCe3V-PVTI_lADOAlIw4c4BCe3Vzgeio4o-PVTF_lADOAlIw4c4BCe3Vzg0rhko.json",
"Command": "Import-Module /Users/rulasg/code/ProjectHelper ; Invoke-GitHubClearItemValues -ProjectId PVT_kwDOAlIw4c4BCe3V -ItemId PVTI_lADOAlIw4c4BCe3Vzgeio4o -FieldId PVTF_lADOAlIw4c4BCe3Vzg0rhko"
},
{
"FileName": "invoke-clearProjectV2ItemFieldValue-PVT_kwDOAlIw4c4BCe3V-PVTI_lADOAlIw4c4BCe3Vzgeio4o-PVTSSF_lADOAlIw4c4BCe3Vzg0rhno.json",
"Command": "Import-Module /Users/rulasg/code/ProjectHelper ; Invoke-GitHubClearItemValues -ProjectId PVT_kwDOAlIw4c4BCe3V -ItemId PVTI_lADOAlIw4c4BCe3Vzgeio4o -FieldId PVTSSF_lADOAlIw4c4BCe3Vzg0rhno"
},
{
"FileName": "invoke-clearProjectV2ItemFieldValue-PVT_kwDOAlIw4c4BCe3V-PVTI_lADOAlIw4c4BCe3Vzgeio4o-PVTF_lADOAlIw4c4BCe3Vzg0rhko.json",
"Command": "Invoke-GitHubClearItemValues -ProjectId PVT_kwDOAlIw4c4BCe3V -ItemId PVTI_lADOAlIw4c4BCe3Vzgeio4o -FieldId PVTF_lADOAlIw4c4BCe3Vzg0rhko"
},
{
"FileName": "invoke-clearProjectV2ItemFieldValue-PVT_kwDOAlIw4c4BCe3V-PVTI_lADOAlIw4c4BCe3Vzgeio4o-PVTSSF_lADOAlIw4c4BCe3Vzg0rhno.json",
"Command": "Invoke-GitHubClearItemValues -ProjectId PVT_kwDOAlIw4c4BCe3V -ItemId PVTI_lADOAlIw4c4BCe3Vzgeio4o -FieldId PVTSSF_lADOAlIw4c4BCe3Vzg0rhno"
},
{
"FileName": "invoke-GitHubOrgProjectWithFields-octodemo-625.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 625 -afterFields \"\" -afterItems \"\""
},
{
"FileName": "invoke-GitHubOrgProjectWithFields-octodemo-626.json",
"Command": "Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 626 -afterFields \"\" -afterItems \"\""
}
]
2 changes: 1 addition & 1 deletion Test/public/interactive_test/get-project-paging.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Test_GetProject_Paging_SUCCESS{

Assert-NotNull -Presented $result

$presented = Get-ProjectItemList -Owner $owner -ProjectNumber $projectNumber
$presented = Get-ProjectItems -Owner $owner -ProjectNumber $projectNumber -IncludeDone
$fields = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber

Assert-Count -Expected 332 -Presented $presented
Expand Down
6 changes: 3 additions & 3 deletions Test/public/project_item.searchprojectitem.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Test_SearchProjectItem_PassThru_SUCCESS {
Assert-Count -Expected $expected -Presented $shown

# Compare one item type difference
Assert-IsTrue -Condition ($raw[0] -is [hashtable])
Assert-IsTrue -Condition ($raw[0] -is [pscustomobject])
Assert-IsTrue -Condition ($shown[0] -is [pscustomobject])
Assert-Count -Expected $attributes.Count -Presented $($shown[0].PSObject.Properties.Name)

Expand Down Expand Up @@ -111,8 +111,8 @@ function Test_SearchProjectItem_AND_Filter_SUCCESS {
MockCall_GetProject $p -Cache

$i = $p.issue
$str = '"Title": "{title}",' -replace "{title}",$i.title
$newStr = '"Title": "{title} UniqueSearchAlpha UniqueSearchBeta",' -replace "{title}",$i.title
$str = '"{title}"' -replace '{title}',$i.title
$newStr = '"{title} UniqueSearchAlpha UniqueSearchBeta"' -replace '{title}',$i.title

# Add content to the title of a file
$dbpathh = Invoke-MyCommand -Command "Invoke-ProjectHelperGetDatabaseStorePath" | Join-Path -ChildPath octodemo_700.json
Expand Down
10 changes: 5 additions & 5 deletions Test/public/project_item.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function Test_EditProjectItems_Direct{

function Test_UpdateProjectDatabase_Fail_With_Staged{
# When changes are staged list update should fail.
# As Update-ProjectDatabase is a private function, we will test it through the public function Get-ProjectItemList with Force
# As Update-ProjectDatabase is a private function, we will test it through the public function Get-ProjectItems with Force

Reset-InvokeCommandMock
Mock_DatabaseRoot
Expand All @@ -309,7 +309,7 @@ function Test_UpdateProjectDatabase_Fail_With_Staged{
MockCall_GetItem -ItemId $itemId

# Act empty as their is nothing staged yet
$result = Get-ProjectItemList -Owner $Owner -ProjectNumber $ProjectNumber -Force
$result = Get-ProjectItems -Owner $Owner -ProjectNumber $ProjectNumber -Force -IncludeDone
Assert-Count -Expected $itemsCount -Presented $result

# arrange modifyt to add staged
Expand All @@ -322,18 +322,18 @@ function Test_UpdateProjectDatabase_Fail_With_Staged{

# This call should fail as there are staged changes
Start-MyTranscript
$result = Get-ProjectItemList -Owner $Owner -ProjectNumber $ProjectNumber -Force
$result = Get-ProjectItems -Owner $Owner -ProjectNumber $ProjectNumber -Force -IncludeDone
$tt = Stop-MyTranscript

Assert-IsNull -Object $result
$message = "Error: Can not get item list with Force [True]; There are unsaved changes. Restore changes with Reset-ProjectItemStaged or sync projects with Sync-ProjectItemStaged first and try again"
$message = "Error: Failed to get project [octodemo/700]: There are unsaved changes. Restore changes with Reset-ProjectItemStaged or sync projects with Sync-ProjectItemStaged first and try again"
Assert-Contains -Expected $message -Presented $tt

# Reset the staged changes
Reset-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
$result = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-Count -Expected 0 -Presented $result.Keys
$result = Get-ProjectItemList -Owner $Owner -ProjectNumber $ProjectNumber -Force
$result = Get-ProjectItems -Owner $Owner -ProjectNumber $ProjectNumber -Force -IncludeDone
Assert-Count -Expected $itemsCount -Presented $result

}
Expand Down
Loading