-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathInvoke-TeamViewerGroupPerUserSync.Tests.ps1
108 lines (96 loc) · 4.61 KB
/
Invoke-TeamViewerGroupPerUserSync.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (c) 2019-2021 TeamViewer GmbH
# See file LICENSE.txt
BeforeAll {
$testApiToken = [securestring]@{}
. "$PSScriptRoot\Invoke-TeamViewerGroupPerUserSync.ps1" `
-ApiToken $testApiToken `
-MappingFilePath "example.csv" `
-IgnoreSourceGroup `
-NoLogFile `
-InformationAction SilentlyContinue
Mock Invoke-TeamViewerPing { $true }
Mock Get-TeamViewerUser { @() }
Mock Get-TeamViewerGroup { @() }
Mock Get-TeamViewerDevice { @() }
Mock New-TeamViewerGroup { }
Mock Set-TeamViewerDevice -RemoveParameterValidation 'Device', 'Group' { }
Mock Publish-TeamViewerGroup -RemoveParameterValidation 'User', 'Group' { }
}
Describe 'Invoke-TeamViewerGroupPerUserSync' {
It 'Should check the connection to the TeamViewer API' {
{ Invoke-TeamViewerGroupPerUserSync -sourceGroupName '' -ignoreSourceGroup $true -mappingData @() } | Should -Not -Throw
Assert-MockCalled Invoke-TeamViewerPing -Times 1 -Scope It
}
Context 'TeamViewer API not reachable' {
BeforeAll {
Mock Invoke-TeamViewerPing { $false }
}
It 'Should abort if TeamViewer API is not reachable' {
{ Invoke-TeamViewerGroupPerUserSync -sourceGroupName '' -ignoreSourceGroup $true -mappingData @() } | Should -Throw
}
}
It 'Should get users, groups and devices' {
{ Invoke-TeamViewerGroupPerUserSync -sourceGroupName '' -ignoreSourceGroup $true -mappingData @() } | Should -Not -Throw
Assert-MockCalled Get-TeamViewerUser -Times 1 -Scope It
Assert-MockCalled Get-TeamViewerGroup -Times 1 -Scope It
Assert-MockCalled Get-TeamViewerDevice -Times 1 -Scope It
}
It 'Should abort if source group does not exist' {
{ Invoke-TeamViewerGroupPerUserSync -sourceGroupName 'Non-existing group' -ignoreSourceGroup $false -mappingData @() } | Should -Throw
}
Context 'Happy Path' {
BeforeAll {
Mock Get-TeamViewerUser { @(
@{Id = 'TestUser1'; Email = '[email protected]' }
) }
Mock Get-TeamViewerDevice { @(
@{Id = '007'; Name = "TestDevice1"; TeamViewerId = "1234" }
) }
Mock New-TeamViewerGroup { @{
Id = 'newgroupid1'; Name = 'Devices of [email protected]'
} }
}
It 'Should create the group, add the device to the group and share the group with the user' {
$mappingData = @(
@{email = '[email protected]'; device = 'TestDevice1' }
)
$result = Invoke-TeamViewerGroupPerUserSync -sourceGroupName '' -ignoreSourceGroup $true -mappingData $mappingData
$result.Statistics.Failed | Should -Be 0
$result.Statistics.Unchanged | Should -Be 0
$result.Statistics.Updated | Should -Be 1
Assert-MockCalled New-TeamViewerGroup -Times 1 -Scope It -ParameterFilter {
$Name -Eq 'Devices of [email protected]'
}
Assert-MockCalled Set-TeamViewerDevice -Times 1 -Scope It -ParameterFilter {
$Device -And $Device.Id -Eq "007" -And `
$Group -And $Group.Id -Eq 'newgroupid1'
}
Assert-MockCalled Publish-TeamViewerGroup -Times 1 -Scope It -ParameterFilter {
$Group -And $Group.Id -Eq 'newgroupid1' -And `
$User -And $User.Id -Eq 'TestUser1' -And `
$Permissions -Eq 'readwrite'
}
}
It 'Should do the lookup via TeamViewer ID' {
$mappingData = @(
@{email = '[email protected]'; teamviewerid = '1234' }
)
$result = Invoke-TeamViewerGroupPerUserSync -sourceGroupName '' -ignoreSourceGroup $true -mappingData $mappingData
$result.Statistics.Failed | Should -Be 0
$result.Statistics.Unchanged | Should -Be 0
$result.Statistics.Updated | Should -Be 1
Assert-MockCalled New-TeamViewerGroup -Times 1 -Scope It -ParameterFilter {
$Name -Eq 'Devices of [email protected]'
}
Assert-MockCalled Set-TeamViewerDevice -Times 1 -Scope It -ParameterFilter {
$Device -And $Device.Id -Eq "007" -And `
$Group -And $Group.Id -Eq 'newgroupid1'
}
Assert-MockCalled Publish-TeamViewerGroup -Times 1 -Scope It -ParameterFilter {
$Group -And $Group.Id -Eq 'newgroupid1' -And `
$User -And $User.Id -Eq 'TestUser1' -And `
$Permissions -Eq 'readwrite'
}
}
}
}