diff --git a/path_not_specified_add_test.go b/path_not_specified_add_test.go index 040be14..44fb876 100644 --- a/path_not_specified_add_test.go +++ b/path_not_specified_add_test.go @@ -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) diff --git a/schema_test.go b/schema_test.go new file mode 100644 index 0000000..15a8ea3 --- /dev/null +++ b/schema_test.go @@ -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, + })), + }, +}