forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing name validation on object names at update (twentyhq#5434)
## Context as per title ## How was it tested? local (/metadata + in product)
- Loading branch information
Showing
4 changed files
with
119 additions
and
44 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
63 changes: 63 additions & 0 deletions
63
...adata-modules/object-metadata/utils/__tests__/validate-object-metadata-input.util.spec.ts
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,63 @@ | ||
import { UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input'; | ||
import { validateObjectMetadataInputOrThrow } from 'src/engine/metadata-modules/object-metadata/utils/validate-object-metadata-input.util'; | ||
|
||
const validObjectInput: UpdateObjectPayload = { | ||
labelPlural: 'Car', | ||
labelSingular: 'Cars', | ||
nameSingular: 'car', | ||
namePlural: 'cars', | ||
}; | ||
|
||
const reservedKeyword = 'user'; | ||
|
||
describe('validateObjectName', () => { | ||
it('should not throw if names are valid', () => { | ||
expect(() => | ||
validateObjectMetadataInputOrThrow(validObjectInput), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should throw is nameSingular has invalid characters', () => { | ||
const invalidObjectInput = { | ||
...validObjectInput, | ||
nameSingular: 'μ', | ||
}; | ||
|
||
expect(() => | ||
validateObjectMetadataInputOrThrow(invalidObjectInput), | ||
).toThrow(); | ||
}); | ||
|
||
it('should throw is namePlural has invalid characters', () => { | ||
const invalidObjectInput = { | ||
...validObjectInput, | ||
namePlural: 'μ', | ||
}; | ||
|
||
expect(() => | ||
validateObjectMetadataInputOrThrow(invalidObjectInput), | ||
).toThrow(); | ||
}); | ||
|
||
it('should throw if nameSingular is a reserved keyword', async () => { | ||
const invalidObjectInput = { | ||
...validObjectInput, | ||
nameSingular: reservedKeyword, | ||
}; | ||
|
||
expect(() => | ||
validateObjectMetadataInputOrThrow(invalidObjectInput), | ||
).toThrow(); | ||
}); | ||
|
||
it('should throw if namePlural is a reserved keyword', async () => { | ||
const invalidObjectInput = { | ||
...validObjectInput, | ||
namePlural: reservedKeyword, | ||
}; | ||
|
||
expect(() => | ||
validateObjectMetadataInputOrThrow(invalidObjectInput), | ||
).toThrow(); | ||
}); | ||
}); |
59 changes: 51 additions & 8 deletions
59
.../src/engine/metadata-modules/object-metadata/utils/validate-object-metadata-input.util.ts
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