Skip to content

Commit

Permalink
feat: add tests (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivixvi authored Feb 8, 2025
1 parent c89575d commit 1c290b8
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 4 deletions.
70 changes: 69 additions & 1 deletion path_not_specified_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
121 changes: 120 additions & 1 deletion path_specified_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 53 additions & 1 deletion path_specified_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 1c290b8

Please sign in to comment.