@@ -4,9 +4,14 @@ if (-not (Get-Module -Name Pester)) {
44Import-Module .\CRX\CRX.psm1 - Force
55
66Describe ' CRX.Tests' {
7+ BeforeAll{
8+ $testUrl = ' https://localhost.com/crx/blobs/ASuc5ohLVu-itAJfZqe6NgPkB0pCREbOH49PhxJq4pMdp7MWQx-ycGQt8dsD8WUSM_dTlB5sLwXljaUve7GTKh485NrRlNGdmT7O5aT9uS4R9jmIqNJBAMZSmuV9IZ0e0VV7jGd-rrI-YR5eoIra2Q/AOCLHCCCFDKJDDGPAAAJLDGLJHLLHGMD_4_0_0_0.crx'
9+ $testExtensionId = ' aoclhcccfdkjddgpaaajldgljhllhgmd'
10+ }
11+
712 Context ' Get-CRXUpdateInfo' {
813 It ' Should return CRXUpdateInfo object' {
9- $response = Get-CRXUpdateInfo " aoclhcccfdkjddgpaaajldgljhllhgmd "
14+ $response = Get-CRXUpdateInfo $testExtensionId
1015 $response.Url | Should -Not - BeNullOrEmpty
1116 $response.Version | Should -Not - BeNullOrEmpty
1217 }
@@ -20,48 +25,48 @@ Describe 'CRX.Tests' {
2025 Context ' Test-CRXUpdateAvailable' {
2126 It ' Should return true if update is available' {
2227 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
28+ New-CRXUpdateInfo @ {
29+ version = " 2.0.0"
30+ codebase = $testUrl
31+ hash_sha256 = " dummyhash"
32+ status = " ok"
33+ size = 12345
2934 }
3035 }
31- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1.0.0"
36+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 1.0.0"
3237 $result | Should - Be $true
3338 }
3439
3540 It ' Should return false if no update is available' {
3641 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
42+ return New-CRXUpdateInfo @ {
43+ version = " 2 .0.0"
44+ codebase = $testUrl
45+ hash_sha256 = " dummyhash"
46+ status = " ok"
47+ size = 12345
4348 }
4449 }
45- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1 .0.0"
50+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 2 .0.0"
4651 $result | Should - Be $false
4752 }
4853
4954 It ' Should return false if update info is null' {
5055 Mock - CommandName Get-CRXUpdateInfo - ModuleName CRX - MockWith { return $null }
51- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1.0.0"
56+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 1.0.0"
5257 $result | Should - Be $false
5358 }
5459 }
5560
5661 Context ' Get-CRX' {
5762 It ' Should download CRX file to specified directory' {
5863 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
64+ return New-CRXUpdateInfo @ {
65+ version = " 2.0.0"
66+ codebase = $testUrl
67+ hash_sha256 = " dummyhash"
68+ status = " ok"
69+ size = 12345
6570 }
6671 }
6772
@@ -71,9 +76,9 @@ Describe 'CRX.Tests' {
7176 }
7277
7378 $outputDir = " .\temp"
74- $result = Get-CRX - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - OutputDirectory $outputDir
79+ $result = Get-CRX - Id $testExtensionId - OutputDirectory $outputDir
7580
76- $expectedPath = Join-Path - Path $outputDir - ChildPath " extension .crx"
81+ $expectedPath = Join-Path - Path $outputDir - ChildPath " $testExtensionId `_4_0_0_0 .crx"
7782 Test-Path $expectedPath | Should - Be $true
7883 $result | Should - BeOfType [System.IO.FileInfo ]
7984 $result.FullName | Should - Be (Resolve-Path $expectedPath | Select-Object - ExpandProperty Path)
0 commit comments