From ac44fca7c29c33fc461bf7048c9d31113fd177cc Mon Sep 17 00:00:00 2001 From: ivixvi Date: Sat, 8 Feb 2025 12:45:09 +0900 Subject: [PATCH] feat: add tests --- path_not_specified_replace_test.go | 70 ++++++++++++++++- path_specified_add_test.go | 121 ++++++++++++++++++++++++++++- path_specified_remove_test.go | 54 ++++++++++++- path_specified_replace_test.go | 121 ++++++++++++++++++++++++++++- 4 files changed, 362 insertions(+), 4 deletions(-) diff --git a/path_not_specified_replace_test.go b/path_not_specified_replace_test.go index 12b36ed..53f1bed 100644 --- a/path_not_specified_replace_test.go +++ b/path_not_specified_replace_test.go @@ -289,13 +289,81 @@ func TestPathNotSpecifiedReplace(t *testing.T) { }, expectedChanged: true, }, + // MultiValued Attribute + { + name: "Replace operation - Extension MultiValued Attributes - add", + op: scim.PatchOperation{ + Op: "replace", + 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: "Replace operation - Extension MultiValued Attributes - replace slice", + op: scim.PatchOperation{ + Op: "replace", + 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{}{"newValue"}, + }, + }, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - no changed", + op: scim.PatchOperation{ + Op: "replace", + 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/path_specified_add_test.go b/path_specified_add_test.go index 5b16e81..4b28423 100644 --- a/path_specified_add_test.go +++ b/path_specified_add_test.go @@ -451,13 +451,132 @@ func TestPathSpecifiedAdd(t *testing.T) { }, expectedChanged: true, }, + // MultiValued Attribute + { + name: "Add operation - Extension MultiValued Attributes - new value", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "value", + }, + data: map[string]interface{}{}, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value"}, + "testString": "value", + }, + }, + expectedChanged: true, + }, + { + name: "Add operation - Extension MultiValued Attributes - add value", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "newValue", + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value", "newValue"}, + "testString": "newValue", + }, + }, + expectedChanged: true, + }, + { + name: "Add operation - Extension MultiValued Attributes - no changed", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "value", + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value"}, + "testString": "value", + }, + }, + // expectedChanged: false, + expectedChanged: true, + }, + { + name: "Add operation - Extension MultiValued Attributes - slice specified new value", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []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 - slice specified add value", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []interface{}{"newValue"}, + }, + 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", "newValue"}, + }, + }, + expectedChanged: true, + }, + { + name: "Add operation - Extension MultiValued Attributes - slice specified no changed", + op: scim.PatchOperation{ + Op: "add", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []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/path_specified_remove_test.go b/path_specified_remove_test.go index d551c84..6c16fc8 100644 --- a/path_specified_remove_test.go +++ b/path_specified_remove_test.go @@ -264,6 +264,7 @@ func TestPathSpecifiedRemove(t *testing.T) { }, expectedChanged: false, }, + // Remove MultiValued Complex Attributes { name: "Remove operation - MultiValued Complex Attribute - Direct Remove", op: scim.PatchOperation{ @@ -382,13 +383,64 @@ func TestPathSpecifiedRemove(t *testing.T) { }, expectedChanged: false, }, + // Remove MultiValued Attributes + { + name: "Remove operation - MultiValued Singular Attribute - remove", + op: scim.PatchOperation{ + Op: "remove", + Path: path("urn:ivixvi:testSchema:testString"), + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + expected: map[string]interface{}{}, + expectedChanged: true, + }, + { + name: "Remove operation - MultiValued Singular Attribute - item remove", + op: scim.PatchOperation{ + Op: "remove", + Path: path(`urn:ivixvi:testSchema:testString[value eq "delete"]`), + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value", "delete"}, + }, + }, + // FIXME + // data: map[string]interface{}{ + // "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value"}, + // }, + // }, + // expectedChanged: true, + expected: map[string]interface{}{}, + expectedChanged: false, + }, + { + name: "Remove operation - MultiValued Singular Attribute - no changed", + op: scim.PatchOperation{ + Op: "remove", + Path: path("urn:ivixvi:testSchema:testString"), + }, + data: map[string]interface{}{}, + expected: map[string]interface{}{}, + 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/path_specified_replace_test.go b/path_specified_replace_test.go index 8a6967b..9b87d57 100644 --- a/path_specified_replace_test.go +++ b/path_specified_replace_test.go @@ -368,13 +368,132 @@ func TestPathSpecifiedReplace(t *testing.T) { expected: map[string]interface{}{}, expectedChanged: false, }, + // MultiValued Attribute + { + name: "Replace operation - Extension MultiValued Attributes - new value", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "value", + }, + data: map[string]interface{}{}, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value"}, + "testString": "value", + }, + }, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - add value", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "newValue", + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"newValue"}, + "testString": "newValue", + }, + }, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - no changed", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: "value", + }, + data: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + // FIXME: schema is not validated + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + // "testString": []interface{}{"value"}, + "testString": "value", + }, + }, + // expectedChanged: false, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - slice specified new value", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []interface{}{"value"}, + }, + data: map[string]interface{}{}, + expected: map[string]interface{}{ + "urn:ivixvi:testSchema": map[string]interface{}{ + "testString": []interface{}{"value"}, + }, + }, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - slice specified add value", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []interface{}{"newValue"}, + }, + 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{}{"newValue"}, + }, + }, + expectedChanged: true, + }, + { + name: "Replace operation - Extension MultiValued Attributes - slice specified no changed", + op: scim.PatchOperation{ + Op: "replace", + Path: path("urn:ivixvi:testSchema:testString"), + Value: []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)