Skip to content

Commit e898b55

Browse files
committed
more test coverage
1 parent ecef88e commit e898b55

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Actions/CheckAuthContext/CheckAuthContext.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

Tests/CheckAuthContext.Action.Test.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)