From 3e3457003b191a60d6eb0e75d6e2fb23a26b77be Mon Sep 17 00:00:00 2001 From: ivixvi Date: Sat, 8 Feb 2025 11:39:17 +0900 Subject: [PATCH 1/2] add: test schema --- schema_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 schema_test.go 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, + })), + }, +} From ad8afb781680e3b39b6e784540b5309a4e530dab Mon Sep 17 00:00:00 2001 From: ivixvi Date: Sat, 8 Feb 2025 11:39:56 +0900 Subject: [PATCH 2/2] feat: Add Operation test for MultiValued --- path_not_specified_add_test.go | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) 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)