Skip to content

The open alternative to Salesforce, designed for AI.

1.6 KB
Raw Blame
import { computeMetadataNameFromLabel } from '@/metadata/utils/compute-metadata-name-from-label.util';

describe('computeMetadataNameFromLabel', () => {
  it('should convert a label to camelCase', () => {
    expect(computeMetadataNameFromLabel({ label: 'My Custom Field' })).toBe(
      'myCustomField',
    );
  });

  it('should convert a label to camelCase', () => {
    expect(computeMetadataNameFromLabel({ label: 'My CreatedAt Field' })).toBe(
      'myCreatedatField',
    );
  });

  it('should return empty string for empty label', () => {
    expect(computeMetadataNameFromLabel({ label: '' })).toBe('');
  });

  it('should prefix numeric labels with n', () => {
    expect(computeMetadataNameFromLabel({ label: '123 Field' })).toBe(
      'n123Field',
    );
  });

  it('should add Custom suffix for reserved words', () => {
    const result = computeMetadataNameFromLabel({ label: 'Name' });

    expect(typeof result).toBe('string');
    expect(result.length).toBeGreaterThan(0);
  });

  it('should reserve nested relation keywords', () => {
    expect(computeMetadataNameFromLabel({ label: 'Connect' })).toBe(
      'connectCustom',
    );
    expect(computeMetadataNameFromLabel({ label: 'Create' })).toBe(
      'createCustom',
    );
    expect(computeMetadataNameFromLabel({ label: 'Disconnect' })).toBe(
      'disconnectCustom',
    );
  });

  it('should skip custom suffix when applyCustomSuffix is false', () => {
    const result = computeMetadataNameFromLabel({
      label: 'My Field',
      applyCustomSuffix: false,
    });

    expect(result).toBe('myField');
  });
});