Skip to content

Commit

Permalink
Return null when no update is available
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-null committed Jan 28, 2025
1 parent edb3ea3 commit c140f1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CRX/CRX.psd1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

@{
RootModule = 'CRX.psm1'
ModuleVersion = '0.2.0'
ModuleVersion = '0.2.1'
GUID = 'b5433b6c-b423-4049-8c5e-b3a50566fcf2'
Author = 'Alan Plocieniak'
CompanyName = 'Alan Plocieniak'
Expand Down
2 changes: 1 addition & 1 deletion CRX/Public/Get-CRXUpdateInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Get-CRXUpdateInfo {
try {
$update = Invoke-RestMethod -Uri $url
$app = $update.gupdate.app
if ($app -and $app.updatecheck) {
if ($app -and $app.updatecheck -and $app.updatecheck.status -ne 'noupdate') {
return [CRXUpdateInfo]::new($app.updatecheck)
}
}
Expand Down
20 changes: 19 additions & 1 deletion tests/CRX.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (-not (Get-Module -Name Pester)) {
Import-Module .\CRX\CRX.psm1 -Force

Describe 'CRX.Tests' {
BeforeAll{
BeforeAll {
$testUrl = 'https://localhost.com/crx/blobs/ASuc5ohLVu-itAJfZqe6NgPkB0pCREbOH49PhxJq4pMdp7MWQx-ycGQt8dsD8WUSM_dTlB5sLwXljaUve7GTKh485NrRlNGdmT7O5aT9uS4R9jmIqNJBAMZSmuV9IZ0e0VV7jGd-rrI-YR5eoIra2Q/AOCLHCCCFDKJDDGPAAAJLDGLJHLLHGMD_4_0_0_0.crx'
$testExtensionId = 'aoclhcccfdkjddgpaaajldgljhllhgmd'
}
Expand All @@ -20,6 +20,24 @@ Describe 'CRX.Tests' {
$response = Get-CRXUpdateInfo "invalid"
$response | Should -BeNullOrEmpty
}

It 'Should return null when no update is available' {
Mock -CommandName Invoke-RestMethod -ModuleName CRX -MockWith {
param ($Uri, $OutFile)
return @{
gupdate = @{
app = @{
updatecheck = @{
status = 'noupdate'
}
}
}
}
}

$result = Get-CRXUpdateInfo -Id $testExtensionId
$result | Should -Be $null
}
}

Context 'Test-CRXUpdateAvailable' {
Expand Down

0 comments on commit c140f1d

Please sign in to comment.