Skip to content

Commit fba83bc

Browse files
authored
Merge pull request #187 from rulasg/fix-lose-items
fix(Get-Project): comment out unused SkipItems logic
2 parents 531e941 + bae9df9 commit fba83bc

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

Test/public/project_fields_list.test.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,34 @@ function Test_GetProjectFields_SUCCESS_MoreInfo{
7878
Assert-Contains -Presented $result[0].MoreInfo -Expected "Todo"
7979
Assert-Contains -Presented $result[0].MoreInfo -Expected "In Progress"
8080
Assert-Contains -Presented $result[0].MoreInfo -Expected "Done"
81+
}
82+
83+
# Check that when calling Get-ProjectFields with -Force the Items are still there
84+
function Test_GetProjectFields_SUCCESS_ForceWithItems{
85+
86+
$p = Get-Mock_Project_700 ; $owner = $p.Owner ; $projectNumber = $p.Number
87+
88+
# Cache project and reset Mocks
89+
MockCall_GetProject $p -Cache
90+
Reset_Test_Mock -NoResetDatabase
91+
92+
## Assert that items are cached
93+
$result = Get-Project -Owner $owner -ProjectNumber $projectNumber
94+
Assert-Count -Expected $p.items.totalCount -Presented $result.items
95+
96+
# Mock the call with SkipItems
97+
MockCall_GetProject $p -SkipItems
98+
99+
# Act
100+
$result = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber -Force
101+
102+
# Assert return items.
103+
Assert-Count -Expected $p.fields.totalCount -Presented $result
104+
105+
# Check that items are still there
106+
# As we do not set a mock it will
107+
$result = Get-Project -Owner $owner -ProjectNumber $projectNumber
108+
Assert-Count -Expected $p.items.totalCount -Presented $result.items
109+
Assert-Count -Expected $p.fields.totalCount -Presented $result.fields
110+
81111
}

private/projectDatabase/project_database_update.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ function Update-ProjectDatabase {
9898
$items = $actualItems
9999
}
100100

101+
# If we are Skiping items on the update we need to keep the existing items in the database and just update the fields
102+
if($SkipItems){
103+
$actualprj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber
104+
105+
# Check if project has no items or the project is not cached yet
106+
$actualItems = $actualprj.items ?? $(New-HashTable)
107+
108+
$items = $actualItems
109+
}
110+
101111
# Save ProjectV2 object to ProjectDatabase
102112
Save-ProjectV2toDatabase $projectV2 -Items $items -Fields $fields
103113

public/project/getproject.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function Get-Project {
1919

2020
$prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber
2121

22-
if($SkipItems){
23-
$prj.Items = @()
24-
}
22+
# if($SkipItems){
23+
# $prj.items = @()
24+
# }
2525

2626
return $prj
2727
} Export-ModuleMember -Function Get-Project

0 commit comments

Comments
 (0)