Skip to content

Commit

Permalink
redo create branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaranionjc committed Dec 4, 2024
1 parent 2b7a879 commit aa3862d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ Function Import-JCUsersFromCSV () {
$FormatGroupOutput = $Null
$CustomGroupArrayList = $Null

$CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object
# Get all the custom attributes that are not null
$CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" }

# Sort the attributes by number and name
$CustomAttributes = $CustomAttributes | Sort-Object {
[int]([regex]::Match($_.Name, '\d+').Value) },
{ $_.Name }

Write-Verbose $CustomAttributes.name.count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,14 @@ Function Update-JCUsersFromCSV () {
$FormatGroupOutput = $Null
$CustomGroupArrayList = $Null

# Get all the custom attributes that are not null
$CustomAttributes = $UserUpdate | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object

# Sort the attributes by number and name
$CustomAttributes = $CustomAttributes | Sort-Object {
[int]([regex]::Match($_.Name, '\d+').Value) },
{ $_.Name }

if ($CustomAttributes.name.count -gt 1) {
try {
# Counter is used to create a clean list of attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,47 @@ Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.14.2" {
}
}
}
Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.15.1" {
Context "Import-JCUsersFromCSV with 10 or more custom attributes" {
It "When there are 10 or more custom attributes, the API should not return an error message in the status field and continue to import the user" {
$user = New-RandomUser -Domain "ImportCSVUser.$(New-RandomString -NumberOfChars 5)"
$today = Get-Date
$EnrollmentDays = 14
$CSVDATA = @{
Username = $user.username
LastName = $user.LastName
FirstName = $user.FirstName
Email = $user.Email
Attribute1_name = "Name"
Attribute1_value = "Value"
Attribute2_name = "Name1"
Attribute2_value = "Value1"
Attribute3_name = "Name2"
Attribute3_value = "Value2"
Attribute4_name = "Name3"
Attribute4_value = "Value3"
Attribute5_name = "Name4"
Attribute5_value = "Value4"
Attribute6_name = "Name5"
Attribute6_value = "Value5"
Attribute7_name = "Name6"
Attribute7_value = "Value6"
Attribute8_name = "Name7"
Attribute8_value = "Value7"
Attribute9_name = "Name8"
Attribute9_value = "Value8"
Attribute10_name = "Name9"
Attribute10_value = "Value9"
Attribute11_name = "Name10"
Attribute11_value = "Value10"
}
$CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/custom_attribute.csv" -Force
$importResults = Import-JCUsersFromCSV -CSVFilePath "$PesterParams_ImportPath/custom_attribute.csv" -force
# ImportResults should not be error
$importResults[0].Status | Should -Match "User Created"
}
}
}

AfterAll {
Get-JCUser | Where-Object Email -like *testimportcsvuser* | Remove-JCUser -force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,43 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.14.2" {
}
}
}

Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.15.1" {
Context "User should be updated even with 10 or more custom attributes" {
It "When there are 10 or more custom attributes, the user should still be updated" {
$user = New-RandomUser -Domain "testupdatecsvuser.$(New-RandomString -NumberOfChars 5)" | New-JCUser
$CSVDATA = @{
Username = $user.username
Attribute1_name = "Name"
Attribute1_value = "Value"
Attribute2_name = "Name1"
Attribute2_value = "Value1"
Attribute3_name = "Name2"
Attribute3_value = "Value2"
Attribute4_name = "Name3"
Attribute4_value = "Value3"
Attribute5_name = "Name4"
Attribute5_value = "Value4"
Attribute6_name = "Name5"
Attribute6_value = "Value5"
Attribute7_name = "Name6"
Attribute7_value = "Value6"
Attribute8_name = "Name7"
Attribute8_value = "Value7"
Attribute9_name = "Name8"
Attribute9_value = "Value8"
Attribute10_name = "Name9"
Attribute10_value = "Value9"
Attribute11_name = "Name10"
Attribute11_value = "Value10"
}
$CSVFILE = $CSVDATA | Export-Csv "$PesterParams_UpdatePath/custom_attribute.csv" -Force
$UpdateStatus = Update-JCUsersFromCSV -CSVFilePath "$PesterParams_UpdatePath/custom_attribute.csv" -force
# the error message should show that custom attribute names cannot contain spaces
$UpdateStatus[0].status | Should -Be "User Updated"
}
}
}
AfterAll {
Get-JCUser | Where-Object Email -like *testupdatecsvuser* | Remove-JCUser -force
}
14 changes: 14 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 2.16.0

Release Date: December 4, 2024

#### RELEASE NOTES

```
This release introduces a bug fix for `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` issues with importing more than 10 custom attributes
```

#### BUG FIXES:

- Fixed a bug with `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` throwing error when importing 10 or more Custom Attributes due to a sorting issue

## 2.15.0

Release Date: November 18, 2024
Expand Down

0 comments on commit aa3862d

Please sign in to comment.