diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index f1724248..4bad710c 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -70,297 +70,305 @@ if (-not $script:accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile -Backup-GitHubConfiguration -Path $configFile -Reset-GitHubConfiguration -Describe 'Obtaining issues for repository' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit +try +{ + Backup-GitHubConfiguration -Path $configFile + Reset-GitHubConfiguration + Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures + + Describe 'Obtaining issues for repository' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there are no issues' { - $issues = Get-GitHubIssue -Uri $repo.svn_url + Context 'When initially created, there are no issues' { + $issues = Get-GitHubIssue -Uri $repo.svn_url - It 'Should return expected number of issues' { - @($issues).Count | Should be 0 + It 'Should return expected number of issues' { + @($issues).Count | Should be 0 + } } - } - Context 'When there are issues present' { - $newIssues = @() - for ($i = 0; $i -lt 4; $i++) - { - $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) - Start-Sleep -Seconds 5 + Context 'When there are issues present' { + $newIssues = @() + for ($i = 0; $i -lt 4; $i++) + { + $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) + Start-Sleep -Seconds 5 + } + + $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State closed + $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State closed + + $issues = Get-GitHubIssue -Uri $repo.svn_url + It 'Should return only open issues' { + @($issues).Count | Should be 2 + } + + $issues = Get-GitHubIssue -Uri $repo.svn_url -State all + It 'Should return all issues' { + @($issues).Count | Should be 4 + } + + $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at + $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at + $issues = (Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) } + + It 'Smart object date conversion works for comparing dates' { + @($issues).Count | Should be 2 + } + + $createdDate = Get-Date -Date $newIssues[1].created_at + $issues = Get-GitHubIssue -Uri $repo.svn_url -State all | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') } + + It 'Able to filter based on date and state' { + @($issues).Count | Should be 1 + } } - $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State closed - $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State closed + $null = Remove-GitHubRepository -Uri ($repo.svn_url) + } - $issues = Get-GitHubIssue -Uri $repo.svn_url - It 'Should return only open issues' { - @($issues).Count | Should be 2 + Describe 'Obtaining repository with biggest number of issues' { + $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + + Context 'When no addional conditions specified' { + for ($i = 0; $i -lt 3; $i++) + { + $null = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo1.name -Title ([guid]::NewGuid().Guid) + } + + $repos = @(($repo1.svn_url), ($repo2.svn_url)) + $issueCounts = @() + $repos | ForEach-Object { $issueCounts = $issueCounts + ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_).Count }) } + $issueCounts = $issueCounts | Sort-Object -Property Count -Descending + + It 'Should return expected number of issues for each repository' { + @($issueCounts[0].Count) | Should be 3 + @($issueCounts[1].Count) | Should be 0 + } + + It 'Should return expected repository names' { + @($issueCounts[0].Uri) | Should be ($repo1.svn_url) + @($issueCounts[1].Uri) | Should be ($repo2.svn_url) + } } - $issues = Get-GitHubIssue -Uri $repo.svn_url -State all - It 'Should return all issues' { - @($issues).Count | Should be 4 - } + $null = Remove-GitHubRepository -Uri ($repo1.svn_url) + $null = Remove-GitHubRepository -Uri ($repo2.svn_url) + } - $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at - $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at - $issues = (Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) } - It 'Smart object date conversion works for comparing dates' { - @($issues).Count | Should be 2 - } + # TODO: Re-enable these tests once the module has sufficient support getting the repository into the + # required state for testing, and to recover back to the original state at the conclusion of the test. - $createdDate = Get-Date -Date $newIssues[1].created_at - $issues = Get-GitHubIssue -Uri $repo.svn_url -State all | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') } + # Describe 'Obtaining pull requests for repository' { + # Context 'When no addional conditions specified' { + # $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl - It 'Able to filter based on date and state' { - @($issues).Count | Should be 1 - } - } + # It 'Should return expected number of PRs' { + # @($pullRequests).Count | Should be 2 + # } + # } - $null = Remove-GitHubRepository -Uri ($repo.svn_url) -} + # Context 'When state and time range specified' { + # $mergedStartDate = Get-Date -Date '2016-04-10' + # $mergedEndDate = Get-Date -Date '2016-05-07' + # $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl -State closed | + # Where-Object { ($_.merged_at -ge $mergedStartDate) -and ($_.merged_at -le $mergedEndDate) } + + # It 'Should return expected number of PRs' { + # @($pullRequests).Count | Should be 3 + # } + # } + # } -Describe 'Obtaining repository with biggest number of issues' { - $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + # Describe 'Obtaining repository with biggest number of pull requests' { + # Context 'When no addional conditions specified' { + # @($script:repositoryUrl, $script:repositoryUrl2) | + # ForEach-Object { + # $pullRequestCounts += ([PSCustomObject]@{ + # 'Uri' = $_; + # 'Count' = (Get-GitHubPullRequest -Uri $_).Count }) } + # $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending + + # It 'Should return expected number of pull requests for each repository' { + # @($pullRequestCounts[0].Count) | Should be 2 + # @($pullRequestCounts[1].Count) | Should be 0 + # } + + # It 'Should return expected repository names' { + # @($pullRequestCounts[0].Uri) | Should be $script:repositoryUrl + # @($pullRequestCounts[1].Uri) | Should be $script:repositoryUrl2 + # } + # } - Context 'When no addional conditions specified' { - for ($i = 0; $i -lt 3; $i++) - { - $null = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo1.name -Title ([guid]::NewGuid().Guid) - } + # Context 'When state and time range specified' { + # $mergedDate = Get-Date -Date '2015-04-20' + # $repos = @($script:repositoryUrl, $script:repositoryUrl2) + # $pullRequestCounts = @() + # $pullRequestSearchParams = @{ + # 'State' = 'closed' + # } + # $repos | + # ForEach-Object { + # $pullRequestCounts += ([PSCustomObject]@{ + # 'Uri' = $_; + # 'Count' = ( + # (Get-GitHubPullRequest -Uri $_ @pullRequestSearchParams) | + # Where-Object { $_.merged_at -ge $mergedDate } + # ).Count + # }) } + + # $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending + # $pullRequests = Get-GitHubTopPullRequestRepository -Uri @($script:repositoryUrl, $script:repositoryUrl2) -State closed -MergedOnOrAfter + + # It 'Should return expected number of pull requests for each repository' { + # @($pullRequests[0].Count) | Should be 3 + # @($pullRequests[1].Count) | Should be 0 + # } + + # It 'Should return expected repository names' { + # @($pullRequests[0].Uri) | Should be $script:repositoryUrl + # @($pullRequests[1].Uri) | Should be $script:repositoryUrl2 + # } + # } + # } - $repos = @(($repo1.svn_url), ($repo2.svn_url)) - $issueCounts = @() - $repos | ForEach-Object { $issueCounts = $issueCounts + ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_).Count }) } - $issueCounts = $issueCounts | Sort-Object -Property Count -Descending + if ($script:accessTokenConfigured) + { + Describe 'Obtaining collaborators for repository' { + $repositoryName = [guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - It 'Should return expected number of issues for each repository' { - @($issueCounts[0].Count) | Should be 3 - @($issueCounts[1].Count) | Should be 0 - } + $collaborators = Get-GitHubRepositoryCollaborator -Uri $repositoryUrl - It 'Should return expected repository names' { - @($issueCounts[0].Uri) | Should be ($repo1.svn_url) - @($issueCounts[1].Uri) | Should be ($repo2.svn_url) + It 'Should return expected number of collaborators' { + @($collaborators).Count | Should be 1 + } + + $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName } } - $null = Remove-GitHubRepository -Uri ($repo1.svn_url) - $null = Remove-GitHubRepository -Uri ($repo2.svn_url) -} - - -# TODO: Re-enable these tests once the module has sufficient support getting the repository into the -# required state for testing, and to recover back to the original state at the conclusion of the test. - -# Describe 'Obtaining pull requests for repository' { -# Context 'When no addional conditions specified' { -# $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl - -# It 'Should return expected number of PRs' { -# @($pullRequests).Count | Should be 2 -# } -# } - -# Context 'When state and time range specified' { -# $mergedStartDate = Get-Date -Date '2016-04-10' -# $mergedEndDate = Get-Date -Date '2016-05-07' -# $pullRequests = Get-GitHubPullRequest -Uri $script:repositoryUrl -State closed | -# Where-Object { ($_.merged_at -ge $mergedStartDate) -and ($_.merged_at -le $mergedEndDate) } - -# It 'Should return expected number of PRs' { -# @($pullRequests).Count | Should be 3 -# } -# } -# } - -# Describe 'Obtaining repository with biggest number of pull requests' { -# Context 'When no addional conditions specified' { -# @($script:repositoryUrl, $script:repositoryUrl2) | -# ForEach-Object { -# $pullRequestCounts += ([PSCustomObject]@{ -# 'Uri' = $_; -# 'Count' = (Get-GitHubPullRequest -Uri $_).Count }) } -# $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending - -# It 'Should return expected number of pull requests for each repository' { -# @($pullRequestCounts[0].Count) | Should be 2 -# @($pullRequestCounts[1].Count) | Should be 0 -# } - -# It 'Should return expected repository names' { -# @($pullRequestCounts[0].Uri) | Should be $script:repositoryUrl -# @($pullRequestCounts[1].Uri) | Should be $script:repositoryUrl2 -# } -# } - -# Context 'When state and time range specified' { -# $mergedDate = Get-Date -Date '2015-04-20' -# $repos = @($script:repositoryUrl, $script:repositoryUrl2) -# $pullRequestCounts = @() -# $pullRequestSearchParams = @{ -# 'State' = 'closed' -# } -# $repos | -# ForEach-Object { -# $pullRequestCounts += ([PSCustomObject]@{ -# 'Uri' = $_; -# 'Count' = ( -# (Get-GitHubPullRequest -Uri $_ @pullRequestSearchParams) | -# Where-Object { $_.merged_at -ge $mergedDate } -# ).Count -# }) } - -# $pullRequestCounts = $pullRequestCounts | Sort-Object -Property Count -Descending -# $pullRequests = Get-GitHubTopPullRequestRepository -Uri @($script:repositoryUrl, $script:repositoryUrl2) -State closed -MergedOnOrAfter - -# It 'Should return expected number of pull requests for each repository' { -# @($pullRequests[0].Count) | Should be 3 -# @($pullRequests[1].Count) | Should be 0 -# } - -# It 'Should return expected repository names' { -# @($pullRequests[0].Uri) | Should be $script:repositoryUrl -# @($pullRequests[1].Uri) | Should be $script:repositoryUrl2 -# } -# } -# } - -if ($script:accessTokenConfigured) -{ - Describe 'Obtaining collaborators for repository' { + Describe 'Obtaining contributors for repository' { $repositoryName = [guid]::NewGuid().Guid $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - $collaborators = Get-GitHubRepositoryCollaborator -Uri $repositoryUrl + $contributors = Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics - It 'Should return expected number of collaborators' { - @($collaborators).Count | Should be 1 + It 'Should return expected number of contributors' { + @($contributors).Count | Should be 1 } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName } -} -Describe 'Obtaining contributors for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - - $contributors = Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics - - It 'Should return expected number of contributors' { - @($contributors).Count | Should be 1 - } + if ($script:accessTokenConfigured) + { + # TODO: Re-enable these tests once the module has sufficient support getting the Organization + # and repository into the required state for testing, and to recover back to the original state + # at the conclusion of the test. - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -} + # Describe 'Obtaining organization members' { + # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName -if ($script:accessTokenConfigured) -{ - # TODO: Re-enable these tests once the module has sufficient support getting the Organization - # and repository into the required state for testing, and to recover back to the original state - # at the conclusion of the test. + # It 'Should return expected number of organization members' { + # @($members).Count | Should be 1 + # } + # } - # Describe 'Obtaining organization members' { - # $members = Get-GitHubOrganizationMember -OrganizationName $script:organizationName + # Describe 'Obtaining organization teams' { + # $teams = Get-GitHubTeam -OrganizationName $script:organizationName - # It 'Should return expected number of organization members' { - # @($members).Count | Should be 1 - # } - # } + # It 'Should return expected number of organization teams' { + # @($teams).Count | Should be 2 + # } + # } - # Describe 'Obtaining organization teams' { - # $teams = Get-GitHubTeam -OrganizationName $script:organizationName + # Describe 'Obtaining organization team members' { + # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName - # It 'Should return expected number of organization teams' { - # @($teams).Count | Should be 2 - # } - # } + # It 'Should return expected number of organization team members' { + # @($members).Count | Should be 1 + # } + # } + } - # Describe 'Obtaining organization team members' { - # $members = Get-GitHubTeamMember -OrganizationName $script:organizationName -TeamName $script:organizationTeamName + Describe 'Getting repositories from organization' { + $original = Get-GitHubRepository -OrganizationName $script:organizationName - # It 'Should return expected number of organization team members' { - # @($members).Count | Should be 1 - # } - # } -} - -Describe 'Getting repositories from organization' { - $original = Get-GitHubRepository -OrganizationName $script:organizationName + $repositoryName = [guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName -OrganizationName $script:organizationName + $current = Get-GitHubRepository -OrganizationName $script:organizationName - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -OrganizationName $script:organizationName - $current = Get-GitHubRepository -OrganizationName $script:organizationName + It 'Should return expected number of organization repositories' { + (@($current).Count - @($original).Count) | Should be 1 + } - It 'Should return expected number of organization repositories' { - (@($current).Count - @($original).Count) | Should be 1 + $null = Remove-GitHubRepository -OwnerName $script:organizationName -RepositoryName $repositoryName } - $null = Remove-GitHubRepository -OwnerName $script:organizationName -RepositoryName $repositoryName -} + Describe 'Getting unique contributors from contributors array' { + $repositoryName = [guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit -Describe 'Getting unique contributors from contributors array' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + $contributors = Get-GitHubRepositoryContributor -OwnerName $script:ownerName -RepositoryName $repositoryName -IncludeStatistics - $contributors = Get-GitHubRepositoryContributor -OwnerName $script:ownerName -RepositoryName $repositoryName -IncludeStatistics + $uniqueContributors = $contributors | + Select-Object -ExpandProperty author | + Select-Object -ExpandProperty login -Unique + Sort-Object - $uniqueContributors = $contributors | - Select-Object -ExpandProperty author | - Select-Object -ExpandProperty login -Unique - Sort-Object + It 'Should return expected number of unique contributors' { + @($uniqueContributors).Count | Should be 1 + } - It 'Should return expected number of unique contributors' { - @($uniqueContributors).Count | Should be 1 + $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName } - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -} - -Describe 'Getting repository name from url' { - $repositoryName = [guid]::NewGuid().Guid - $url = "https://github.com/$script:ownerName/$repositoryName" - $name = Split-GitHubUri -Uri $url -RepositoryName + Describe 'Getting repository name from url' { + $repositoryName = [guid]::NewGuid().Guid + $url = "https://github.com/$script:ownerName/$repositoryName" + $name = Split-GitHubUri -Uri $url -RepositoryName - It 'Should return expected repository name' { - $name | Should be $repositoryName + It 'Should return expected repository name' { + $name | Should be $repositoryName + } } -} -Describe 'Getting repository owner from url' { - $repositoryName = [guid]::NewGuid().Guid - $url = "https://github.com/$script:ownerName/$repositoryName" - $owner = Split-GitHubUri -Uri $url -OwnerName + Describe 'Getting repository owner from url' { + $repositoryName = [guid]::NewGuid().Guid + $url = "https://github.com/$script:ownerName/$repositoryName" + $owner = Split-GitHubUri -Uri $url -OwnerName - It 'Should return expected repository owner' { - $owner | Should be $script:ownerName + It 'Should return expected repository owner' { + $owner | Should be $script:ownerName + } } -} -Describe 'Getting branches for repository' { - $repositoryName = [guid]::NewGuid().Guid - $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit + Describe 'Getting branches for repository' { + $repositoryName = [guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $branches = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName + $branches = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName - It 'Should return expected number of repository branches' { - @($branches).Count | Should be 1 - } + It 'Should return expected number of repository branches' { + @($branches).Count | Should be 1 + } - It 'Should return the name of the branches' { - @($branches[0].name) | Should be "master" - } + It 'Should return the name of the branches' { + @($branches[0].name) | Should be "master" + } - $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName + $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName + } +} +finally +{ + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $configFile } - -# Restore the user's configuration to its pre-test state -Restore-GitHubConfiguration -Path $configFile diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index b88516ac..5bf035a5 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -70,11 +70,13 @@ if (-not $script:accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile + try { Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $issue = New-GitHubIssue -Uri $repo.svn_url -Title "Test issue" diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index c7ec7a34..1461bcec 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -75,6 +75,7 @@ try Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures # Define Script-scoped, readonly, hidden variables. diff --git a/Tests/GitHubCore.Tests.ps1 b/Tests/GitHubCore.Tests.ps1 index d806e43e..93159a9d 100644 --- a/Tests/GitHubCore.Tests.ps1 +++ b/Tests/GitHubCore.Tests.ps1 @@ -67,14 +67,16 @@ if (-not $script:accessTokenConfigured) Write-Warning -Message ($message -join [Environment]::NewLine) } +# Backup the user's configuration before we begin, and ensure we're at a pure state before running +# the tests. We'll restore it at the end. +$configFile = New-TemporaryFile + try { - # Backup the user's configuration before we begin, and ensure we're at a pure state before running - # the tests. We'll restore it at the end. - $configFile = New-TemporaryFile Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures Describe 'Testing ConvertTo-SmarterObject behavior' { InModuleScope PowerShellForGitHub { diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index c7fecb6d..51070522 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -75,6 +75,8 @@ try { Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration + Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures if ($accessTokenConfigured) { diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index aaa8ed9d..d081b71d 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -70,10 +70,13 @@ if (-not $accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile + try { Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration + Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures $defaultLabels = @( @{ @@ -300,6 +303,23 @@ try $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName } + + Describe 'Creating a new Issue with labels' { + $repositoryName = [Guid]::NewGuid().Guid + $null = New-GitHubRepository -RepositoryName $repositoryName + Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels + + $issueName = [Guid]::NewGuid().Guid + $issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name) + $issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels + + It 'Should return the number of labels that were just added' { + $issue.labels.Count | Should be $issueLabels.Count + } + + $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName + } + Describe 'Removing labels on an issue'{ $repositoryName = [Guid]::NewGuid().Guid $null = New-GitHubRepository -RepositoryName $repositoryName diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index ad433ca6..93729b85 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -70,11 +70,13 @@ if (-not $script:accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile + try { Backup-GitHubConfiguration -Path $configFile Reset-GitHubConfiguration Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures # Define Script-scoped, readonly, hidden variables. diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index 4b2da7fe..9ee3c1c2 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -70,46 +70,54 @@ if (-not $script:accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile -Backup-GitHubConfiguration -Path $configFile -Reset-GitHubConfiguration -Describe 'Creating a new fork for user' { - $originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub +try +{ + Backup-GitHubConfiguration -Path $configFile + Reset-GitHubConfiguration + Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures - Context 'When a new fork is created' { - $repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub - $newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest + Describe 'Creating a new fork for user' { + $originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub - It 'Should have one more fork than before' { - (@($newForks).Count - @($originalForks).Count) | Should be 1 - } + Context 'When a new fork is created' { + $repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub + $newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest - It 'Should be the latest fork in the list' { - $newForks[0].full_name | Should be "$($script:ownerName)/PowerShellForGitHub" - } + It 'Should have one more fork than before' { + (@($newForks).Count - @($originalForks).Count) | Should be 1 + } - Remove-GitHubRepository -Uri $repo.svn_url + It 'Should be the latest fork in the list' { + $newForks[0].full_name | Should be "$($script:ownerName)/PowerShellForGitHub" + } + + Remove-GitHubRepository -Uri $repo.svn_url + } } -} -Describe 'Creating a new fork for an org' { - $originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub + Describe 'Creating a new fork for an org' { + $originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub - Context 'When a new fork is created' { - $repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName - $newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest + Context 'When a new fork is created' { + $repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName + $newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest - It 'Should have one more fork than before' { - (@($newForks).Count - @($originalForks).Count) | Should be 1 - } + It 'Should have one more fork than before' { + (@($newForks).Count - @($originalForks).Count) | Should be 1 + } - It 'Should be the latest fork in the list' { - $newForks[0].full_name | Should be "$($script:organizationName)/PowerShellForGitHub" - } + It 'Should be the latest fork in the list' { + $newForks[0].full_name | Should be "$($script:organizationName)/PowerShellForGitHub" + } - Remove-GitHubRepository -Uri $repo.svn_url + Remove-GitHubRepository -Uri $repo.svn_url + } } } - -# Restore the user's configuration to its pre-test state -Restore-GitHubConfiguration -Path $configFile +finally +{ + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $configFile +} diff --git a/Tests/GitHubRepositoryTraffic.tests.ps1 b/Tests/GitHubRepositoryTraffic.tests.ps1 index e4b4eeb3..fd9e4530 100644 --- a/Tests/GitHubRepositoryTraffic.tests.ps1 +++ b/Tests/GitHubRepositoryTraffic.tests.ps1 @@ -70,64 +70,72 @@ if (-not $script:accessTokenConfigured) # Backup the user's configuration before we begin, and ensure we're at a pure state before running # the tests. We'll restore it at the end. $configFile = New-TemporaryFile -Backup-GitHubConfiguration -Path $configFile -Reset-GitHubConfiguration -Describe 'Getting the referrer list' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit +try +{ + Backup-GitHubConfiguration -Path $configFile + Reset-GitHubConfiguration + Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry + Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures - Context 'When initially created, there are no referrers' { - $referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url + Describe 'Getting the referrer list' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - It 'Should return expected number of referrers' { - @($referrerList).Count | Should be 0 - } + Context 'When initially created, there are no referrers' { + $referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url - Remove-GitHubRepository -Uri $repo.svn_url + It 'Should return expected number of referrers' { + @($referrerList).Count | Should be 0 + } + + Remove-GitHubRepository -Uri $repo.svn_url + } } -} -Describe 'Getting the popular content over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Getting the popular content over the last 14 days' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there are is no popular content' { - $pathList = Get-GitHubPathTraffic -Uri $repo.svn_url + Context 'When initially created, there are is no popular content' { + $pathList = Get-GitHubPathTraffic -Uri $repo.svn_url - It 'Should return expected number of popular content' { - @($pathList).Count | Should be 0 - } + It 'Should return expected number of popular content' { + @($pathList).Count | Should be 0 + } - Remove-GitHubRepository -Uri $repo.svn_url + Remove-GitHubRepository -Uri $repo.svn_url + } } -} -Describe 'Getting the views over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Getting the views over the last 14 days' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there are no views' { - $viewList = Get-GitHubViewTraffic -Uri $repo.svn_url + Context 'When initially created, there are no views' { + $viewList = Get-GitHubViewTraffic -Uri $repo.svn_url - It 'Should return 0 in the count property' { - $viewList.Count | Should be 0 - } + It 'Should return 0 in the count property' { + $viewList.Count | Should be 0 + } - Remove-GitHubRepository -Uri $repo.svn_url + Remove-GitHubRepository -Uri $repo.svn_url + } } -} -Describe 'Getting the clones over the last 14 days' { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit + Describe 'Getting the clones over the last 14 days' { + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - Context 'When initially created, there is 0 clones' { - $cloneList = Get-GitHubCloneTraffic -Uri $repo.svn_url + Context 'When initially created, there is 0 clones' { + $cloneList = Get-GitHubCloneTraffic -Uri $repo.svn_url - It 'Should return expected number of clones' { - $cloneList.Count | Should be 0 - } + It 'Should return expected number of clones' { + $cloneList.Count | Should be 0 + } - Remove-GitHubRepository -Uri $repo.svn_url + Remove-GitHubRepository -Uri $repo.svn_url + } } } - -# Restore the user's configuration to its pre-test state -Restore-GitHubConfiguration -Path $configFile +finally +{ + # Restore the user's configuration to its pre-test state + Restore-GitHubConfiguration -Path $configFile +}