Skip to content

Commit 9fc5dd6

Browse files
committed
fix: update secondaryType validation and add tests for convertFormulaSecondaryTypeToEvaluatorType
Refs: Resolves betterstack error b6ef8c57fe46e77538723abcec6d649e1812a7ac8f4686727753c8351e0e4eae
1 parent 0e57f0a commit 9fc5dd6

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

libs/features/create-object-and-fields/src/CreateFieldsImportExport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const CreateFieldsImportExport = ({ selectedOrg, rows, onImportRows, onLo
104104
if (field === 'deleteConstraint' && value) {
105105
value = ['SetNull', 'Cascade', 'Restrict'].includes(value) ? value : 'SetNull';
106106
}
107-
if (field === 'secondaryType' && value) {
107+
if (field === 'secondaryType') {
108108
value = ensureValidSecondaryType(value);
109109
}
110110
if (field === 'writeRequiresMasterRead' && value) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, test } from 'vitest';
2+
import { SalesforceFieldType } from '../create-fields-types';
3+
import { convertFormulaSecondaryTypeToEvaluatorType } from '../create-fields-utils';
4+
5+
describe('create-fields-utils#convertFormulaSecondaryTypeToEvaluatorType', () => {
6+
test.each([
7+
['Checkbox', 'boolean'],
8+
['Currency', 'number'],
9+
['Date', 'date'],
10+
['DateTime', 'datetime'],
11+
['Number', 'number'],
12+
['Percent', 'number'],
13+
['Time', 'time'],
14+
['Text', 'string'],
15+
])('maps secondary type %s to %s', (input, expected) => {
16+
expect(convertFormulaSecondaryTypeToEvaluatorType(input as SalesforceFieldType)).toBe(expected);
17+
});
18+
19+
// Imported fields can omit the secondaryType column, leaving the value undefined - it must not throw
20+
test.each([undefined, null])('returns string for missing secondary type (%s)', (input) => {
21+
expect(convertFormulaSecondaryTypeToEvaluatorType(input as unknown as SalesforceFieldType)).toBe('string');
22+
});
23+
24+
test('returns string for an unknown secondary type', () => {
25+
expect(convertFormulaSecondaryTypeToEvaluatorType('SomethingElse' as SalesforceFieldType)).toBe('string');
26+
});
27+
});

libs/shared/ui-core/src/create-fields/create-fields-utils.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ export function ensureValidSecondaryType(type: string): string {
7676
return 'Text';
7777
}
7878

79-
export function convertFormulaSecondaryTypeToEvaluatorType(type: SalesforceFieldType): FormulaReturnType {
79+
export function convertFormulaSecondaryTypeToEvaluatorType(type: Maybe<SalesforceFieldType>): FormulaReturnType {
80+
if (!type) {
81+
return 'string';
82+
}
8083
return ({
8184
checkbox: 'boolean',
8285
currency: 'number',

0 commit comments

Comments
 (0)