Skip to content

Commit 1e70b5f

Browse files
Fixed unit tests for Remove-TeamViewerDuplicateDevicesV2
Existing tests were flaky, as they assumed that the cmdlet would return the results in the same order they were defined. We change these tests to test for existence within a list, rather than for exact matches on its elements.
1 parent b07790a commit 1e70b5f

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

Remove-TeamViewerDuplicateDevicesV2/Remove-TeamViewerDuplicateDevicesV2.Tests.ps1

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,36 @@ Describe 'Remove-TeamViewerDuplicateDevicesV2' {
2323
It 'Should not remove any devices if -WhatIf parameter has been set' {
2424
$result = (Remove-TeamViewerDuplicateDevicesV2 -force:$false -WhatIf)
2525
$result | Should -HaveCount 3
26-
$result[0].TeamViewerId | Should -Be 'older device A'
27-
$result[0].Status | Should -Be 'Unchanged'
28-
$result[1].TeamViewerId | Should -Be 'newer device A'
29-
$result[1].Status | Should -Be 'Unchanged'
30-
$result[2].TeamViewerId | Should -Be 'older device B'
31-
$result[2].Status | Should -Be 'Unchanged'
32-
33-
Assert-MockCalled Get-TeamViewerCompanyManagedDevice -Times 1 -Scope It
34-
Assert-MockCalled Remove-TeamViewerManagedDeviceManagement -Times 0 -Scope It
26+
27+
$result_names = $result | ForEach-Object { $_.TeamViewerId }
28+
$result_names | Should -Contain 'older device A'
29+
$result_names | Should -Contain 'newer device A'
30+
$result_names | Should -Contain 'older device B'
31+
32+
$result_statuses = $result | ForEach-Object { $_.Status }
33+
$result_statuses[0] | Should -Be 'Unchanged'
34+
$result_statuses[1] | Should -Be 'Unchanged'
35+
$result_statuses[2] | Should -Be 'Unchanged'
36+
37+
Assert-MockCalled Get-TeamViewerCompanyManagedDevice -Times 1 -Exactly -Scope It
38+
Assert-MockCalled Remove-TeamViewerManagedDeviceManagement -Times 0 -Exactly -Scope It
3539
}
3640

3741
It 'Should remove duplicate devices with an older last-seen timestamp' {
3842
$result = (Remove-TeamViewerDuplicateDevicesV2 -force:$true)
3943
$result | Should -HaveCount 3
40-
$result[0].TeamViewerId | Should -Be 'older device A'
41-
$result[0].Status | Should -Be 'Removed'
42-
$result[1].TeamViewerId | Should -Be 'newer device A'
43-
$result[1].Status | Should -Be 'Removed'
44-
$result[2].TeamViewerId | Should -Be 'older device B'
45-
$result[2].Status | Should -Be 'Removed'
46-
47-
Assert-MockCalled Get-TeamViewerCompanyManagedDevice -Times 1 -Scope It
48-
Assert-MockCalled Remove-TeamViewerManagedDeviceManagement -Times 3 -Scope It
44+
45+
$result_names = $result | ForEach-Object { $_.TeamViewerId }
46+
$result_names | Should -Contain 'older device A'
47+
$result_names | Should -Contain 'newer device A'
48+
$result_names | Should -Contain 'older device B'
49+
50+
$result_statuses = $result | ForEach-Object { $_.Status }
51+
$result_statuses[0] | Should -Be 'Removed'
52+
$result_statuses[1] | Should -Be 'Removed'
53+
$result_statuses[2] | Should -Be 'Removed'
54+
55+
Assert-MockCalled Get-TeamViewerCompanyManagedDevice -Times 1 -Exactly -Scope It
56+
Assert-MockCalled Remove-TeamViewerManagedDeviceManagement -Times 3 -Exactly -Scope It
4957
}
5058
}

0 commit comments

Comments
 (0)