feat(workspace): expand forbidden subdomain validation (#9082)

Added new forbidden words and regex patterns to subdomain validation in
`update-workspace-input`. Enhanced the `ForbiddenWords` validator to
support both strings and regex matching. Updated tests to verify
regex-based forbidden subdomain validation.

Fix #9064

---------

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
Antoine Moreaux
2024-12-18 16:46:59 +01:00
committed by GitHub
parent 550756c2bf
commit 2bcce44e08
8 changed files with 126 additions and 86 deletions

View File

@ -1,38 +0,0 @@
import { validate } from 'class-validator';
import { ForbiddenWords } from 'src/engine/utils/custom-class-validator/ForbiddenWords';
describe('ForbiddenWordsConstraint', () => {
test('should throw error when word is forbidden', async () => {
class Test {
@ForbiddenWords(['forbidden', 'restricted'])
subdomain: string;
}
const instance = new Test();
instance.subdomain = 'forbidden';
const errors = await validate(instance);
expect(errors.length).toBeGreaterThan(0);
expect(errors[0].constraints).toEqual({
ForbiddenWordsConstraint: 'forbidden, restricted are not allowed',
});
});
test('should pass validation word is not in the list', async () => {
class Test {
@ForbiddenWords(['forbidden', 'restricted'])
subdomain: string;
}
const instance = new Test();
instance.subdomain = 'valid';
const errors = await validate(instance);
expect(errors.length).toEqual(0);
});
});