-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Path with a complex filter match only the first occurrence (#560)
* Build done * Changed navigate() signature: - navigate return a list of sub-schemas - `applyRemoveOperation` and `applyAddOrReplaceOperation` adapted to the new signature (and logic) * Add tests for cases where valuePath match multiple elements * Revert "Build done" This reverts commit e8354a6. * Fixed case special case of replace: "REPLACE: replace on multiValued objects without complete path" * Removed commented console logs --------- Co-authored-by: Thomas Poignant <[email protected]>
- Loading branch information
1 parent
ac3dc19
commit 94d330b
Showing
2 changed files
with
218 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,74 @@ describe('SCIM PATCH', () => { | |
return done(); | ||
}); | ||
|
||
it('REPLACE: replace on multiValued objects', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre"}, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: expected, path: 'emails.newProperty'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
it('REPLACE: replace on multiValued objects without complete path', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre"}, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: {newProperty: expected}, path: 'emails'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails.length).to.be.eq(4); | ||
return done(); | ||
}); | ||
|
||
it('REPLACE: filter that match multiple elements of complex multiValued attribute', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre"}, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: expected, path: 'emails[primary eq false].newProperty'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.eq("pre"); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
|
||
it('REPLACE: filter that match multiple elements of complex multiValued attribute without complete path', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre"}, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: {newProperty: expected}, path: 'emails[primary eq false]'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.eq("pre"); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
|
||
// see https://github.com/thomaspoignant/scim-patch/issues/489 | ||
it('REPLACE: Replace op with value of empty object results in circular reference', done => { | ||
const expected = [ | ||
|
@@ -832,6 +900,41 @@ describe('SCIM PATCH', () => { | |
expect(afterPatch.emails.length).to.be.eq(2); | ||
return done(); | ||
}); | ||
|
||
|
||
it('ADD: filter that match multiple elements of complex multiValued attribute', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true }, | ||
{ value: "[email protected]", primary: false }, | ||
{ value: "[email protected]", primary: false }, | ||
{ value: "[email protected]", primary: false }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'add', value: expected, path: 'emails[primary eq false].newProperty'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
|
||
it('ADD: filter that match multiple elements of complex multiValued attribute without complete path', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true }, | ||
{ value: "[email protected]", primary: false }, | ||
{ value: "[email protected]", primary: false }, | ||
{ value: "[email protected]", primary: false }, | ||
]; | ||
const expected = "post"; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'add', value: {newProperty: expected}, path: 'emails[primary eq false]'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[1].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[2].newProperty).to.be.eq(expected); | ||
expect(afterPatch.emails[3].newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
}); | ||
describe('remove', () => { | ||
it('REMOVE: with no path', done => { | ||
|
@@ -1041,6 +1144,40 @@ describe('SCIM PATCH', () => { | |
expect(scimUser).not.to.eq(afterPatch); | ||
return done(); | ||
}); | ||
|
||
|
||
|
||
it('REMOVE: remove all sub-attributes in a complex multi-valued attribute', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const patch: ScimPatchRemoveOperation = {op: 'remove', path: 'emails.newProperty'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[1].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[2].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[3].newProperty).to.be.an('undefined'); | ||
return done(); | ||
}); | ||
|
||
it('REMOVE: filter that match multiple elements of complex multiValued attribute', done => { | ||
scimUser.emails = [ | ||
{ value: "[email protected]", primary: true, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
{ value: "[email protected]", primary: false, newProperty: "pre" }, | ||
]; | ||
const patch: ScimPatchRemoveOperation = {op: 'remove', path: 'emails[primary eq false].newProperty'}; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.emails[0].newProperty).to.be.eq("pre"); | ||
expect(afterPatch.emails[1].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[2].newProperty).to.be.an('undefined'); | ||
expect(afterPatch.emails[3].newProperty).to.be.an('undefined'); | ||
return done(); | ||
}); | ||
}); | ||
|
||
describe('invalid requests', () => { | ||
|