@@ -3,10 +3,13 @@ if (-not (Get-Module -Name Pester)) {
33}
44Import-Module .\CRX\CRX.psm1 - Force
55
6+ $testUrl = ' https://localhost.com/crx/blobs/ASuc5ohLVu-itAJfZqe6NgPkB0pCREbOH49PhxJq4pMdp7MWQx-ycGQt8dsD8WUSM_dTlB5sLwXljaUve7GTKh485NrRlNGdmT7O5aT9uS4R9jmIqNJBAMZSmuV9IZ0e0VV7jGd-rrI-YR5eoIra2Q/AOCLHCCCFDKJDDGPAAAJLDGLJHLLHGMD_4_0_0_0.crx'
7+ $testExtensionId = ' aoclhcccfdkjddgpaaajldgljhllhgmd'
8+
69Describe ' CRX.Tests' {
710 Context ' Get-CRXUpdateInfo' {
811 It ' Should return CRXUpdateInfo object' {
9- $response = Get-CRXUpdateInfo " aoclhcccfdkjddgpaaajldgljhllhgmd "
12+ $response = Get-CRXUpdateInfo $testExtensionId
1013 $response.Url | Should -Not - BeNullOrEmpty
1114 $response.Version | Should -Not - BeNullOrEmpty
1215 }
@@ -20,48 +23,48 @@ Describe 'CRX.Tests' {
2023 Context ' Test-CRXUpdateAvailable' {
2124 It ' Should return true if update is available' {
2225 Mock - CommandName Get-CRXUpdateInfo - ModuleName CRX - MockWith {
23- return [ PSCustomObject ] @ {
24- Version = " 2.0.0"
25- Url = " http://example.com "
26- SHA256 = " dummyhash"
27- Status = " ok"
28- Size = 12345
26+ New-CRXUpdateInfo @ {
27+ version = " 2.0.0"
28+ codebase = $testUrl
29+ hash_sha256 = " dummyhash"
30+ status = " ok"
31+ size = 12345
2932 }
3033 }
31- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1.0.0"
34+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 1.0.0"
3235 $result | Should - Be $true
3336 }
3437
3538 It ' Should return false if no update is available' {
3639 Mock - CommandName Get-CRXUpdateInfo - ModuleName CRX - MockWith {
37- return [ PSCustomObject ] @ {
38- Version = " 1 .0.0"
39- Url = " http://example.com "
40- SHA256 = " dummyhash"
41- Status = " ok"
42- Size = 12345
40+ return New-CRXUpdateInfo @ {
41+ version = " 2 .0.0"
42+ codebase = $testUrl
43+ hash_sha256 = " dummyhash"
44+ status = " ok"
45+ size = 12345
4346 }
4447 }
45- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1 .0.0"
48+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 2 .0.0"
4649 $result | Should - Be $false
4750 }
4851
4952 It ' Should return false if update info is null' {
5053 Mock - CommandName Get-CRXUpdateInfo - ModuleName CRX - MockWith { return $null }
51- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1.0.0"
54+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 1.0.0"
5255 $result | Should - Be $false
5356 }
5457 }
5558
5659 Context ' Get-CRX' {
5760 It ' Should download CRX file to specified directory' {
5861 Mock - CommandName Get-CRXUpdateInfo - ModuleName CRX - MockWith {
59- return [ PSCustomObject ] @ {
60- Version = " 2.0.0"
61- Url = " http://example.com/extension.crx "
62- SHA256 = " dummyhash"
63- Status = " ok"
64- Size = 12345
62+ return New-CRXUpdateInfo @ {
63+ version = " 2.0.0"
64+ codebase = $testUrl
65+ hash_sha256 = " dummyhash"
66+ status = " ok"
67+ size = 12345
6568 }
6669 }
6770
@@ -71,9 +74,9 @@ Describe 'CRX.Tests' {
7174 }
7275
7376 $outputDir = " .\temp"
74- $result = Get-CRX - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - OutputDirectory $outputDir
77+ $result = Get-CRX - Id $testExtensionId - OutputDirectory $outputDir
7578
76- $expectedPath = Join-Path - Path $outputDir - ChildPath " extension .crx"
79+ $expectedPath = Join-Path - Path $outputDir - ChildPath " $testExtensionId `_4_0_0_0 .crx"
7780 Test-Path $expectedPath | Should - Be $true
7881 $result | Should - BeOfType [System.IO.FileInfo ]
7982 $result.FullName | Should - Be (Resolve-Path $expectedPath | Select-Object - ExpandProperty Path)
0 commit comments