-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c5b221
commit 8b8ea50
Showing
3 changed files
with
308 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import JSONSchemaPatch from '../src'; | ||
|
||
describe('JSONSchemaPatch - renameProperty', () => { | ||
it('should rename a property and update required fields', () => { | ||
const schema = { | ||
properties: { | ||
oldName: { type: "string" }, | ||
otherProp: { type: "number" } | ||
}, | ||
required: ["oldName", "otherProp"] | ||
}; | ||
const patcher = new JSONSchemaPatch(schema); | ||
|
||
// Preparing operation to rename 'oldName' to 'newName' | ||
patcher.prepareOperation({ | ||
op: 'renameProperty', | ||
path: '/properties', | ||
value: { oldName: 'oldName', newName: 'newName' } | ||
}); | ||
|
||
// Applying all prepared operations | ||
patcher.applyPatch(); | ||
|
||
// Expected schema after the operation | ||
const expectedSchema = { | ||
properties: { | ||
newName: { type: "string" }, // 'oldName' should now be 'newName' | ||
otherProp: { type: "number" } | ||
}, | ||
required: ["newName", "otherProp"] // 'required' should be updated to reflect the new property name | ||
}; | ||
|
||
// Asserting that the schema has been updated as expected | ||
expect(schema).toEqual(expectedSchema); | ||
}); | ||
|
||
it('should handle renaming a non-existent property gracefully', () => { | ||
const schema = { | ||
properties: { | ||
someProp: { type: "string" } | ||
}, | ||
required: ["someProp"] | ||
}; | ||
const patcher = new JSONSchemaPatch(schema); | ||
|
||
// Attempting to rename a non-existent property | ||
patcher.prepareOperation({ | ||
op: 'renameProperty', | ||
path: '/properties', | ||
value: { oldName: 'nonExistent', newName: 'newName' } | ||
}); | ||
|
||
// Applying all prepared operations | ||
patcher.applyPatch(); | ||
|
||
// Expect the schema to remain unchanged as the property does not exist | ||
expect(schema).toEqual({ | ||
properties: { | ||
someProp: { type: "string" } | ||
}, | ||
required: ["someProp"] | ||
}); | ||
}); | ||
}); |
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