PowerShellForGitHub/Tests/GitHubProjectCards.tests.ps1

255 строки
8.3 KiB
PowerShell
Исходник Обычный вид История

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.Synopsis
Tests for GitHubProjectCards.ps1 module
#>
# This is common test code setup logic for all Pester test files
$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1')
try
{
# Define Script-scoped, readOnly, hidden variables.
@{
defaultProject = "TestProject_$([Guid]::NewGuid().Guid)"
defaultColumn = "TestColumn"
defaultColumnTwo = "TestColumnTwo"
defaultCard = "TestCard"
defaultCardTwo = "TestCardTwo"
defaultCardUpdated = "TestCard_Updated"
defaultArchivedCard = "TestCard_Archived"
defaultIssue = "TestIssue"
}.GetEnumerator() | ForEach-Object {
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
}
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
$project = New-GitHubProject -Owner $script:ownerName -Repository $repo.name -Name $defaultProject
$column = New-GitHubProjectColumn -Project $project.id -Name $defaultColumn
$columntwo = New-GitHubProjectColumn -Project $project.id -Name $defaultColumnTwo
$issue = New-GitHubIssue -Owner $script:ownerName -RepositoryName $repo.name -Title $defaultIssue
Describe 'Getting Project Cards' {
BeforeAll {
$card = New-GitHubProjectCard -Column $column.id -Note $defaultCard
$cardArchived = New-GitHubProjectCard -Column $column.id -Note $defaultArchivedCard
$null = Set-GitHubProjectCard -Card $cardArchived.id -Archive
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$card = $card
$cardArchived = $cardArchived
}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
AfterAll {
$null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false
}
Context 'Get cards for a column' {
$results = Get-GitHubProjectCard -Column $column.id
It 'Should get cards' {
$results | Should Not BeNullOrEmpty
}
It 'Note is correct' {
$results.note | Should be $defaultCard
}
}
Context 'Get all cards for a column' {
$results = Get-GitHubProjectCard -Column $column.id -ArchivedState All
It 'Should get all cards' {
$results.Count | Should Be 2
}
}
Context 'Get archived cards for a column' {
$results = Get-GitHubProjectCard -Column $column.id -ArchivedState Archived
It 'Should get archived card' {
$results | Should Not BeNullOrEmpty
}
It 'Note is correct' {
$results.note | Should be $defaultArchivedCard
}
It 'Should be archived' {
$results.Archived | Should be $true
}
}
}
Describe 'Modify card' {
BeforeAll {
$card = New-GitHubProjectCard -Column $column.id -Note $defaultCard
$cardTwo = New-GitHubProjectCard -Column $column.id -Note $defaultCardTwo
$cardArchived = New-GitHubProjectCard -Column $column.id -Note $defaultArchivedCard
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$card = $card
$cardTwo = $cardTwo
$cardArchived = $cardArchived
}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
AfterAll {
$null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false
}
Context 'Modify card note' {
$null = Set-GitHubProjectCard -Card $card.id -Note $defaultCardUpdated
$results = Get-GitHubProjectCard -Card $card.id
It 'Should get card' {
$results | Should Not BeNullOrEmpty
}
It 'Note has been updated' {
$results.note | Should be $defaultCardUpdated
}
}
Context 'Archive a card' {
$null = Set-GitHubProjectCard -Card $cardArchived.id -Archive
$results = Get-GitHubProjectCard -Card $cardArchived.id
It 'Should get card' {
$results | Should Not BeNullOrEmpty
}
It 'Card is archived' {
$results.Archived | Should be $true
}
}
Context 'Restore a card' {
$null = Set-GitHubProjectCard -Card $cardArchived.id -Restore
$results = Get-GitHubProjectCard -Card $cardArchived.id
It 'Should get card' {
$results | Should Not BeNullOrEmpty
}
It 'Card is not archived' {
$results.Archived | Should be $false
}
}
Context 'Move card position within column' {
$null = Move-GitHubProjectCard -Card $cardTwo.id -Top
$results = Get-GitHubProjectCard -Column $column.id
It 'Card is now top' {
$results[0].note | Should be $defaultCardTwo
}
}
Context 'Move card using after parameter' {
$null = Move-GitHubProjectCard -Card $cardTwo.id -After $card.id
$results = Get-GitHubProjectCard -Column $column.id
It 'Card now exists in new column' {
$results[1].note | Should be $defaultCardTwo
}
}
Context 'Move card to another column' {
$null = Move-GitHubProjectCard -Card $cardTwo.id -Top -ColumnId $columnTwo.id
$results = Get-GitHubProjectCard -Column $columnTwo.id
It 'Card now exists in new column' {
$results[0].note | Should be $defaultCardTwo
}
}
Context 'Move command throws appropriate error' {
It 'Appropriate error is thrown' {
{ Move-GitHubProjectCard -Card $cardTwo.id -Top -Bottom } | Should Throw 'You must use one (and only one) of the parameters Top, Bottom or After.'
}
}
}
Describe 'Create Project Cards' -tag new {
Context 'Create project card with note' {
BeforeAll {
$card = @{id = 0}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$card = $card
}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
AfterAll {
$null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false
Remove-Variable -Name card
}
$card.id = (New-GitHubProjectCard -Column $column.id -Note $defaultCard).id
$results = Get-GitHubProjectCard -Card $card.id
It 'Card exists' {
$results | Should Not BeNullOrEmpty
}
It 'Note is correct' {
$results.note | Should be $defaultCard
}
}
Context 'Create project card from issue' {
BeforeAll {
$card = @{id = 0}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$card = $card
}
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
AfterAll {
$null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false
Remove-Variable -Name card
}
$card.id = (New-GitHubProjectCard -Column $column.id -ContentId $issue.id -ContentType 'Issue').id
$results = Get-GitHubProjectCard -Card $card.id
It 'Card exists' {
$results | Should Not BeNullOrEmpty
}
It 'Content url is for an issue' {
$results.content_url | Should match 'issues'
}
}
}
Describe 'Remove card' {
Context 'Remove card' {
BeforeAll {
$card = New-GitHubProjectCard -Column $column.id -Note $defaultCard
Get PSScriptAnalyzer clean again (#180) Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
2020-05-26 18:01:17 +03:00
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$card = $card
}
$null = Remove-GitHubProjectCard -Card $card.id -Confirm:$false
It 'Project card should be removed' {
{Get-GitHubProjectCard -Card $card.id} | Should Throw
}
}
}
Remove-GitHubProject -Project $project.id -Confirm:$false
}
finally
{
if (Test-Path -Path $script:originalConfigFile -PathType Leaf)
{
# Restore the user's configuration to its pre-test state
Restore-GitHubConfiguration -Path $script:originalConfigFile
$script:originalConfigFile = $null
}
}