Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joseartrivera committed Dec 4, 2018
1 parent 0f9190a commit 59e4f59
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
25 changes: 20 additions & 5 deletions GitHubLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -676,8 +689,10 @@ function Add-GitHubLabel
ParameterSetName='Uri')]
[string] $Uri,

[Parameter(Mandatory)]
[int] $Issue,

[Parameter(Mandatory)]
[string[]] $Labels,

[switch] $Replace,
Expand Down
1 change: 1 addition & 0 deletions PowerShellForGitHub.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

# Functions to export from this module
FunctionsToExport = @(
'Add-GitHubLabel',
'Backup-GitHubConfiguration',
'Clear-GitHubAuthentication',
'ConvertFrom-Markdown',
Expand Down
54 changes: 54 additions & 0 deletions Tests/GitHubLabels.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59e4f59

Please sign in to comment.