Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Object names should be camel cased #5571

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,26 @@ describe('validateObjectName', () => {
validateObjectMetadataInputOrThrow(invalidObjectInput),
).toThrow();
});

it('should throw if nameSingular is not camelCased', async () => {
const invalidObjectInput = {
...validObjectInput,
nameSingular: 'notACamelCase1a',
};

expect(() =>
validateObjectMetadataInputOrThrow(invalidObjectInput),
).toThrow();
});

it('should throw if namePlural is a not camelCased', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the test description: 'should throw if namePlural is a not camelCased' should be 'should throw if namePlural is not camelCased'.

const invalidObjectInput = {
...validObjectInput,
namePlural: 'notACamelCase1b',
};

expect(() =>
validateObjectMetadataInputOrThrow(invalidObjectInput),
).toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { InvalidStringException } from 'src/engine/metadata-modules/errors/Inval
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
import { UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
import { validateMetadataName } from 'src/engine/metadata-modules/utils/validate-metadata-name.utils';
import { camelCase } from 'src/utils/camel-case';

const coreObjectNames = [
'appToken',
Expand Down Expand Up @@ -41,6 +42,9 @@ export const validateObjectMetadataInputOrThrow = <
>(
objectMetadataInput: T,
): void => {
validateNameCamelCasedOrThrow(objectMetadataInput.nameSingular);
validateNameCamelCasedOrThrow(objectMetadataInput.namePlural);

validateNameCharactersOrThrow(objectMetadataInput.nameSingular);
validateNameCharactersOrThrow(objectMetadataInput.namePlural);

Expand All @@ -56,6 +60,14 @@ const validateNameIsNotReservedKeywordOrThrow = (name?: string) => {
}
};

const validateNameCamelCasedOrThrow = (name?: string) => {
if (name) {
if (name !== camelCase(name)) {
throw new ForbiddenException(`Name should be in camelCase: ${name}`);
}
}
};

const validateNameCharactersOrThrow = (name?: string) => {
try {
if (name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ export class RemoteTableService {
: plural(localTableBaseName);

const objectMetadata = await this.objectMetadataService.createOne({
nameSingular: localTableNameSingular,
namePlural: localTableNamePlural,
nameSingular: camelCase(localTableNameSingular),
namePlural: camelCase(localTableNamePlural),
labelSingular: camelToTitleCase(camelCase(localTableBaseName)),
labelPlural: camelToTitleCase(plural(camelCase(localTableBaseName))),
description: 'Remote table',
Expand Down
Loading