File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ if ($authContext) {
3232 DownloadAndImportBcContainerHelper
3333 $authContext = New-BcAuthContext - includeDeviceLogin - deviceLoginTimeout ([TimeSpan ]::FromSeconds(0 ))
3434 if ($null -eq $authContext ) {
35- throw " Failed to acquire authentication context via device code flow"
35+ OutputError " Failed to acquire authentication context via device code flow."
36+ return
3637 }
3738
3839 # Build appropriate error message
Original file line number Diff line number Diff line change @@ -100,4 +100,37 @@ Describe "CheckAuthContext Action Tests" {
100100 $summary = Get-Content $env: GITHUB_STEP_SUMMARY - Raw
101101 $summary | Should -Match " could not locate a secret"
102102 }
103+
104+ It ' Should output error when New-BcAuthContext returns null' {
105+ $env: Settings = ' {"adminCenterApiCredentialsSecretName": "adminCenterApiCredentials"}'
106+ $env: Secrets = ' {}'
107+
108+ . (Join-Path $scriptRoot " ..\AL-Go-Helper.ps1" )
109+ Mock DownloadAndImportBcContainerHelper { }
110+ Mock New-BcAuthContext { return $null }
111+ Mock OutputError { }
112+
113+ Invoke-Expression $actionScript
114+ CheckAuthContext - secretName ' nonExistentSecret'
115+
116+ Should - Invoke OutputError - ParameterFilter { $message -like " *Failed to acquire authentication*" }
117+ }
118+
119+ It ' Should use environment-specific message when environmentName is provided' {
120+ $env: Settings = ' {"adminCenterApiCredentialsSecretName": "adminCenterApiCredentials"}'
121+ $env: Secrets = ' {}'
122+
123+ . (Join-Path $scriptRoot " ..\AL-Go-Helper.ps1" )
124+ Mock DownloadAndImportBcContainerHelper { }
125+ Mock New-BcAuthContext {
126+ return @ { deviceCode = " TESTDEVICECODE" ; message = " Enter code to authenticate" }
127+ }
128+
129+ Invoke-Expression $actionScript
130+ CheckAuthContext - secretName ' secret1,secret2' - environmentName ' MyEnv (Production)'
131+
132+ $summary = Get-Content $env: GITHUB_STEP_SUMMARY - Raw
133+ $summary | Should -Match " Business Central Environment MyEnv"
134+ $summary | Should -Match " secret1 or secret2"
135+ }
103136}
You can’t perform that action at this time.
0 commit comments