Feat/improve error management in core module (#8933)
## Summary This Pull Request introduces a custom validator for checking forbidden words in workspaces and refines how exceptions are handled within the workspace module. - Introduced `ForbiddenWords` custom class validator for validating forbidden words against specific fields in `UpdateWorkspaceInput`. - Added `EnvironmentService` usage in `WorkspaceService` to check default subdomains. - New file `workspaceGraphqlApiExceptionHandler` to handle GraphQL API exceptions with specific error mappings. - Expanded `WorkspaceExceptionCode` with `SUBDOMAIN_ALREADY_TAKEN`. - Added new unit tests for validating forbidden words and exception handler behavior.
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user