fix: guard against invalid date and undefined links field value (#16039)
closes https://github.com/twentyhq/twenty/issues/15854 - Add `isValid()` check in `formatDateISOStringToDateTime` before calling `formatInTimeZone` - Add `isDefined()` guard in `getFieldLinkDefinedLinks` (mirrors `phonesUtils` pattern) before: https://github.com/user-attachments/assets/1eb89fa4-70b6-4794-8860-0a42522598b5 https://github.com/user-attachments/assets/781c7d37-c435-4832-98d4-8e6925b51e10 after: https://github.com/user-attachments/assets/b1c22d25-4e8e-45c3-af98-be1684a5962e https://github.com/user-attachments/assets/ce084a9d-03b8-4f88-8522-a32cb1b7cf2f --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
+17
@@ -1,6 +1,23 @@
|
||||
import { getFieldLinkDefinedLinks } from '@/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks';
|
||||
import { type FieldLinksValue } from '@/object-record/record-field/ui/types/FieldMetadata';
|
||||
|
||||
describe('getFieldLinkDefinedLinks', () => {
|
||||
describe('Field value', () => {
|
||||
it('should return an empty array if fieldValue is undefined', () => {
|
||||
const result = getFieldLinkDefinedLinks(
|
||||
undefined as unknown as FieldLinksValue,
|
||||
);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return an empty array if fieldValue is null', () => {
|
||||
const result = getFieldLinkDefinedLinks(
|
||||
null as unknown as FieldLinksValue,
|
||||
);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Primary link', () => {
|
||||
it('should not return primary link when primaryLinkUrl is null', () => {
|
||||
expect(
|
||||
|
||||
+4
@@ -3,6 +3,10 @@ import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { isDefined, isValidUrl } from 'twenty-shared/utils';
|
||||
|
||||
export const getFieldLinkDefinedLinks = (fieldValue: FieldLinksValue) => {
|
||||
if (!isDefined(fieldValue)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
isNonEmptyString(fieldValue.primaryLinkUrl)
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user