From 59e4f596bdb20714d74638f090271ad9f449f493 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Mon, 3 Dec 2018 16:24:17 -0800 Subject: [PATCH] Add tests --- GitHubLabels.ps1 | 25 +++++++++++++---- PowerShellForGitHub.psd1 | 1 + Tests/GitHubLabels.tests.ps1 | 54 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 78638cd8..48208e13 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -61,22 +61,35 @@ function Get-GitHubLabel DefaultParametersetName='Elements')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( - [Parameter(ParameterSetName='Elements')] + [Parameter(Mandatory,ParameterSetName='Elements')] + [Parameter(Mandatory,ParameterSetName='NameElements')] + [Parameter(Mandatory,ParameterSetName='IssueElements')] + [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [string] $OwnerName, - [Parameter(ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='Elements')] + [Parameter(Mandatory, ParameterSetName='NameElements')] + [Parameter(Mandatory, ParameterSetName='IssueElements')] + [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [string] $RepositoryName, - [Parameter( - Mandatory, - ParameterSetName='Uri')] + [Parameter(Mandatory, ParameterSetName='Uri')] + [Parameter(Mandatory, ParameterSetName='NameUri')] + [Parameter(Mandatory, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ParameterSetName='MilestoneUri')] [string] $Uri, + [Parameter(Mandatory, ParameterSetName='NameUri')] + [Parameter(Mandatory, ParameterSetName='NameElements')] [Alias('LabelName')] [string] $Name, + [Parameter(Mandatory, ParameterSetName='IssueUri')] + [Parameter(Mandatory, ParameterSetName='IssueElements')] [int] $Issue, + [Parameter(Mandatory, ParameterSetName='MilestoneUri')] + [Parameter(Mandatory, ParameterSetName='MilestoneElements')] [int] $Milestone, [string] $AccessToken, @@ -676,8 +689,10 @@ function Add-GitHubLabel ParameterSetName='Uri')] [string] $Uri, + [Parameter(Mandatory)] [int] $Issue, + [Parameter(Mandatory)] [string[]] $Labels, [switch] $Replace, diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index fb44f43f..644839b6 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -42,6 +42,7 @@ # Functions to export from this module FunctionsToExport = @( + 'Add-GitHubLabel', 'Backup-GitHubConfiguration', 'Clear-GitHubAuthentication', 'ConvertFrom-Markdown', diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 5f7a3dff..3b746535 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -271,6 +271,60 @@ if ($script:accessTokenConfigured) $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName } + + Describe 'Adding and removing labels to an issue'{ + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $script:defaultLabels + + $issueName = [Guid]::NewGuid().Guid + $issue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repositoryName -Title $issueName + + Context 'Adding labels to an issue' { + $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', + 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + $addedLabels = @(Add-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $labelsToAdd) + + It 'Should return the expected number of labels' { + $addedLabels.Count | Should be $script:defaultLabels.Count + } + + $labelIssues = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number + + It 'Should have added the expected number of labels' { + $labelIssues.Count | Should be $script:defaultLabels.Count + } + } + + Context 'Removing labels from an issue' { + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Name "discussion" -Issue $issue.number + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Name "question" -Issue $issue.number + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Name "bug" -Issue $issue.number + $labelIssues = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number + + It 'Should have added the expected number of labels' { + $labelIssues.Count | Should be ($script:defaultLabels.Count - 3) + } + } + + Context 'Replacing labels on an issue' { + $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', + 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') + + $addedLabels = @(Add-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $labelsToAdd -Replace) + + It 'Should return the expected number of labels' { + $addedLabels.Count | Should be $script:defaultLabels.Count + } + + $labelIssues = Get-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue $issue.number + + It 'Should have added the expected number of labels' { + $labelIssues.Count | Should be $script:defaultLabels.Count + } + } + + } } # Restore the user's configuration to its pre-test state