Skip to content

Commit

Permalink
Get all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardWolosky committed Aug 12, 2020
1 parent 4e0b573 commit 90eca4e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 74 deletions.
35 changes: 5 additions & 30 deletions GitHubTeams.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ filter Set-GitHubTeam
[CmdletBinding(
SupportsShouldProcess,
PositionalBinding = $false,
DefaultParameterSetName = 'TeamSlug'
DefaultParameterSetName = 'ParentName'
)]
[OutputType( { $script:GitHubTeamTypeName } )]
param
Expand All @@ -582,33 +582,11 @@ filter Set-GitHubTeam
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
Position = 2,
ParameterSetName='TeamName')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
Position = 2,
ParameterSetName='TeamSlug')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
Position = 2,
ParameterSetName='ParentTeamId')]
Position = 2)]
[ValidateNotNullOrEmpty()]
[string] $TeamName,

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='TeamSlug')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='ParentTeamName')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='ParentTeamId')]
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[string] $TeamSlug,

Expand All @@ -617,13 +595,9 @@ filter Set-GitHubTeam
[ValidateSet('Secret','Closed')]
[string] $Privacy,

[Parameter(ParameterSetName='TeamName')]
[Parameter(ParameterSetName='TeamSlug')]
[Parameter(ParameterSetName='ParentTeamName')]
[string] $ParentTeamName,

[Parameter(ParameterSetName='TeamName')]
[Parameter(ParameterSetName='TeamSlug')]
[Parameter(ParameterSetName='ParentTeamId')]
[int64] $ParentTeamId,

Expand All @@ -638,7 +612,8 @@ filter Set-GitHubTeam
TeamName = (Get-PiiSafeString -PlainText $TeamName)
}

if ($PSBoundParameters.ContainsKey('TeamName') -or $PSBoundParameters.ContainsKey('ParentTeamName'))
if ((-not $PSBoundParameters.ContainsKey('TeamSlug')) -or
$PSBoundParameters.ContainsKey('ParentTeamName'))
{
$getGitHubTeamParms = @{
OrganizationName = $OrganizationName
Expand Down
104 changes: 60 additions & 44 deletions Tests/GitHubTeams.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ try
$childTeamName = [Guid]::NewGuid().Guid

$newGithubTeamParms = @{
OrganizationName = $organizationName
TeamName = $childTeamName
Privacy = $privacy
}
Expand Down Expand Up @@ -509,48 +508,6 @@ try
}
}

Context 'When specifying the "Organization" parameter through the pipeline' {
BeforeAll {
$teamName1 = [Guid]::NewGuid().Guid
$teamName2 = [Guid]::NewGuid().Guid

$newGithubTeamParms = @{
OrganizationName = $organizationName
TeamName = $teamName1
}

$team1 = New-GitHubTeam @newGithubTeamParms

$team2 = $team1 | New-GitHubTeam -TeamName $teamName2
}

It 'Should have the expected type and additional properties' {
$team2.PSObject.TypeNames[0] | Should -Be 'GitHub.Team'
$team2.name | Should -Be $teamName2
$team2.organization.login | Should -Be $organizationName
$team2.parent | Should -BeNullOrEmpty
$team2.created_at | Should -Not -BeNullOrEmpty
$team2.updated_at | Should -Not -BeNullOrEmpty
$team2.members_count | Should -Be 1
$team2.repos_count | Should -Be 0
$team2.TeamName | Should -Be $teamName2
$team2.TeamId | Should -Be $team2.id
$team2.OrganizationName | Should -Be $organizationName
}

AfterAll {
if (Get-Variable -Name team1 -ErrorAction SilentlyContinue)
{
$team1 | Remove-GitHubTeam -Force
}

if (Get-Variable -Name team2 -ErrorAction SilentlyContinue)
{
$team2 | Remove-GitHubTeam -Force
}
}
}

Context 'When specifying the "TeamName" parameter through the pipeline' {
BeforeAll {
$teamName = [Guid]::NewGuid().Guid
Expand Down Expand Up @@ -723,6 +680,65 @@ try
}
}

Context 'When updating a GitHub team to be a child using the Parent TeamId' {
BeforeAll {
$teamName = [Guid]::NewGuid().Guid
$parentTeamName = [Guid]::NewGuid().Guid
$description = 'Team Description'
$privacy = 'Closed'

$newGithubTeamParms = @{
OrganizationName = $organizationName
TeamName = $parentTeamName
Privacy = $privacy
}

$parentTeam = New-GitHubTeam @newGithubTeamParms

$newGithubTeamParms = @{
OrganizationName = $organizationName
TeamName = $teamName
Privacy = $privacy
}

$team = New-GitHubTeam @newGithubTeamParms

$updateGitHubTeamParms = @{
OrganizationName = $organizationName
TeamName = $teamName
Description = $description
Privacy = $privacy
ParentTeamId = $parentTeam.id
}

$updatedTeam = Set-GitHubTeam @updateGitHubTeamParms
}

It 'Should have the expected type and additional properties' {
$updatedTeam.PSObject.TypeNames[0] | Should -Be 'GitHub.Team'
$updatedTeam.name | Should -Be $teamName
$updatedTeam.organization.login | Should -Be $organizationName
$updatedTeam.description | Should -Be $description
$updatedTeam.parent.name | Should -Be $parentTeamName
$updatedTeam.privacy | Should -Be $privacy
$updatedTeam.TeamName | Should -Be $teamName
$updatedTeam.TeamId | Should -Be $team.id
$updatedTeam.OrganizationName | Should -Be $organizationName
}

AfterAll {
if (Get-Variable -Name team -ErrorAction SilentlyContinue)
{
$team | Remove-GitHubTeam -Force
}

if (Get-Variable -Name parentTeam -ErrorAction SilentlyContinue)
{
$parentTeam | Remove-GitHubTeam -Force
}
}
}

Context 'When specifying the "Organization" and "TeamName" parameters through the pipeline' {
BeforeAll {
$teamName = [Guid]::NewGuid().Guid
Expand All @@ -733,7 +749,7 @@ try
TeamName = $teamName
}

$team = New-GitHubTeam -OrganizationName $organizationName -TeamName $teamName
$team = New-GitHubTeam @newGithubTeamParms

$updatedTeam = $team | Set-GitHubTeam -Description $description
}
Expand Down

0 comments on commit 90eca4e

Please sign in to comment.