@@ -4,16 +4,13 @@ Describe "Initialize-Blogger" {
44 Import-Module $PSScriptRoot \..\PSBlogger.psm1 - Force
55 }
66
7- # Context "Try it" {
8- # It "Should launch browser and authenticate" {
9- # Initialize-Blogger
10- # }
11- # }
12-
137 Context " User provides AuthCode" {
148
159 BeforeEach {
1610 InModuleScope - ModuleName PSBlogger {
11+ # simulate running as admin
12+ Mock Test-IsAdmin { $true }
13+
1714 # simulate valid auth token
1815 Mock Get-GoogleAccessToken { return @ { refresh_token = " refresh_token" } }
1916 # simulate valid offline token
@@ -72,4 +69,30 @@ Describe "Initialize-Blogger" {
7269
7370 }
7471
72+ Context " Running as non-admin" {
73+ BeforeEach {
74+ InModuleScope - ModuleName PSBlogger {
75+ # simulate running as non-admin
76+ Mock Test-IsAdmin { $false }
77+
78+ # ensure that we don't launch browser or admin features
79+ Mock Start-Process { throw " Unexpected call to start-process" }
80+ }
81+ }
82+
83+ It " Should show warning and exit when not admin" {
84+ InModuleScope - ModuleName PSBlogger {
85+ # arrange
86+ $initArgs = @ { ClientId = " dummy" ; ClientSecret = " dummy" }
87+ Mock Write-Warning {} - Verifiable
88+
89+ # act & assert
90+ { Initialize-Blogger @initArgs } | Should -Not - Throw
91+
92+ # The function should exit early, so we can verify it doesn't try to do auth
93+ Assert-MockCalled Test-IsAdmin - Times 1
94+ Should - InvokeVerifiable
95+ }
96+ }
97+ }
7598}
0 commit comments