From 7c1a76d051b78d0b46293983774918d051a72ff0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 12:55:09 +0200 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Refactor=20respon?= =?UTF-8?q?se=20handling=20in=20GitHub=20app=20installation=20functions=20?= =?UTF-8?q?for=20improved=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 | 4 +++- .../GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 index c179a6a3f..568e120f4 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 @@ -51,7 +51,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_) } + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization) + } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 index 90c442354..5c63a6866 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 @@ -50,8 +50,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.installations | ForEach-Object { - [GitHubAppInstallation]::new($_) + foreach ($installation in $_.Response.installations) { + [GitHubAppInstallation]::new($installation) } } } From 192b63bc5027d6cb153fa4b4c73d7bf1c89d6b01 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 12:55:17 +0200 Subject: [PATCH 02/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Update=20installa?= =?UTF-8?q?tion=20handling=20in=20Get-GitHubEnterpriseOrganizationAppInsta?= =?UTF-8?q?llation=20to=20correctly=20process=20multiple=20installations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Get-GitHubEnterpriseOrganizationAppInstallation.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index bdad499f8..502650afd 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -58,7 +58,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubAppInstallation]::new($_.Response) + foreach ($installation in $_.Response.installations) { + [GitHubAppInstallation]::new($installation) + } } } From 83e321155978c40b3dadc9be61bffa8f4a9c96ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 13:54:41 +0200 Subject: [PATCH 03/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Enhance=20GitHubA?= =?UTF-8?q?ppInstallation=20constructor=20to=20accept=20target=20and=20typ?= =?UTF-8?q?e=20parameters=20for=20improved=20installation=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/App/GitHubAppInstallation.ps1 | 23 ++++++++++++++++++- ...bEnterpriseOrganizationAppInstallation.ps1 | 2 +- .../public/Auth/Connect-GitHubApp.ps1 | 6 ++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/classes/public/App/GitHubAppInstallation.ps1 b/src/classes/public/App/GitHubAppInstallation.ps1 index 6684d77f4..c0071d3ad 100644 --- a/src/classes/public/App/GitHubAppInstallation.ps1 +++ b/src/classes/public/App/GitHubAppInstallation.ps1 @@ -40,7 +40,7 @@ GitHubAppInstallation() {} - GitHubAppInstallation([PSCustomObject]$Object) { + GitHubAppInstallation([PSCustomObject] $Object) { $this.ID = $Object.id $this.App = [GitHubApp]::new( [PSCustomObject]@{ @@ -60,4 +60,25 @@ $this.SuspendedAt = $Object.suspended_at $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) } + + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type) { + $this.ID = $Object.id + $this.App = [GitHubApp]::new( + [PSCustomObject]@{ + client_id = $Object.client_id + app_id = $Object.app_id + app_slug = $Object.app_slug + } + ) + $this.Target = [GitHubOwner]::new($Target) + $this.Type = $Type + $this.RepositorySelection = $Object.repository_selection + $this.Permissions = $Object.permissions + $this.Events = , ($Object.events) + $this.FilePaths = $Object.single_file_paths + $this.CreatedAt = $Object.created_at + $this.UpdatedAt = $Object.updated_at + $this.SuspendedAt = $Object.suspended_at + $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) + } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index 502650afd..79b2f94d5 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -59,7 +59,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($installation in $_.Response.installations) { - [GitHubAppInstallation]::new($installation) + [GitHubAppInstallation]::new($installation, $Organization, 'Organization') } } } diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index dd11923d2..1bf29392e 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -153,8 +153,8 @@ $contextParams['Owner'] = [string]$installation.Target.Name } 'Enterprise' { - $contextParams['InstallationName'] = [string]$installation.account.slug - $contextParams['Enterprise'] = [string]$installation.account.slug + $contextParams['InstallationName'] = [string]$installation.Target.Name + $contextParams['Enterprise'] = [string]$installation.Target.Name } } Write-Verbose 'Logging in using a managed installation access token...' @@ -162,7 +162,7 @@ $contextObj = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) $contextObj | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose $_ } if (-not $Silent) { - $name = $contextObj.name + $name = $contextObj.Name if ($script:GitHub.EnvironmentType -eq 'GHA') { $green = $PSStyle.Foreground.Green $reset = $PSStyle.Reset From f8d98464368134a021a589358f81479719585b1a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 14:15:49 +0200 Subject: [PATCH 04/17] Add initial test scripts for GitHub API interactions - Created TEMPLATE.ps1 for structuring Pester tests. - Added Teams.Tests.ps1 to test GitHub Teams API functionalities. - Implemented Users.Tests.ps1 for user-related API tests. - Developed Variables.Tests.ps1 to validate GitHub variable management. - Introduced Apps.Tests.ps1 for testing GitHub Apps API endpoints. - Each test file includes setup and teardown logic, context management, and various test cases for different authentication types and scenarios. --- {tests => tests copy}/Artifacts.Tests.ps1 | 0 tests copy/Data/AuthCases.ps1 | 83 ++++++++ tests copy/Data/IssueForm.md | 19 ++ {tests => tests copy}/Environments.Tests.ps1 | 0 {tests => tests copy}/GitHub.Tests.ps1 | 158 --------------- {tests => tests copy}/Organizations.Tests.ps1 | 0 {tests => tests copy}/README.md | 0 {tests => tests copy}/Releases.Tests.ps1 | 0 {tests => tests copy}/Repositories.Tests.ps1 | 0 {tests => tests copy}/Secrets.Tests.ps1 | 0 {tests => tests copy}/TEMPLATE.ps1 | 0 {tests => tests copy}/Teams.Tests.ps1 | 0 {tests => tests copy}/Users.Tests.ps1 | 0 {tests => tests copy}/Variables.Tests.ps1 | 0 tests/Apps.Tests.ps1 | 180 ++++++++++++++++++ 15 files changed, 282 insertions(+), 158 deletions(-) rename {tests => tests copy}/Artifacts.Tests.ps1 (100%) create mode 100644 tests copy/Data/AuthCases.ps1 create mode 100644 tests copy/Data/IssueForm.md rename {tests => tests copy}/Environments.Tests.ps1 (100%) rename {tests => tests copy}/GitHub.Tests.ps1 (80%) rename {tests => tests copy}/Organizations.Tests.ps1 (100%) rename {tests => tests copy}/README.md (100%) rename {tests => tests copy}/Releases.Tests.ps1 (100%) rename {tests => tests copy}/Repositories.Tests.ps1 (100%) rename {tests => tests copy}/Secrets.Tests.ps1 (100%) rename {tests => tests copy}/TEMPLATE.ps1 (100%) rename {tests => tests copy}/Teams.Tests.ps1 (100%) rename {tests => tests copy}/Users.Tests.ps1 (100%) rename {tests => tests copy}/Variables.Tests.ps1 (100%) create mode 100644 tests/Apps.Tests.ps1 diff --git a/tests/Artifacts.Tests.ps1 b/tests copy/Artifacts.Tests.ps1 similarity index 100% rename from tests/Artifacts.Tests.ps1 rename to tests copy/Artifacts.Tests.ps1 diff --git a/tests copy/Data/AuthCases.ps1 b/tests copy/Data/AuthCases.ps1 new file mode 100644 index 000000000..63c7f1438 --- /dev/null +++ b/tests copy/Data/AuthCases.ps1 @@ -0,0 +1,83 @@ +@( + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Fine-grained PAT token' + TokenType = 'USER_FG_PAT' + Target = 'it self (user account)' + Owner = 'psmodule-user' + OwnerType = 'user' + ConnectParams = @{ + Token = $env:TEST_USER_USER_FG_PAT + } + } + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Fine-grained PAT token' + TokenType = 'ORG_FG_PAT' + Target = 'organization account' + Owner = 'psmodule-test-org2' + OwnerType = 'organization' + ConnectParams = @{ + Token = $env:TEST_USER_ORG_FG_PAT + } + } + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Classic PAT token' + TokenType = 'PAT' + Target = 'user account' + Owner = 'psmodule-user' + OwnerType = 'user' + ConnectParams = @{ + Token = $env:TEST_USER_PAT + } + } + @{ + AuthType = 'IAT' + Type = 'GitHub Actions' + Case = 'GITHUB_TOKEN' + TokenType = 'GITHUB_TOKEN' + Target = 'this repository (GitHub)' + Owner = 'PSModule' + Repo = 'GitHub' + OwnerType = 'repository' + ConnectParams = @{ + Token = $env:GITHUB_TOKEN + } + } + @{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org3' + } + } + @{ + AuthType = 'App' + Type = 'a GitHub App from an Organization' + Case = 'PEM + IAT' + TokenType = 'APP_ORG' + Target = 'organization account' + Owner = 'psmodule-test-org' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ORG_CLIENT_ID + PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org' + } + } +) diff --git a/tests copy/Data/IssueForm.md b/tests copy/Data/IssueForm.md new file mode 100644 index 000000000..83b1b3967 --- /dev/null +++ b/tests copy/Data/IssueForm.md @@ -0,0 +1,19 @@ + +### Type with spaces + +Action + +### Multiline + +test +is multi + line + +### OS + +- [x] Windows +- [x] Linux +- [ ] macOS + diff --git a/tests/Environments.Tests.ps1 b/tests copy/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to tests copy/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/tests copy/GitHub.Tests.ps1 similarity index 80% rename from tests/GitHub.Tests.ps1 rename to tests copy/GitHub.Tests.ps1 index cf42caafa..dc23e96c1 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests copy/GitHub.Tests.ps1 @@ -470,164 +470,6 @@ line } } -Describe 'Apps' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - Write-Host ('-' * 60) - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - Context 'GitHub Apps' { - It 'Get-GitHubApp - Can get app details' { - $app = Get-GitHubApp - LogGroup 'App' { - Write-Host ($app | Format-List | Out-String) - } - $app | Should -Not -BeNullOrEmpty - $app | Should -BeOfType 'GitHubApp' - $app.ID | Should -Not -BeNullOrEmpty - $app.ClientID | Should -Not -BeNullOrEmpty - $app.Slug | Should -Not -BeNullOrEmpty - $app.NodeID | Should -Not -BeNullOrEmpty - $app.Owner | Should -BeOfType 'GitHubOwner' - $app.Name | Should -Not -BeNullOrEmpty - $app.Description | Should -Not -BeNullOrEmpty - $app.ExternalUrl | Should -Not -BeNullOrEmpty - $app.Url | Should -Not -BeNullOrEmpty - $app.CreatedAt | Should -Not -BeNullOrEmpty - $app.UpdatedAt | Should -Not -BeNullOrEmpty - $app.Permissions | Should -BeOfType 'PSCustomObject' - $app.Events | Should -BeOfType 'string' - $app.Installations | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { - $jwt = Get-GitHubAppJSONWebToken @connectParams - LogGroup 'JWT' { - Write-Host ($jwt | Format-Table | Out-String) - } - $jwt | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppInstallationRequest - Can get installation requests' { - $installationRequests = Get-GitHubAppInstallationRequest - LogGroup 'Installation requests' { - Write-Host ($installationRequests | Format-List | Out-String) - } - } - - It 'Get-GitHubAppInstallation - Can get app installations' { - $installations = Get-GitHubAppInstallation - LogGroup 'Installations' { - Write-Host ($installations | Format-List | Out-String) - } - $installations | Should -Not -BeNullOrEmpty - $githubApp = Get-GitHubApp - foreach ($installation in $installations) { - $installation | Should -BeOfType 'GitHubAppInstallation' - $installation.ID | Should -Not -BeNullOrEmpty - $installation.App | Should -BeOfType 'GitHubApp' - $installation.App.ClientID | Should -Be $githubApp.ClientID - $installation.App.AppID | Should -Not -BeNullOrEmpty - $installation.App.Slug | Should -Not -BeNullOrEmpty - $installation.Target | Should -BeOfType 'GitHubOwner' - $installation.Type | Should -Not -BeNullOrEmpty - $installation.RepositorySelection | Should -Not -BeNullOrEmpty - $installation.Permissions | Should -BeOfType 'PSCustomObject' - $installation.Events | Should -BeOfType 'string' - $installation.CreatedAt | Should -Not -BeNullOrEmpty - $installation.UpdatedAt | Should -Not -BeNullOrEmpty - $installation.SuspendedAt | Should -BeNullOrEmpty - $installation.SuspendedBy | Should -BeOfType 'GitHubUser' - } - } - - It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { - $installations = Get-GitHubAppInstallation - LogGroup 'Tokens' { - $installations | ForEach-Object { - $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id - Write-Host ($token | Format-List | Out-String) - } - $token | Should -Not -BeNullOrEmpty - } - } - } - - Context 'Webhooks' { - It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - $webhookConfig | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { - { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - form' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - json' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - } - - It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { - $deliveries = Get-GitHubAppWebhookDelivery - LogGroup 'Deliveries' { - Write-Host ($deliveries | Format-Table | Out-String) - } - $deliveries | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { - $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - } - } - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - It 'Get-GitHubApp - Get an app by slug' { - $app = Get-GitHubApp -Slug 'github-actions' - LogGroup 'App by slug' { - Write-Host ($app | Format-List | Out-String) - } - $app | Should -Not -BeNullOrEmpty - } - } -} - Describe 'API' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" diff --git a/tests/Organizations.Tests.ps1 b/tests copy/Organizations.Tests.ps1 similarity index 100% rename from tests/Organizations.Tests.ps1 rename to tests copy/Organizations.Tests.ps1 diff --git a/tests/README.md b/tests copy/README.md similarity index 100% rename from tests/README.md rename to tests copy/README.md diff --git a/tests/Releases.Tests.ps1 b/tests copy/Releases.Tests.ps1 similarity index 100% rename from tests/Releases.Tests.ps1 rename to tests copy/Releases.Tests.ps1 diff --git a/tests/Repositories.Tests.ps1 b/tests copy/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to tests copy/Repositories.Tests.ps1 diff --git a/tests/Secrets.Tests.ps1 b/tests copy/Secrets.Tests.ps1 similarity index 100% rename from tests/Secrets.Tests.ps1 rename to tests copy/Secrets.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/tests copy/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to tests copy/TEMPLATE.ps1 diff --git a/tests/Teams.Tests.ps1 b/tests copy/Teams.Tests.ps1 similarity index 100% rename from tests/Teams.Tests.ps1 rename to tests copy/Teams.Tests.ps1 diff --git a/tests/Users.Tests.ps1 b/tests copy/Users.Tests.ps1 similarity index 100% rename from tests/Users.Tests.ps1 rename to tests copy/Users.Tests.ps1 diff --git a/tests/Variables.Tests.ps1 b/tests copy/Variables.Tests.ps1 similarity index 100% rename from tests/Variables.Tests.ps1 rename to tests copy/Variables.Tests.ps1 diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 new file mode 100644 index 000000000..3692347a4 --- /dev/null +++ b/tests/Apps.Tests.ps1 @@ -0,0 +1,180 @@ +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Pester grouping syntax: known issue.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Used to create a secure string for testing.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long test descriptions and skip switches' +)] +[CmdletBinding()] +param() + +Describe 'Apps' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + Write-Host ('-' * 60) + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + Context 'GitHub Apps' { + It 'Get-GitHubApp - Can get app details' { + $app = Get-GitHubApp + LogGroup 'App' { + Write-Host ($app | Format-List | Out-String) + } + $app | Should -Not -BeNullOrEmpty + $app | Should -BeOfType 'GitHubApp' + $app.ID | Should -Not -BeNullOrEmpty + $app.ClientID | Should -Not -BeNullOrEmpty + $app.Slug | Should -Not -BeNullOrEmpty + $app.NodeID | Should -Not -BeNullOrEmpty + $app.Owner | Should -BeOfType 'GitHubOwner' + $app.Name | Should -Not -BeNullOrEmpty + $app.Description | Should -Not -BeNullOrEmpty + $app.ExternalUrl | Should -Not -BeNullOrEmpty + $app.Url | Should -Not -BeNullOrEmpty + $app.CreatedAt | Should -Not -BeNullOrEmpty + $app.UpdatedAt | Should -Not -BeNullOrEmpty + $app.Permissions | Should -BeOfType 'PSCustomObject' + $app.Events | Should -BeOfType 'string' + $app.Installations | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { + $jwt = Get-GitHubAppJSONWebToken @connectParams + LogGroup 'JWT' { + Write-Host ($jwt | Format-Table | Out-String) + } + $jwt | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppInstallationRequest - Can get installation requests' { + $installationRequests = Get-GitHubAppInstallationRequest + LogGroup 'Installation requests' { + Write-Host ($installationRequests | Format-List | Out-String) + } + } + + It 'Get-GitHubAppInstallation - Can get app installations' { + $installations = Get-GitHubAppInstallation + LogGroup 'Installations' { + Write-Host ($installations | Format-List | Out-String) + } + $installations | Should -Not -BeNullOrEmpty + $githubApp = Get-GitHubApp + foreach ($installation in $installations) { + $installation | Should -BeOfType 'GitHubAppInstallation' + $installation.ID | Should -Not -BeNullOrEmpty + $installation.App | Should -BeOfType 'GitHubApp' + $installation.App.ClientID | Should -Be $githubApp.ClientID + $installation.App.AppID | Should -Not -BeNullOrEmpty + $installation.App.Slug | Should -Not -BeNullOrEmpty + $installation.Target | Should -BeOfType 'GitHubOwner' + $installation.Target | Should -Not -BeNullOrEmpty + $installation.Type | Should -Not -BeNullOrEmpty + $installation.RepositorySelection | Should -Not -BeNullOrEmpty + $installation.Permissions | Should -BeOfType 'PSCustomObject' + $installation.Events | Should -BeOfType 'string' + $installation.CreatedAt | Should -Not -BeNullOrEmpty + $installation.UpdatedAt | Should -Not -BeNullOrEmpty + $installation.SuspendedAt | Should -BeNullOrEmpty + $installation.SuspendedBy | Should -BeOfType 'GitHubUser' + $installation.SuspendedBy | Should -BeNullOrEmpty + } + } + + It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { + $installations = Get-GitHubAppInstallation + LogGroup 'Tokens' { + $installations | ForEach-Object { + $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id + Write-Host ($token | Format-List | Out-String) + } + $token | Should -Not -BeNullOrEmpty + } + } + } + + Context 'Webhooks' { + It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + $webhookConfig | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { + { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - form' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - json' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + } + + It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { + $deliveries = Get-GitHubAppWebhookDelivery + LogGroup 'Deliveries' { + Write-Host ($deliveries | Format-Table | Out-String) + } + $deliveries | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { + $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + } + } + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + It 'Get-GitHubApp - Get an app by slug' { + $app = Get-GitHubApp -Slug 'github-actions' + LogGroup 'App by slug' { + Write-Host ($app | Format-List | Out-String) + } + $app | Should -Not -BeNullOrEmpty + } + } +} From a6ff73a5c658afcabd1faf48fcc4e8b9354b05a8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 14:30:18 +0200 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Add=20test=20case?= =?UTF-8?q?=20for=20GitHub=20App=20Enterprise=20authentication=20with=20PE?= =?UTF-8?q?M=20+=20IAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Data/AuthCases.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 63c7f1438..25c1f9ca2 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -64,6 +64,22 @@ Organization = 'psmodule-test-org3' } } + @{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'Enterprise account' + Owner = 'psmodule-test-org3' + OwnerType = 'enterprise' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Enterprise = 'msx' + } + } @{ AuthType = 'App' Type = 'a GitHub App from an Organization' From c1bd5fec5b141c4bb41e5ad9118d71d8640ab7b1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 15:12:44 +0200 Subject: [PATCH 06/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Update=20owner=20?= =?UTF-8?q?in=20PEM=20+=20IAT=20test=20case=20for=20Enterprise=20account?= =?UTF-8?q?=20and=20enhance=20assertions=20in=20Apps.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Apps.Tests.ps1 | 4 ++-- tests/Data/AuthCases.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 3692347a4..963e33e8c 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -91,8 +91,8 @@ Describe 'Apps' { $installation.App.AppID | Should -Not -BeNullOrEmpty $installation.App.Slug | Should -Not -BeNullOrEmpty $installation.Target | Should -BeOfType 'GitHubOwner' - $installation.Target | Should -Not -BeNullOrEmpty - $installation.Type | Should -Not -BeNullOrEmpty + $installation.Target | Should -Be $owner + $installation.Type | Should -Be $ownerType $installation.RepositorySelection | Should -Not -BeNullOrEmpty $installation.Permissions | Should -BeOfType 'PSCustomObject' $installation.Events | Should -BeOfType 'string' diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 25c1f9ca2..6ebf9e9a4 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -70,7 +70,7 @@ Case = 'PEM + IAT' TokenType = 'APP_ENT' Target = 'Enterprise account' - Owner = 'psmodule-test-org3' + Owner = 'msx' OwnerType = 'enterprise' ConnectParams = @{ ClientID = $env:TEST_APP_ENT_CLIENT_ID From e826659575aee8fd27c25d385a92413cea1a3f80 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 16:12:07 +0200 Subject: [PATCH 07/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Update=20Apps.Tes?= =?UTF-8?q?ts=20to=20enhance=20GitHub=20App=20installation=20tests=20and?= =?UTF-8?q?=20add=20enterprise-specific=20assertions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 4 ++++ tests/Apps.Tests.ps1 | 57 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 6d578178e..89cf0af6f 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,7 @@ Test: + PSModule: + Skip: true + SourceCode: + Skip: true CodeCoverage: PercentTarget: 50 diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 963e33e8c..5ca7dd5d2 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -77,12 +77,12 @@ Describe 'Apps' { } It 'Get-GitHubAppInstallation - Can get app installations' { + $githubApp = Get-GitHubApp $installations = Get-GitHubAppInstallation LogGroup 'Installations' { Write-Host ($installations | Format-List | Out-String) } $installations | Should -Not -BeNullOrEmpty - $githubApp = Get-GitHubApp foreach ($installation in $installations) { $installation | Should -BeOfType 'GitHubAppInstallation' $installation.ID | Should -Not -BeNullOrEmpty @@ -91,8 +91,8 @@ Describe 'Apps' { $installation.App.AppID | Should -Not -BeNullOrEmpty $installation.App.Slug | Should -Not -BeNullOrEmpty $installation.Target | Should -BeOfType 'GitHubOwner' - $installation.Target | Should -Be $owner - $installation.Type | Should -Be $ownerType + $installation.Target | Should -Not -BeNullOrEmpty + $installation.Type | Should -BeIn @('Enterprise', 'Organization', 'User') $installation.RepositorySelection | Should -Not -BeNullOrEmpty $installation.Permissions | Should -BeOfType 'PSCustomObject' $installation.Events | Should -BeOfType 'string' @@ -114,6 +114,32 @@ Describe 'Apps' { $token | Should -Not -BeNullOrEmpty } } + + It 'Get-GitHubAppInstallation - Enterprise' -Skip($ownerType -ne 'enterprise') { + $githubApp = Get-GitHubApp + $installation = Get-GitHubAppInstallation -Enterprise $owner + LogGroup 'Installations - Enterprise' { + Write-Host ($installation | Format-List | Out-String) + } + $installation | Should -Not -BeNullOrEmpty + $installation | Should -BeOfType 'GitHubAppInstallation' + $installation.ID | Should -Not -BeNullOrEmpty + $installation.App | Should -BeOfType 'GitHubApp' + $installation.App.ClientID | Should -Be $githubApp.ClientID + $installation.App.AppID | Should -Not -BeNullOrEmpty + $installation.App.Slug | Should -Not -BeNullOrEmpty + $installation.Target | Should -BeOfType 'GitHubOwner' + $installation.Target | Should -Be $owner + $installation.Type | Should -Be $ownerType + $installation.RepositorySelection | Should -Not -BeNullOrEmpty + $installation.Permissions | Should -BeOfType 'PSCustomObject' + $installation.Events | Should -BeOfType 'string' + $installation.CreatedAt | Should -Not -BeNullOrEmpty + $installation.UpdatedAt | Should -Not -BeNullOrEmpty + $installation.SuspendedAt | Should -BeNullOrEmpty + $installation.SuspendedBy | Should -BeOfType 'GitHubUser' + $installation.SuspendedBy | Should -BeNullOrEmpty + } } Context 'Webhooks' { @@ -158,10 +184,35 @@ Describe 'Apps' { } } It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $githubApp = Get-GitHubApp + $config = Get-GitHubConfig $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } + $context | Should -BeOfType 'InstallationGitHubContext' + $context.ClientID | Should -Be $githubApp.ClientID + $context.TokenExpirationDate | Should -BeOfType [datetime] + $context.InstallationID | Should -Be 29371 + $context.Permissions | Should -BeOfType [PSCustomObject] + $context.Events | Should -BeOfType 'string' + $context.InstallationType | Should -Be $ownertype + $context.InstallationName | Should -Be $owner + $context.ID | Should -Be "$($config.HostName)/$($githubApp.Slug)/$ownertype/$owner" + $context.Name | Should -Be "$($config.HostName)/$($githubApp.Slug)/$ownertype/$owner" + $context.DisplayName | Should -Be $githubApp.Name + $context.Type | Should -Be 'Installation' + $context.HostName | Should -Be $config.HostName + $context.ApiBaseUri | Should -Be $config.ApiBaseUri + $context.ApiVersion | Should -Be $config.ApiVersion + $context.AuthType | Should -Be 'IAT' + $context.NodeID | Should -Not -BeNullOrEmpty + $context.DatabaseID | Should -Not -BeNullOrEmpty + $context.UserName | Should -Be $githubApp.Slug + $context.Token | Should -BeOfType [System.Security.SecureString] + $context.TokenType | Should -Be 'ghs' + $context.HttpVersion | Should -Be $config.HttpVersion + $context.PerPage | Should -Be $config.PerPage } } From edeccc9c0bf4330b67207311029b2eaa9f209757 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 16:17:47 +0200 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Update=20test=20c?= =?UTF-8?q?ase=20for=20GitHub=20App=20installation=20to=20use=20correct=20?= =?UTF-8?q?syntax=20for=20skipping=20enterprise=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Apps.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 5ca7dd5d2..ddafa0713 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -115,7 +115,7 @@ Describe 'Apps' { } } - It 'Get-GitHubAppInstallation - Enterprise' -Skip($ownerType -ne 'enterprise') { + It 'Get-GitHubAppInstallation - Enterprise' -Skip:($ownerType -ne 'enterprise') { $githubApp = Get-GitHubApp $installation = Get-GitHubAppInstallation -Enterprise $owner LogGroup 'Installations - Enterprise' { From 68c7161ca5d81ff4fd49972e1e1af258e21157b7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 16:26:09 +0200 Subject: [PATCH 09/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Change=20Installa?= =?UTF-8?q?tionID=20type=20to=20uint64=20and=20update=20related=20test=20a?= =?UTF-8?q?ssertions=20in=20Apps.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Context/GitHubContext/InstallationGitHubContext.ps1 | 2 +- tests/Apps.Tests.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 b/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 index 9d61ff992..b7dc45a15 100644 --- a/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 +++ b/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 @@ -7,7 +7,7 @@ [datetime] $TokenExpirationDate # The installation ID. - [int] $InstallationID + [uint64] $InstallationID # The permissions that the app is requesting on the target [pscustomobject] $Permissions diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index ddafa0713..7e4b51bda 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -193,7 +193,8 @@ Describe 'Apps' { $context | Should -BeOfType 'InstallationGitHubContext' $context.ClientID | Should -Be $githubApp.ClientID $context.TokenExpirationDate | Should -BeOfType [datetime] - $context.InstallationID | Should -Be 29371 + $context.InstallationID | Should -BeOfType [uint64] + $context.InstallationID | Should -BeGreaterThan 0 $context.Permissions | Should -BeOfType [PSCustomObject] $context.Events | Should -BeOfType 'string' $context.InstallationType | Should -Be $ownertype From bda131d237371b3b941816e85b114eba1b17e9e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 16:30:18 +0200 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Add=20test=20case?= =?UTF-8?q?=20for=20GitHub=20App=20installation=20retrieval=20for=20organi?= =?UTF-8?q?zations=20in=20Apps.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Apps.Tests.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 7e4b51bda..f214403c4 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -140,6 +140,31 @@ Describe 'Apps' { $installation.SuspendedBy | Should -BeOfType 'GitHubUser' $installation.SuspendedBy | Should -BeNullOrEmpty } + It 'Get-GitHubAppInstallation - Organization' -Skip:($ownerType -ne 'organization') { + $githubApp = Get-GitHubApp + $installation = Get-GitHubAppInstallation -Organization $owner + LogGroup 'Installations - Organization' { + Write-Host ($installation | Format-List | Out-String) + } + $installation | Should -Not -BeNullOrEmpty + $installation | Should -BeOfType 'GitHubAppInstallation' + $installation.ID | Should -Not -BeNullOrEmpty + $installation.App | Should -BeOfType 'GitHubApp' + $installation.App.ClientID | Should -Be $githubApp.ClientID + $installation.App.AppID | Should -Not -BeNullOrEmpty + $installation.App.Slug | Should -Not -BeNullOrEmpty + $installation.Target | Should -BeOfType 'GitHubOwner' + $installation.Target | Should -Be $owner + $installation.Type | Should -Be $ownerType + $installation.RepositorySelection | Should -Not -BeNullOrEmpty + $installation.Permissions | Should -BeOfType 'PSCustomObject' + $installation.Events | Should -BeOfType 'string' + $installation.CreatedAt | Should -Not -BeNullOrEmpty + $installation.UpdatedAt | Should -Not -BeNullOrEmpty + $installation.SuspendedAt | Should -BeNullOrEmpty + $installation.SuspendedBy | Should -BeOfType 'GitHubUser' + $installation.SuspendedBy | Should -BeNullOrEmpty + } } Context 'Webhooks' { From cdd352feeab1dff1e329d6b3cfce00014d2b4b88 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 17:12:58 +0200 Subject: [PATCH 11/17] [Fix]: Remove redundant '-Default' parameter from Connect-GitHubApp call in Apps.Tests --- tests/Apps.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index f214403c4..a18977410 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -211,7 +211,7 @@ Describe 'Apps' { It 'Connect-GitHubApp - Connects as a GitHub App to ' { $githubApp = Get-GitHubApp $config = Get-GitHubConfig - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + $context = Connect-GitHubApp @connectAppParams -PassThru -Silent LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } From 86e5b987ee295adab7ef727de9f72f0f9089276d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 17:31:27 +0200 Subject: [PATCH 12/17] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Refactor=20Get-Gi?= =?UTF-8?q?tHubAppInstallation=20tests=20to=20use=20dynamic=20owner=20type?= =?UTF-8?q?=20and=20improve=20readability=20in=20Apps.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Get-GitHubAppInstallation.ps1 | 1 + tests/Apps.Tests.ps1 | 31 ++----------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 index 856252aa0..69ae92370 100644 --- a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 +++ b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 @@ -56,6 +56,7 @@ PerPage = $PerPage Context = $Context } + Write-Debug "ParamSet: $($PSCmdlet.ParameterSetName)" switch ($PSCmdlet.ParameterSetName) { 'List installations on an Enterprise' { $params += @{ diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index a18977410..59007b786 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -115,35 +115,10 @@ Describe 'Apps' { } } - It 'Get-GitHubAppInstallation - Enterprise' -Skip:($ownerType -ne 'enterprise') { + It 'Get-GitHubAppInstallation - ' { $githubApp = Get-GitHubApp - $installation = Get-GitHubAppInstallation -Enterprise $owner - LogGroup 'Installations - Enterprise' { - Write-Host ($installation | Format-List | Out-String) - } - $installation | Should -Not -BeNullOrEmpty - $installation | Should -BeOfType 'GitHubAppInstallation' - $installation.ID | Should -Not -BeNullOrEmpty - $installation.App | Should -BeOfType 'GitHubApp' - $installation.App.ClientID | Should -Be $githubApp.ClientID - $installation.App.AppID | Should -Not -BeNullOrEmpty - $installation.App.Slug | Should -Not -BeNullOrEmpty - $installation.Target | Should -BeOfType 'GitHubOwner' - $installation.Target | Should -Be $owner - $installation.Type | Should -Be $ownerType - $installation.RepositorySelection | Should -Not -BeNullOrEmpty - $installation.Permissions | Should -BeOfType 'PSCustomObject' - $installation.Events | Should -BeOfType 'string' - $installation.CreatedAt | Should -Not -BeNullOrEmpty - $installation.UpdatedAt | Should -Not -BeNullOrEmpty - $installation.SuspendedAt | Should -BeNullOrEmpty - $installation.SuspendedBy | Should -BeOfType 'GitHubUser' - $installation.SuspendedBy | Should -BeNullOrEmpty - } - It 'Get-GitHubAppInstallation - Organization' -Skip:($ownerType -ne 'organization') { - $githubApp = Get-GitHubApp - $installation = Get-GitHubAppInstallation -Organization $owner - LogGroup 'Installations - Organization' { + $installation = Get-GitHubAppInstallation | Where-Object { $_.Target -eq $owner -and $_.Type -eq $ownerType } + LogGroup "Installation - $ownerType" { Write-Host ($installation | Format-List | Out-String) } $installation | Should -Not -BeNullOrEmpty From f38dd34c451e7be0d4d31e67bdd514f2afe5c191 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 17:42:48 +0200 Subject: [PATCH 13/17] [Fix]: Update Get-GitHubAppInstallation test to correctly filter installations by owner name and type --- tests/Apps.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 59007b786..2ce7e120a 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -117,7 +117,7 @@ Describe 'Apps' { It 'Get-GitHubAppInstallation - ' { $githubApp = Get-GitHubApp - $installation = Get-GitHubAppInstallation | Where-Object { $_.Target -eq $owner -and $_.Type -eq $ownerType } + $installation = Get-GitHubAppInstallation | Where-Object { ($_.Target.Name -eq $owner) -and ($_.Type -eq $ownerType) } LogGroup "Installation - $ownerType" { Write-Host ($installation | Format-List | Out-String) } From c6bcd40fde9c207671fe9eb58594c99c49923d1b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 18:34:54 +0200 Subject: [PATCH 14/17] [Fix]: Remove redundant section for GitHub Actions tests in Apps.Tests --- tests/Apps.Tests.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 2ce7e120a..e6613bb13 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -217,11 +217,8 @@ Describe 'Apps' { } } - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - # Tests for IAT UAT and PAT goes here - It 'Get-GitHubApp - Get an app by slug' { + It 'Get-GitHubApp - Get an app by slug' -Skip:($AuthType -eq 'APP') { $app = Get-GitHubApp -Slug 'github-actions' LogGroup 'App by slug' { Write-Host ($app | Format-List | Out-String) From 287c77a59b4d42b315371bdfeea69f92985d8e9d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 18:46:30 +0200 Subject: [PATCH 15/17] Add initial test scripts for GitHub API interactions - Created TEMPLATE.ps1 for standardized test structure using Pester. - Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion. - Developed Users.Tests.ps1 to validate user-related API calls such as fetching user details and updating user information. - Added Variables.Tests.ps1 to test GitHub variable management, including setting, updating, and removing variables for organizations and repositories. --- .github/PSModule.yml | 4 - tests copy/Data/AuthCases.ps1 | 83 ------------------- tests copy/Data/IssueForm.md | 19 ----- {tests copy => tests}/Artifacts.Tests.ps1 | 0 {tests copy => tests}/Environments.Tests.ps1 | 0 {tests copy => tests}/GitHub.Tests.ps1 | 0 {tests copy => tests}/Organizations.Tests.ps1 | 0 {tests copy => tests}/README.md | 0 {tests copy => tests}/Releases.Tests.ps1 | 0 {tests copy => tests}/Repositories.Tests.ps1 | 0 {tests copy => tests}/Secrets.Tests.ps1 | 0 {tests copy => tests}/TEMPLATE.ps1 | 0 {tests copy => tests}/Teams.Tests.ps1 | 0 {tests copy => tests}/Users.Tests.ps1 | 0 {tests copy => tests}/Variables.Tests.ps1 | 0 15 files changed, 106 deletions(-) delete mode 100644 tests copy/Data/AuthCases.ps1 delete mode 100644 tests copy/Data/IssueForm.md rename {tests copy => tests}/Artifacts.Tests.ps1 (100%) rename {tests copy => tests}/Environments.Tests.ps1 (100%) rename {tests copy => tests}/GitHub.Tests.ps1 (100%) rename {tests copy => tests}/Organizations.Tests.ps1 (100%) rename {tests copy => tests}/README.md (100%) rename {tests copy => tests}/Releases.Tests.ps1 (100%) rename {tests copy => tests}/Repositories.Tests.ps1 (100%) rename {tests copy => tests}/Secrets.Tests.ps1 (100%) rename {tests copy => tests}/TEMPLATE.ps1 (100%) rename {tests copy => tests}/Teams.Tests.ps1 (100%) rename {tests copy => tests}/Users.Tests.ps1 (100%) rename {tests copy => tests}/Variables.Tests.ps1 (100%) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 89cf0af6f..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,7 +1,3 @@ Test: - PSModule: - Skip: true - SourceCode: - Skip: true CodeCoverage: PercentTarget: 50 diff --git a/tests copy/Data/AuthCases.ps1 b/tests copy/Data/AuthCases.ps1 deleted file mode 100644 index 63c7f1438..000000000 --- a/tests copy/Data/AuthCases.ps1 +++ /dev/null @@ -1,83 +0,0 @@ -@( - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Fine-grained PAT token' - TokenType = 'USER_FG_PAT' - Target = 'it self (user account)' - Owner = 'psmodule-user' - OwnerType = 'user' - ConnectParams = @{ - Token = $env:TEST_USER_USER_FG_PAT - } - } - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Fine-grained PAT token' - TokenType = 'ORG_FG_PAT' - Target = 'organization account' - Owner = 'psmodule-test-org2' - OwnerType = 'organization' - ConnectParams = @{ - Token = $env:TEST_USER_ORG_FG_PAT - } - } - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Classic PAT token' - TokenType = 'PAT' - Target = 'user account' - Owner = 'psmodule-user' - OwnerType = 'user' - ConnectParams = @{ - Token = $env:TEST_USER_PAT - } - } - @{ - AuthType = 'IAT' - Type = 'GitHub Actions' - Case = 'GITHUB_TOKEN' - TokenType = 'GITHUB_TOKEN' - Target = 'this repository (GitHub)' - Owner = 'PSModule' - Repo = 'GitHub' - OwnerType = 'repository' - ConnectParams = @{ - Token = $env:GITHUB_TOKEN - } - } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - TokenType = 'APP_ENT' - Target = 'organization account' - Owner = 'psmodule-test-org3' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org3' - } - } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Organization' - Case = 'PEM + IAT' - TokenType = 'APP_ORG' - Target = 'organization account' - Owner = 'psmodule-test-org' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ORG_CLIENT_ID - PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org' - } - } -) diff --git a/tests copy/Data/IssueForm.md b/tests copy/Data/IssueForm.md deleted file mode 100644 index 83b1b3967..000000000 --- a/tests copy/Data/IssueForm.md +++ /dev/null @@ -1,19 +0,0 @@ - -### Type with spaces - -Action - -### Multiline - -test -is multi - line - -### OS - -- [x] Windows -- [x] Linux -- [ ] macOS - diff --git a/tests copy/Artifacts.Tests.ps1 b/tests/Artifacts.Tests.ps1 similarity index 100% rename from tests copy/Artifacts.Tests.ps1 rename to tests/Artifacts.Tests.ps1 diff --git a/tests copy/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from tests copy/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/tests copy/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from tests copy/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/tests copy/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 similarity index 100% rename from tests copy/Organizations.Tests.ps1 rename to tests/Organizations.Tests.ps1 diff --git a/tests copy/README.md b/tests/README.md similarity index 100% rename from tests copy/README.md rename to tests/README.md diff --git a/tests copy/Releases.Tests.ps1 b/tests/Releases.Tests.ps1 similarity index 100% rename from tests copy/Releases.Tests.ps1 rename to tests/Releases.Tests.ps1 diff --git a/tests copy/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from tests copy/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/tests copy/Secrets.Tests.ps1 b/tests/Secrets.Tests.ps1 similarity index 100% rename from tests copy/Secrets.Tests.ps1 rename to tests/Secrets.Tests.ps1 diff --git a/tests copy/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from tests copy/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/tests copy/Teams.Tests.ps1 b/tests/Teams.Tests.ps1 similarity index 100% rename from tests copy/Teams.Tests.ps1 rename to tests/Teams.Tests.ps1 diff --git a/tests copy/Users.Tests.ps1 b/tests/Users.Tests.ps1 similarity index 100% rename from tests copy/Users.Tests.ps1 rename to tests/Users.Tests.ps1 diff --git a/tests copy/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 similarity index 100% rename from tests copy/Variables.Tests.ps1 rename to tests/Variables.Tests.ps1 From 70a043f526b6a3a94b2bc57e33a330b60c0baa8d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 19:42:31 +0200 Subject: [PATCH 16/17] [Fix]: Update tests to handle both 'repository' and 'enterprise' owner types in various test files --- tests/Data/AuthCases.ps1 | 64 +++++++++++++++++------------------ tests/Environments.Tests.ps1 | 22 ++++++------ tests/Organizations.Tests.ps1 | 18 ++++------ tests/Releases.Tests.ps1 | 4 +-- tests/Repositories.Tests.ps1 | 30 ++++++++-------- tests/Secrets.Tests.ps1 | 4 +-- tests/Variables.Tests.ps1 | 4 +-- 7 files changed, 71 insertions(+), 75 deletions(-) diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 6ebf9e9a4..ad252ae73 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -48,38 +48,6 @@ Token = $env:GITHUB_TOKEN } } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - TokenType = 'APP_ENT' - Target = 'organization account' - Owner = 'psmodule-test-org3' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org3' - } - } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - TokenType = 'APP_ENT' - Target = 'Enterprise account' - Owner = 'msx' - OwnerType = 'enterprise' - ConnectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY - } - ConnectAppParams = @{ - Enterprise = 'msx' - } - } @{ AuthType = 'App' Type = 'a GitHub App from an Organization' @@ -97,3 +65,35 @@ } } ) +@{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org3' + } +} +@{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'enterprise account' + Owner = 'msx' + OwnerType = 'enterprise' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Enterprise = 'msx' + } +} diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0c2750c3e..762eab550 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -72,21 +72,21 @@ Describe 'Environments' { Write-Host ('-' * 60) } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10 LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -96,7 +96,7 @@ Describe 'Environments' { $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -104,7 +104,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -112,7 +112,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) @@ -120,29 +120,29 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) { { Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) { { Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 07059997c..82d074353 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -65,21 +65,17 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } - if ($OwnerType -ne 'user') { - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { - $members = Get-GitHubOrganizationMember -Organization $owner - LogGroup 'Members' { - Write-Host ($members | Select-Object * | Out-String) - } - $members | Should -Not -BeNullOrEmpty + It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' -Skip:($OwnerType -in ('user', 'enterprise')) { + $members = Get-GitHubOrganizationMember -Organization $owner + LogGroup 'Members' { + Write-Host ($members | Select-Object * | Out-String) } + $members | Should -Not -BeNullOrEmpty } # Tests for IAT UAT and PAT goes here - if ($OwnerType -eq 'user') { - It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' { - { Get-GitHubOrganization } | Should -Not -Throw - } + It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' -Skip:($OwnerType -in ('user')) { + { Get-GitHubOrganization } | Should -Not -Throw } if ($OwnerType -eq 'organization' -and $Type -ne 'GitHub Actions') { diff --git a/tests/Releases.Tests.ps1 b/tests/Releases.Tests.ps1 index bf6cec578..2837cabb6 100644 --- a/tests/Releases.Tests.ps1 +++ b/tests/Releases.Tests.ps1 @@ -78,7 +78,7 @@ Describe 'Releases' { Write-Host ('-' * 60) } - Context 'Releases' -Skip:($OwnerType -eq 'repository') { + Context 'Releases' -Skip:($OwnerType -in ('repository', 'enterprise')) { It 'New-GitHubRelease - Creates a new release' { $release = New-GitHubRelease -Owner $Owner -Repository $repo -Tag 'v1.0' -Latest LogGroup 'Release' { @@ -316,7 +316,7 @@ Describe 'Releases' { $notes.Notes | Should -Match $releaseTag } } - Context 'Release Assets' -Skip:($OwnerType -eq 'repository') { + Context 'Release Assets' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $testFolderGuid = [Guid]::NewGuid().ToString().Substring(0, 8) $testFolderName = "GHAssetTest-$testFolderGuid" diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 417b66faf..3605ea829 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -66,7 +66,7 @@ Describe 'Repositories' { Write-Host ('-' * 60) } - It 'New-GitHubRepository - Creates a new repository' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Creation' { $params = @{ Name = $repoName @@ -111,7 +111,7 @@ Describe 'Repositories' { $repo.IsArchived | Should -Be $false } } - It 'New-GitHubRepository - Creates a new repository with settings' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository with settings' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-settings" LogGroup 'Repository - Creation + Settings' { $params = @{ @@ -179,7 +179,7 @@ Describe 'Repositories' { $repo.Homepage | Should -Be 'https://example.com' } } - It 'New-GitHubRepository - Creates a new repository from a template' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository from a template' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-template" LogGroup 'Repository - Template' { $params = @{ @@ -228,7 +228,7 @@ Describe 'Repositories' { $repo.IsArchived | Should -Be $false } } - It 'New-GitHubRepository - Creates a new repository as a fork' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository as a fork' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-fork" LogGroup 'Repository - Fork' { $params = @{ @@ -297,7 +297,7 @@ Describe 'Repositories' { } $repos | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets a specific repository' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets a specific repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository' { switch ($OwnerType) { 'user' { @@ -311,7 +311,7 @@ Describe 'Repositories' { } $repo | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets repositories with properties' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with properties' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Property' { switch ($OwnerType) { 'user' { @@ -333,7 +333,7 @@ Describe 'Repositories' { $item.Owner | Should -BeNullOrEmpty } } - It 'Get-GitHubRepository - Gets repositories with additional properties' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with additional properties' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - AdditionalProperty' { switch ($OwnerType) { 'user' { @@ -349,7 +349,7 @@ Describe 'Repositories' { $repo.CreatedAt | Should -Not -BeNullOrEmpty $repo.UpdatedAt | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets repositories with properties - only name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with properties - only name' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Property' { switch ($OwnerType) { 'user' { @@ -386,7 +386,7 @@ Describe 'Repositories' { } $repos.Count | Should -BeGreaterThan 0 } - It 'Set-GitHubRepository - Updates an existing repository' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Updates an existing repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { $description = 'Updated description' LogGroup 'Repository - Set update' { switch ($OwnerType) { @@ -412,7 +412,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 2 } } - It 'Set-GitHubRepository - Creates a new repository when missing' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates a new repository when missing' -Skip:($OwnerType -in ('repository', 'enterprise')) { $newRepoName = "$repoName-new" LogGroup 'Repository - Set create' { switch ($OwnerType) { @@ -433,7 +433,7 @@ Describe 'Repositories' { $repo | Should -Not -BeNullOrEmpty } } - It 'Update-GitHubRepository - Renames a repository' -Skip:($OwnerType -eq 'repository') { + It 'Update-GitHubRepository - Renames a repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { $newName = "$repoName-newname" LogGroup 'Repository - Renamed' { switch ($OwnerType) { @@ -465,7 +465,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 8 } } - It 'Remove-GitHubRepository - Removes all repositories' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubRepository - Removes all repositories' -Skip:($OwnerType -in ('repository', 'enterprise')) { switch ($OwnerType) { 'user' { Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false @@ -476,7 +476,7 @@ Describe 'Repositories' { } } } - It 'Get-GitHubRepository - Gets none repositories after removal' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets none repositories after removal' -Skip:($OwnerType -in ('repository', 'enterprise')) { switch ($OwnerType) { 'user' { $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoName*" } @@ -490,7 +490,7 @@ Describe 'Repositories' { $repos | Should -BeNullOrEmpty } } - It 'Set-GitHubRepository - Creates and updates a repository from a template' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates and updates a repository from a template' -Skip:($OwnerType -in ('repository', 'enterprise')) { $templateRepoName = "$repoName-template" $templateParams = @{ Name = $templateRepoName @@ -541,7 +541,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 4 } } - It 'Set-GitHubRepository - Creates and updates a repository as a fork' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates and updates a repository as a fork' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-fork3" $forkParams = @{ Name = $name diff --git a/tests/Secrets.Tests.ps1 b/tests/Secrets.Tests.ps1 index 152145535..2384187ab 100644 --- a/tests/Secrets.Tests.ps1 +++ b/tests/Secrets.Tests.ps1 @@ -307,7 +307,7 @@ Describe 'Secrets' { } } - Context 'Repository' -Skip:($OwnerType -eq 'repository') { + Context 'Repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner @@ -420,7 +420,7 @@ Describe 'Secrets' { } } - Context 'Environment' -Skip:($OwnerType -eq 'repository') { + Context 'Environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 41107a50a..2b039ce31 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -328,7 +328,7 @@ Describe 'Variables' { } } - Context 'Repository' -Skip:($OwnerType -eq 'repository') { + Context 'Repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner @@ -447,7 +447,7 @@ Describe 'Variables' { } } - Context 'Environment' -Skip:($OwnerType -eq 'repository') { + Context 'Environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner From ace7d9b345fb8bf5f35a536fe433e5c0b4d9ce37 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 25 Jun 2025 21:16:20 +0200 Subject: [PATCH 17/17] [Fix]: Update Get-GitHubOrganization test to correctly skip based on owner type condition --- tests/Organizations.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 82d074353..32ddb2b28 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -74,7 +74,7 @@ Describe 'Organizations' { } # Tests for IAT UAT and PAT goes here - It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' -Skip:($OwnerType -in ('user')) { + It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' -Skip:($OwnerType -notin ('user')) { { Get-GitHubOrganization } | Should -Not -Throw }