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