Rename Money/Url to Currency/Link and remove snake_case from composite fields (#2536)

* Rename Money/Url to Currency/Link

* regenerate front types

* renaming money/url field types

* fix double text

* fix tests

* fix server tests

* fix generate-target-column-map

* fix currency convert

* fix: tests

---------

Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
This commit is contained in:
Weiko
2023-11-17 10:31:17 +01:00
committed by GitHub
parent 31e439681c
commit bc579d64a6
56 changed files with 579 additions and 512 deletions
@@ -19,46 +19,49 @@ describe('convertFieldMetadataToColumnActions', () => {
]);
});
it('should convert URL field metadata to column actions', () => {
it('should convert LINK field metadata to column actions', () => {
const fieldMetadata = {
type: FieldMetadataType.URL,
targetColumnMap: { text: 'url_text', link: 'url_link' },
defaultValue: { text: 'http://example.com', link: 'Example' },
type: FieldMetadataType.LINK,
targetColumnMap: { label: 'linkLabel', url: 'linkURL' },
defaultValue: { label: 'http://example.com', url: 'Example' },
} as any;
const columnActions = convertFieldMetadataToColumnActions(fieldMetadata);
expect(columnActions).toEqual([
{
action: 'CREATE',
columnName: 'url_text',
columnName: 'linkLabel',
columnType: 'varchar',
defaultValue: "'http://example.com'",
},
{
action: 'CREATE',
columnName: 'url_link',
columnName: 'linkURL',
columnType: 'varchar',
defaultValue: "'Example'",
},
]);
});
it('should convert MONEY field metadata to column actions', () => {
it('should convert CURRENCY field metadata to column actions', () => {
const fieldMetadata = {
type: FieldMetadataType.MONEY,
targetColumnMap: { amount: 'money_amount', currency: 'money_currency' },
defaultValue: { amount: 100, currency: 'USD' },
type: FieldMetadataType.CURRENCY,
targetColumnMap: {
amountMicros: 'moneyAmountMicros',
currencyCode: 'moneyCurrencyCode',
},
defaultValue: { amountMicros: 100 * 1_000_000, currencyCode: 'USD' },
} as any;
const columnActions = convertFieldMetadataToColumnActions(fieldMetadata);
expect(columnActions).toEqual([
{
action: 'CREATE',
columnName: 'money_amount',
columnName: 'moneyAmountMicros',
columnType: 'integer',
defaultValue: 100,
defaultValue: 100 * 1_000_000,
},
{
action: 'CREATE',
columnName: 'money_currency',
columnName: 'moneyCurrencyCode',
columnType: 'varchar',
defaultValue: "'USD'",
},
@@ -12,21 +12,21 @@ describe('generateTargetColumnMap', () => {
);
expect(textMap).toEqual({ value: 'name' });
const urlMap = generateTargetColumnMap(
FieldMetadataType.URL,
const linkMap = generateTargetColumnMap(
FieldMetadataType.LINK,
false,
'website',
);
expect(urlMap).toEqual({ text: 'website_text', link: 'website_link' });
expect(linkMap).toEqual({ label: 'websiteLabel', url: 'websiteUrl' });
const moneyMap = generateTargetColumnMap(
FieldMetadataType.MONEY,
const currencyMap = generateTargetColumnMap(
FieldMetadataType.CURRENCY,
true,
'price',
);
expect(moneyMap).toEqual({
amount: '_price_amount',
currency: '_price_currency',
expect(currencyMap).toEqual({
amountMicros: '_priceAmountMicros',
currencyCode: '_priceCurrencyCode',
});
});
@@ -8,7 +8,9 @@ describe('serializeDefaultValue', () => {
});
it('should handle uuid dynamic default value', () => {
expect(serializeDefaultValue({ type: 'uuid' })).toBe('uuid_generate_v4()');
expect(serializeDefaultValue({ type: 'uuid' })).toBe(
'public.uuid_generate_v4()',
);
});
it('should handle now dynamic default value', () => {
@@ -124,44 +124,44 @@ describe('validateDefaultValueBasedOnType', () => {
).toBe(false);
});
// URL type
it('should validate URL default value', () => {
// LINK type
it('should validate LINK default value', () => {
expect(
validateDefaultValueBasedOnType(
{ text: 'http://example.com', link: 'Example' },
FieldMetadataType.URL,
{ label: 'http://example.com', url: 'Example' },
FieldMetadataType.LINK,
),
).toBe(true);
});
it('should return false for invalid URL default value', () => {
it('should return false for invalid LINK default value', () => {
expect(
validateDefaultValueBasedOnType(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error Just for testing purposes
{ text: 123, link: {} },
FieldMetadataType.URL,
{ label: 123, url: {} },
FieldMetadataType.LINK,
),
).toBe(false);
});
// MONEY type
it('should validate MONEY default value', () => {
// CURRENCY type
it('should validate CURRENCY default value', () => {
expect(
validateDefaultValueBasedOnType(
{ amount: 100, currency: 'USD' },
FieldMetadataType.MONEY,
{ amountMicros: 100, currencyCode: 'USD' },
FieldMetadataType.CURRENCY,
),
).toBe(true);
});
it('should return false for invalid MONEY default value', () => {
it('should return false for invalid CURRENCY default value', () => {
expect(
validateDefaultValueBasedOnType(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error Just for testing purposes
{ amount: '100', currency: 'USD' },
FieldMetadataType.MONEY,
{ amountMicros: '100', currencyCode: 'USD' },
FieldMetadataType.CURRENCY,
),
).toBe(false);
});