Skip to content

Commit

Permalink
Merge pull request #34 from ivixvi/feat-add-multivalued-tests
Browse files Browse the repository at this point in the history
Feat add multivalued tests
  • Loading branch information
ivixvi authored Feb 8, 2025
2 parents 9f92e44 + ad8afb7 commit c89575d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
68 changes: 67 additions & 1 deletion path_not_specified_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,79 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
},
expectedChanged: true,
},
// MultiValued Attribute
{
name: "Add operation - Extension MultiValued Attributes - add",
op: scim.PatchOperation{
Op: "add",
Value: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"value"},
},
},
},
data: map[string]interface{}{},
expected: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"value"},
},
},
expectedChanged: true,
},
{
name: "Add operation - Extension MultiValued Attributes - merge slice",
op: scim.PatchOperation{
Op: "add",
Value: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"newValue"},
},
},
},
data: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"oldValue"},
},
},
expected: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"oldValue", "newValue"},
},
},
expectedChanged: true,
},
{
name: "Add operation - Extension MultiValued Attributes - no changed",
op: scim.PatchOperation{
Op: "add",
Value: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"value"},
},
},
},
data: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"value"},
},
},
expected: map[string]interface{}{
"urn:ivixvi:testSchema": map[string]interface{}{
"testString": []interface{}{"value"},
},
},
expectedChanged: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(schema.CoreUserSchema(), []schema.Schema{schema.ExtensionEnterpriseUser()}, nil)
patcher := scimpatch.NewPatcher(schema.CoreUserSchema(), []schema.Schema{
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(tc.op, tc.data)
Expand Down
18 changes: 18 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scimpatch_test

import (
"github.com/elimity-com/scim/optional"
"github.com/elimity-com/scim/schema"
)

var TestExtensionSchema = schema.Schema{
Description: optional.NewString("test"),
ID: "urn:ivixvi:testSchema",
Name: optional.NewString("test"),
Attributes: []schema.CoreAttribute{
schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{
Name: "testString",
MultiValued: true,
})),
},
}

0 comments on commit c89575d

Please sign in to comment.