Skip to content

Commit

Permalink
Tests for single user ID input added
Browse files Browse the repository at this point in the history
  • Loading branch information
karthickgandhiTV committed Jul 20, 2023
1 parent 67b6ea0 commit a0442bf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions TeamViewerPS/Private/Resolve-TeamViewerUserGroupMemberId.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function Resolve-TeamViewerUserGroupMemberMemberId {
elseif ($UserGroupMember -match 'u[0-9]+') {
return $UserGroupMember
}
elseif ($UserGroupMember -is [string]) {
return [int]$UserGroupMember
}
elseif ($UserGroupMember -is [int]) {
return $UserGroupMember
}
Expand Down
2 changes: 1 addition & 1 deletion TeamViewerPS/TeamViewerPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'TeamViewerPS.psm1'

# Version number of this module.
ModuleVersion = '1.5.0'
ModuleVersion = '1.5.1'

# Supported PSEditions.
# CompatiblePSEditions = @()
Expand Down
21 changes: 17 additions & 4 deletions Tests/Public/Add-TeamViewerUserGroupMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ BeforeAll {
$null = $testApiToken
$testMembers = @(123, 456, 789)
$null = $testMembers
$testMemberWithU = @('u101')
$null = $testMemberWithU
$testUserGroupId = 1001
$null = $testUserGroupId

Expand All @@ -24,8 +26,8 @@ Describe 'Add-TeamViewerUserGroupMember' {
-Member $testMembers
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -And `
$Uri -eq "//unit.test/usergroups/$testUserGroupId/members" -And `
$Method -eq 'Post' }
$Uri -eq "//unit.test/usergroups/$testUserGroupId/members" -And `
$Method -eq 'Post' }
}

It 'Should handle domain object as input' {
Expand All @@ -36,8 +38,19 @@ Describe 'Add-TeamViewerUserGroupMember' {
-Member $testMembers
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -And `
$Uri -eq "//unit.test/usergroups/$testUserGroupId/members" -And `
$Method -eq 'Post' }
$Uri -eq "//unit.test/usergroups/$testUserGroupId/members" -And `
$Method -eq 'Post' }
}

It 'Should add a single member to the user group with format u[0-9]+' {
Add-TeamViewerUserGroupMember `
-ApiToken $testApiToken `
-UserGroup $testUserGroupId `
-Member $testMemberWithU
$mockArgs.Body | Should -Not -BeNullOrEmpty
$body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json
$body | Should -HaveCount 1
$body | Should -Contain $testMemberWithU.trim('u')
}

It 'Should add the given members to the user group' {
Expand Down
15 changes: 14 additions & 1 deletion Tests/Public/Remove-TeamViewerUserGroupMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ BeforeAll {
$testApiToken = [securestring]@{}
$null = $testApiToken
$testMembers = @(123, 456, 789)
$testMemberId = @('u101')
$null = $testMemberId
$testUserGroupMembers = @(
@{AccountId = $testMembers[0]; Name = 'test account 1' }
@{AccountId = $testMembers[1]; Name = 'test account 2' }
Expand All @@ -25,7 +27,7 @@ BeforeAll {

Describe 'Remove-TeamViewerUserGroupMember' {

Context 'Should bulk remove members ByUserGroupMemberId' {
Context 'Should remove members ByUserGroupMember' {

It 'Should call the correct API endpoint' {
Remove-TeamViewerUserGroupMember `
Expand All @@ -38,6 +40,17 @@ Describe 'Remove-TeamViewerUserGroupMember' {
$Method -eq 'Delete' }
}

It 'Should remove a single user from the user group' {
Remove-TeamViewerUserGroupMember `
-ApiToken $testApiToken `
-UserGroup $testUserGroupId `
-UserGroupMember $testMemberId
$mockArgs.Body | Should -Not -BeNullOrEmpty
$body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json
$body | Should -HaveCount 1
$body | Should -Contain $testMemberId.trim('u')
}

It 'Should handle domain object as input' {
$testUserGroup = @{Id = $testUserGroupId; Name = 'test user group' } | ConvertTo-TeamViewerUserGroup
Remove-TeamViewerUserGroupMember `
Expand Down

0 comments on commit a0442bf

Please sign in to comment.