Skip to content

Commit 53a5d53

Browse files
committed
Improve test code coverage
1 parent be1b357 commit 53a5d53

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/PSWattTime.Tests/PSWattTime.Tests.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ Describe "PSWattTimeTests" {
55
$env:WATTTIMEUSERNAME | Should -Not -BeNullOrEmpty
66
$env:WATTTIMEPASSWORD | Should -Not -BeNullOrEmpty
77
}
8+
9+
Context "When we have imported the module" {
10+
It "Should have a ConvertFrom-AzureRegion command" {
11+
$test = Get-Command -Module PSWattTime -Name 'ConvertFrom-AzureRegion'
12+
$test | Should -Not -BeNullOrEmpty
13+
$test.CommandType | Should -Be 'Function'
14+
}
15+
16+
It "Should have a Get-AzureRegionWithLowestWattTime command" {
17+
$test = Get-Command -Module PSWattTime -Name 'Get-AzureRegionWithLowestWattTime'
18+
$test | Should -Not -BeNullOrEmpty
19+
$test.CommandType | Should -Be 'Function'
20+
}
21+
22+
It "Should have a Get-WattTime command" {
23+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTime'
24+
$test | Should -Not -BeNullOrEmpty
25+
$test.CommandType | Should -Be 'Function'
26+
}
27+
28+
It "Should have a Get-WattTimeAuthToken command" {
29+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTimeAuthToken'
30+
$test | Should -Not -BeNullOrEmpty
31+
$test.CommandType | Should -Be 'Function'
32+
}
33+
34+
It "Should have a Get-WattTimeForAzureRegion command" {
35+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTimeForAzureRegion'
36+
$test | Should -Not -BeNullOrEmpty
37+
$test.CommandType | Should -Be 'Function'
38+
}
39+
40+
It "Should have a New-WattTimeAccount command" {
41+
$test = Get-Command -Module PSWattTime -Name 'New-WattTimeAccount'
42+
$test | Should -Not -BeNullOrEmpty
43+
$test.CommandType | Should -Be 'Function'
44+
}
45+
46+
}
847

948
Context "When we login" {
1049
It "Should return a token" {
@@ -105,4 +144,22 @@ Describe "PSWattTimeTests" {
105144
$wattTime.percent | Should -BeOfType 'string'
106145
}
107146
}
147+
Context "When we register an account" {
148+
BeforeAll {
149+
Mock -ModuleName PSWattTime -CommandName Invoke-RestMethod { return (New-Object PSObject -Property @{'user' = 'freddo';'ok' = 'User created'})}
150+
$newAccount = New-WattTimeAccount `
151+
-Username 'freddo' `
152+
-Password 'P@ssvvordsAr3St00p1d' `
153+
-Organization 'CloudySpells' `
154+
-Email 'freddo@example.com'
155+
}
156+
157+
It "Should return a PSObject" {
158+
$newAccount | Should -BeOfType 'PSObject'
159+
}
160+
161+
It "Should return an ok field with a user created value" {
162+
$newAccount.ok | Should -Be 'User created'
163+
}
164+
}
108165
}

0 commit comments

Comments
 (0)