@@ -3,10 +3,13 @@ if (-not (Get-Module -Name Pester)) {
3
3
}
4
4
Import-Module .\CRX\CRX.psm1 - Force
5
5
6
+ $testUrl = ' https://localhost.com/crx/blobs/ASuc5ohLVu-itAJfZqe6NgPkB0pCREbOH49PhxJq4pMdp7MWQx-ycGQt8dsD8WUSM_dTlB5sLwXljaUve7GTKh485NrRlNGdmT7O5aT9uS4R9jmIqNJBAMZSmuV9IZ0e0VV7jGd-rrI-YR5eoIra2Q/AOCLHCCCFDKJDDGPAAAJLDGLJHLLHGMD_4_0_0_0.crx'
7
+ $testExtensionId = ' aoclhcccfdkjddgpaaajldgljhllhgmd'
8
+
6
9
Describe ' CRX.Tests' {
7
10
Context ' Get-CRXUpdateInfo' {
8
11
It ' Should return CRXUpdateInfo object' {
9
- $response = Get-CRXUpdateInfo " aoclhcccfdkjddgpaaajldgljhllhgmd "
12
+ $response = Get-CRXUpdateInfo $testExtensionId
10
13
$response.Url | Should -Not - BeNullOrEmpty
11
14
$response.Version | Should -Not - BeNullOrEmpty
12
15
}
@@ -20,48 +23,48 @@ Describe 'CRX.Tests' {
20
23
Context ' Test-CRXUpdateAvailable' {
21
24
It ' Should return true if update is available' {
22
25
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
29
32
}
30
33
}
31
- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1.0.0"
34
+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 1.0.0"
32
35
$result | Should - Be $true
33
36
}
34
37
35
38
It ' Should return false if no update is available' {
36
39
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
43
46
}
44
47
}
45
- $result = Test-CRXUpdateAvailable - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - currentVersion " 1 .0.0"
48
+ $result = Test-CRXUpdateAvailable - Id $testExtensionId - currentVersion " 2 .0.0"
46
49
$result | Should - Be $false
47
50
}
48
51
49
52
It ' Should return false if update info is null' {
50
53
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"
52
55
$result | Should - Be $false
53
56
}
54
57
}
55
58
56
59
Context ' Get-CRX' {
57
60
It ' Should download CRX file to specified directory' {
58
61
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
65
68
}
66
69
}
67
70
@@ -71,9 +74,9 @@ Describe 'CRX.Tests' {
71
74
}
72
75
73
76
$outputDir = " .\temp"
74
- $result = Get-CRX - Id " aoclhcccfdkjddgpaaajldgljhllhgmd " - OutputDirectory $outputDir
77
+ $result = Get-CRX - Id $testExtensionId - OutputDirectory $outputDir
75
78
76
- $expectedPath = Join-Path - Path $outputDir - ChildPath " extension .crx"
79
+ $expectedPath = Join-Path - Path $outputDir - ChildPath " $testExtensionId `_4_0_0_0 .crx"
77
80
Test-Path $expectedPath | Should - Be $true
78
81
$result | Should - BeOfType [System.IO.FileInfo ]
79
82
$result.FullName | Should - Be (Resolve-Path $expectedPath | Select-Object - ExpandProperty Path)
0 commit comments