From 270a038e9ac1cfaf4e0212889c1ff455419aaeff Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 20 Nov 2023 09:35:13 -0700 Subject: [PATCH 1/2] Remove duplicate tests --- .../CSV_Import/Import-JCMSPFromCSV.Tests.ps1 | 94 ------------------- .../CSV_Import/Import-JCMspFromCSV.Tests.ps1 | 94 ------------------- 2 files changed, 188 deletions(-) delete mode 100644 PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 delete mode 100644 PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMspFromCSV.Tests.ps1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 deleted file mode 100644 index a0ebf1f71..000000000 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 +++ /dev/null @@ -1,94 +0,0 @@ -Describe -Tag:('MSP') 'Import-JCMSPFromCSV' { - - BeforeAll { - BeforeAll { Connect-JCOnline -JumpCloudApiKey:($env:PESTER_MSP_APIKEY) -JumpCloudOrgId:($env:PESTER_ORGID) -force | Out-Null } - - # Validate MSP Test org is set to default: - $org = Get-JCSdkOrganization -id $env:PESTER_ORGID - if (($org.Settings.Name -ne "PesterMSP") -And ($org.Settings.Name -ne "Updated PesterMSP")) { - Set-JcSdkOrganization -Id $env:PESTER_ORGID -Settings @{Name = "PesterMSP" } - } - } - Context 'Organization Import' { - it 'should import a valid org with the correct system users' { - $orgName = 'org name' - $orgUserMax = '10' - $generatedID = 'p46392y0oyc45cez6ntedo92' - - $CSVDATA = @{ - name = $orgName - maxSystemUsers = $orgUserMax - } - $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock -ModuleName "JumpCloud" -commandName Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - $status = import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force - - # assert statements - $status.count | should -BeExactly 1 - $status.name | should -Be $orgName - $status.maxSystemUsers | should -be $orgUserMax - $status.status | should -be "Imported" - $status.id | should -be $generatedID - } - it 'should throw an error when the org already exists on console' { - $orgs = Get-JcSdkOrganization - $selectedOrg = $orgs[$(Get-Random (0..($orgs.count - 1)))] - - $orgName = $selectedOrg.DisplayName - $orgUserMax = '10' - $generatedID = $selectedOrg.id - - $CSVDATA = @{ - name = $orgName - maxSystemUsers = $orgUserMax - } - $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) already exists on console.jumpcloud.com" - } - it 'should throw an error when duplicate org names in the csv does are defined' { - $orgName = "same name" - $orgUserMax = '10' - $generatedID = 'p46392y0oyc45cez6ntedo92' - $CSV = New-Object System.Collections.ArrayList - $CSV.add(@{ - name = $orgName - maxSystemUsers = $orgUserMax - }) | Out-Null - $CSV.add(@{ - name = $orgName - maxSystemUsers = $orgUserMax - }) | Out-Null - $CSVFILE = $CSV | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) in import file. organiztion name already exists." - } - } -} diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMspFromCSV.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMspFromCSV.Tests.ps1 deleted file mode 100644 index ff1ac9ccb..000000000 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMspFromCSV.Tests.ps1 +++ /dev/null @@ -1,94 +0,0 @@ -Describe -Tag:('MSP') 'Import-JCMSPFromCSV' { - - BeforeAll { - BeforeAll { Connect-JCOnline -JumpCloudApiKey:($env:JCAPIKEY) -JumpCloudOrgId:($env:JCOrgId) -force | Out-Null } - - # Validate MSP Test org is set to default: - $org = Get-JCSdkOrganization -id $env:JCOrgId - if (($org.Settings.Name -ne "PesterMSP") -And ($org.Settings.Name -ne "Updated PesterMSP")) { - Set-JcSdkOrganization -Id $env:JCOrgId -Settings @{Name = "PesterMSP" } - } - } - Context 'Organization Import' { - it 'should import a valid org with the correct system users' { - $orgName = 'org name' - $orgUserMax = '10' - $generatedID = 'p46392y0oyc45cez6ntedo92' - - $CSVDATA = @{ - name = $orgName - maxSystemUsers = $orgUserMax - } - $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock -ModuleName "JumpCloud" -commandName Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - $status = import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force - - # assert statements - $status.count | should -BeExactly 1 - $status.name | should -Be $orgName - $status.maxSystemUsers | should -be $orgUserMax - $status.status | should -be "Imported" - $status.id | should -be $generatedID - } - it 'should throw an error when the org already exists on console' { - $orgs = Get-JcSdkOrganization - $selectedOrg = $orgs[$(Get-Random (0..($orgs.count - 1)))] - - $orgName = $selectedOrg.DisplayName - $orgUserMax = '10' - $generatedID = $selectedOrg.id - - $CSVDATA = @{ - name = $orgName - maxSystemUsers = $orgUserMax - } - $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) already exists on console.jumpcloud.com" - } - it 'should throw an error when duplicate org names in the csv does are defined' { - $orgName = "same name" - $orgUserMax = '10' - $generatedID = 'p46392y0oyc45cez6ntedo92' - $CSV = New-Object System.Collections.ArrayList - $CSV.add(@{ - name = $orgName - maxSystemUsers = $orgUserMax - }) | Out-Null - $CSV.add(@{ - name = $orgName - maxSystemUsers = $orgUserMax - }) | Out-Null - $CSVFILE = $CSV | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force - - # mock IRM requests to return expected results - Mock Invoke-RestMethod -MockWith { - $obj = [PSCustomObject]@{ - 'name' = $orgName - 'maxSystemUsers' = $orgUserMax - 'id' = $generatedID - } - return $obj - } - { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) in import file. organiztion name already exists." - } - } -} From 8538bd93b5eb2c969e001d2739106dd5b025a68c Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 20 Nov 2023 09:36:08 -0700 Subject: [PATCH 2/2] Add import msp test --- .../CSV_Import/Import-JCMSPFromCSV.Tests.ps1 | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 new file mode 100644 index 000000000..a0ebf1f71 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCMSPFromCSV.Tests.ps1 @@ -0,0 +1,94 @@ +Describe -Tag:('MSP') 'Import-JCMSPFromCSV' { + + BeforeAll { + BeforeAll { Connect-JCOnline -JumpCloudApiKey:($env:PESTER_MSP_APIKEY) -JumpCloudOrgId:($env:PESTER_ORGID) -force | Out-Null } + + # Validate MSP Test org is set to default: + $org = Get-JCSdkOrganization -id $env:PESTER_ORGID + if (($org.Settings.Name -ne "PesterMSP") -And ($org.Settings.Name -ne "Updated PesterMSP")) { + Set-JcSdkOrganization -Id $env:PESTER_ORGID -Settings @{Name = "PesterMSP" } + } + } + Context 'Organization Import' { + it 'should import a valid org with the correct system users' { + $orgName = 'org name' + $orgUserMax = '10' + $generatedID = 'p46392y0oyc45cez6ntedo92' + + $CSVDATA = @{ + name = $orgName + maxSystemUsers = $orgUserMax + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force + + # mock IRM requests to return expected results + Mock -ModuleName "JumpCloud" -commandName Invoke-RestMethod -MockWith { + $obj = [PSCustomObject]@{ + 'name' = $orgName + 'maxSystemUsers' = $orgUserMax + 'id' = $generatedID + } + return $obj + } + $status = import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force + + # assert statements + $status.count | should -BeExactly 1 + $status.name | should -Be $orgName + $status.maxSystemUsers | should -be $orgUserMax + $status.status | should -be "Imported" + $status.id | should -be $generatedID + } + it 'should throw an error when the org already exists on console' { + $orgs = Get-JcSdkOrganization + $selectedOrg = $orgs[$(Get-Random (0..($orgs.count - 1)))] + + $orgName = $selectedOrg.DisplayName + $orgUserMax = '10' + $generatedID = $selectedOrg.id + + $CSVDATA = @{ + name = $orgName + maxSystemUsers = $orgUserMax + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force + + # mock IRM requests to return expected results + Mock Invoke-RestMethod -MockWith { + $obj = [PSCustomObject]@{ + 'name' = $orgName + 'maxSystemUsers' = $orgUserMax + 'id' = $generatedID + } + return $obj + } + { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) already exists on console.jumpcloud.com" + } + it 'should throw an error when duplicate org names in the csv does are defined' { + $orgName = "same name" + $orgUserMax = '10' + $generatedID = 'p46392y0oyc45cez6ntedo92' + $CSV = New-Object System.Collections.ArrayList + $CSV.add(@{ + name = $orgName + maxSystemUsers = $orgUserMax + }) | Out-Null + $CSV.add(@{ + name = $orgName + maxSystemUsers = $orgUserMax + }) | Out-Null + $CSVFILE = $CSV | Export-Csv "$PesterParams_ImportPath/importOrg.csv" -Force + + # mock IRM requests to return expected results + Mock Invoke-RestMethod -MockWith { + $obj = [PSCustomObject]@{ + 'name' = $orgName + 'maxSystemUsers' = $orgUserMax + 'id' = $generatedID + } + return $obj + } + { import-JCMSPFromCSV -CSVFilePath "$PesterParams_ImportPath/importOrg.csv" -ProviderID $ProviderID -force } | should -Throw "Duplicate organization name: $($orgName) in import file. organiztion name already exists." + } + } +}