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
2 changes: 1 addition & 1 deletion Test/private/Mock_Today.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function Get-Mock_Today{
$ret = @{
# today = "2024-06-30"
today = "2025-03-15"
past = "2024-02-18"
}

return $ret
Expand Down
64 changes: 57 additions & 7 deletions Test/public/project/updateprojectrecent.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,80 @@

# Verify Set-EnvItem_Last_RecentUpdate_Today was NOT called - env item should be null/empty
$envValue = Invoke-PrivateContext { Get-EnvItem_Last_RecentUpdate -Owner "octodemo" -ProjectNumber 700 }
Assert-IsNotNull -Object $envValue
Assert-AreEqual -Expected $today -Presented $envValue

}

function Test_UpdateProjectRecent_UpdateBasedOn_SetRecentUpdate{
function Test_UpdateProjectRecent_UpdateBasedOn_FirstTime{
# Arrange
$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$today = (Get-Mock_Today).today

# Cache project
MockCall_GetProject_700 -Cache
# Act - use the mock to run the project full sync to set the last recent update to today
MockCall_GetProject_700

$result = Update-ProjectRecent -Owner $owner -ProjectNumber $projectNumber

Check warning

Code scanning / PSScriptAnalyzer

The variable 'result' is assigned but never used. Warning

The variable 'result' is assigned but never used.

## Assert check that the EnvironmentCache_Last_RecentUpdate_octodemo_700.json is set to today
$envValue = Invoke-PrivateContext { Get-EnvItem_Last_RecentUpdate -Owner "octodemo" -ProjectNumber 700 }
Assert-AreEqual -Expected $today -Presented $envValue

}

function Test_UpdateProjectRecent_UpdateBasedOn_SetToToday{
# Arrange
$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$today = (Get-Mock_Today).today

# Act - use the mock to run the project full sync to set the last recent update to today
MockCall_GetProject_700 -Cache

## Assert check that the EnvironmentCache_Last_RecentUpdate_octodemo_700.json is set to today
$envValue = Invoke-PrivateContext { Get-EnvItem_Last_RecentUpdate -Owner "octodemo" -ProjectNumber 700 }
Assert-AreEqual -Expected $today -Presented $envValue

# Reset Mocks to ensure no mocks functions left from caching project
Reset_Test_Mock -NoResetDatabase

$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$today = (Get-Mock_Today).today
$query = "updated:<$today"
# Mock the call to GitHubOrgProjectWithFields with the query to get only recently updated items
$query = "updated:>=$today"
# not real query just a mock file with some items reply
$fileName = $p.getProjectWithQuery.getProjectWithQueryMockFile
# Set te only sync allowed on Update-ProjectRecent
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -Query $query -FileName $fileName

# Act second time - call Update-ProjectRecent again to ensure it uses the last recent update date
$result = Update-ProjectRecent -Owner $owner -ProjectNumber $projectNumber
Assert-IsTrue $result
}

function Test_UpdateProjectRecent_UpdateBasedOn_SetToTehPast{
# Arrange
$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$d = Get-Mock_Today ; $today = $d.today ; $pastDate = $d.past

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Act - use the mock to run the project full sync to set the last recent update to today
MockCall_GetProject_700 -Cache

## Assert check that the EnvironmentCache_Last_RecentUpdate_octodemo_700.json is set to today
Invoke-PrivateContext { Set-EnvItem_Last_RecentUpdate -Owner "octodemo" -ProjectNumber 700 -Value "2024-02-18" }


# Reset Mocks to ensure no mocks functions left from caching project
Reset_Test_Mock -NoResetDatabase

# Mock the call to GitHubOrgProjectWithFields with the query to get only recently updated items
$query = "updated:>=$pastDate"
# not real query just a mock file with some items reply
$fileName = $p.getProjectWithQuery.getProjectWithQueryMockFile
# Set te only sync allowed on Update-ProjectRecent
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -Query $query -FileName $fileName

# Act second time - call Update-ProjectRecent again to ensure it uses the last recent update date
$result = Update-ProjectRecent -Owner $owner -ProjectNumber $projectNumber
Assert-IsTrue $result

# ASsert that value has changed to today
$envValue = Invoke-PrivateContext { Get-EnvItem_Last_RecentUpdate -Owner "octodemo" -ProjectNumber 700 }
Assert-AreEqual -Expected $today -Presented $envValue
}
56 changes: 47 additions & 9 deletions public/project/updateprojectrecent.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

$RECENT_QUERY = "updated:>={date}"

function Update-ProjectRecent{
[CmdletBinding()]
param(
Expand All @@ -11,29 +14,35 @@
}

# Get Last update date
$last = Get-EnvItem_Last_RecentUpdate -Owner $Owner -ProjectNumber $ProjectNumber
$query = ($null -eq $last) ? $null : "updated:<$last"
$query = Get-UpdateRecentQuery -Owner $Owner -ProjectNumber $ProjectNumber

$ret = Update-Project -Owner $Owner -ProjectNumber $ProjectNumber -SkipItems:$SkipItems -Query $Query

if($result){
if($ret){
Set-EnvItem_Last_RecentUpdate_Today -Owner $Owner -ProjectNumber $ProjectNumber
}

return $ret
} Export-ModuleMember -Function Update-ProjectRecent

function Set-EnvItem_Last_RecentUpdate_Today{
function Get-UpdateRecentQuery{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-UpdateRecentQuery' does not have a help comment. Note

The cmdlet 'Get-UpdateRecentQuery' does not have a help comment.
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Owner,
[Parameter(Mandatory)][int]$ProjectNumber
[Parameter()][string]$Owner,
[Parameter()][int]$ProjectNumber
)

$now = Get-DateToday
Set-EnvItem -Name "EnvironmentCache_Last_RecentUpdate_$($Owner)_$($ProjectNumber)" -Value $now
$last = Get-EnvItem_Last_RecentUpdate -Owner $Owner -ProjectNumber $ProjectNumber

}
# If no last update return no filter to update all
if ($null -eq $last){
return ""

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-UpdateRecentQuery' returns an object of type 'System.String' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Get-UpdateRecentQuery' returns an object of type 'System.String' but this type is not declared in the OutputType attribute.
}

$ret = $RECENT_QUERY -replace "{date}", $last

return $ret
} Export-ModuleMember -Function Get-UpdateRecentQuery

function Get-EnvItem_Last_RecentUpdate{
[CmdletBinding()]
Expand All @@ -44,5 +53,34 @@

$last = Get-EnvItem -Name "EnvironmentCache_Last_RecentUpdate_$($Owner)_$($ProjectNumber)"

Write-MyDebug "EnvItem_Last_RecentUpdate" "Last recent update for $Owner/$ProjectNumber is $last"

return $last
}

function Set-EnvItem_Last_RecentUpdate{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Set-EnvItem_Last_RecentUpdate' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Set-EnvItem_Last_RecentUpdate' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Owner,
[Parameter(Mandatory)][int]$ProjectNumber,
[Parameter(Mandatory)][string]$Value
)

Set-EnvItem -Name "EnvironmentCache_Last_RecentUpdate_$($Owner)_$($ProjectNumber)" -Value $Value

Write-MyDebug "EnvItem_Last_RecentUpdate" "Set last recent update for $Owner/$ProjectNumber to $Value"

}

function Set-EnvItem_Last_RecentUpdate_Today{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Set-EnvItem_Last_RecentUpdate_Today' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Set-EnvItem_Last_RecentUpdate_Today' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Owner,
[Parameter(Mandatory)][int]$ProjectNumber
)

$now = Get-DateToday

Set-EnvItem_Last_RecentUpdate -Owner $Owner -ProjectNumber $ProjectNumber -Value $now

}
Loading