Skip to content

Commit

Permalink
fix(rename field decorator): throw when put space inside fieldName (#748
Browse files Browse the repository at this point in the history
)
  • Loading branch information
arnaud-moncel authored Jun 26, 2023
1 parent 462c80e commit 5793eff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export default class RenameFieldCollectionDecorator extends CollectionDecorator

let initialName = currentName;

if (/ /.test(newName)) {
const sanitizedName = newName.replace(/ (.)/g, (_, s) => s.toUpperCase());
throw new Error(
`The renaming of field '${currentName}' must not contain space.` +
` Something like '${sanitizedName}' should work has expected.`,
);
}

// Revert previous renaming (avoids conflicts and need to recurse on this.toSubCollection).
if (this.toChildCollection[currentName]) {
const childName = this.toChildCollection[currentName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ describe('RenameFieldCollectionDecorator', () => {
expect(() => newPersons.renameField('id', 'primaryKey')).toThrow(`No such field 'id'`);
});

test('should throw when renaming with a name including space', () => {
expect(() => newPersons.renameField('id', 'the key')).toThrow(
`The renaming of field 'id' must not contain space.` +
` Something like 'theKey' should work has expected.`,
);
});

test('should allow renaming multiple times the same field', () => {
newPersons.renameField('id', 'key');
newPersons.renameField('key', 'primaryKey');
Expand Down

0 comments on commit 5793eff

Please sign in to comment.