-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitialize-Blogger.Tests.ps1
More file actions
75 lines (60 loc) · 1.98 KB
/
Initialize-Blogger.Tests.ps1
File metadata and controls
75 lines (60 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Describe "Initialize-Blogger" {
BeforeEach {
Import-Module $PSScriptRoot\..\PSBlogger.psm1 -Force
}
# Context "Try it" {
# It "Should launch browser and authenticate" {
# Initialize-Blogger
# }
# }
Context "User provides AuthCode" {
BeforeEach {
InModuleScope -ModuleName PSBlogger {
# simulate valid auth token
Mock Get-GoogleAccessToken { return @{ refresh_token = "refresh_token" } }
# simulate valid offline token
Mock Update-GoogleAccessToken { return @{ access_token = "access_token" } }
# simulate auth-flow in browser
Mock Wait-GoogleAuthApiToken { "simulatedcode" }
# prevent browser from being launched
Mock Start-Process { }
}
}
It "Should persist credentials" {
# test variable inside loaded module
InModuleScope -ModuleName PSBlogger {
# arrange
$credentialCache = "TestDrive:\credentialcache.json"
$BloggerSession.CredentialCache = $credentialCache
$initArgs = @{
ClientId = "dummy"
ClientSecret = "dummy"
}
# act
Initialize-Blogger @initArgs
# assert
$credentials = Get-Content -Path $credentialCache | ConvertFrom-Json
$credentials.access_token | Should -Be "access_token"
}
}
It "Should reset previous auth tokens" {
# test variable inside loaded module
InModuleScope -ModuleName PSBlogger {
# arrange
$credentialCache = "TestDrive:\credentialcache.json"
$BloggerSession.CredentialCache = $credentialCache
$BloggerSession.AccessToken = "invalid"
$BloggerSession.RefreshToken = "invalid"
$initArgs = @{
ClientId = "dummy"
ClientSecret = "dummy"
}
# act
Initialize-Blogger @initArgs
# assert
$BloggerSession.AccessToken | Should -Be $null
$BloggerSession.RefreshToken | Should -Be $null
}
}
}
}