Fix phone deletion (#12821)

Fixes https://github.com/twentyhq/core-team-issues/issues/1124
This commit is contained in:
Marie
2025-06-24 15:12:40 +02:00
committed by GitHub
parent 2da66af26a
commit 540f3ffd67
2 changed files with 25 additions and 8 deletions

View File

@ -1,8 +1,3 @@
import {
isDefined,
parseJson,
removeUndefinedFields,
} from 'twenty-shared/utils';
import { isNonEmptyString } from '@sniptt/guards'; import { isNonEmptyString } from '@sniptt/guards';
import { import {
CountryCallingCode, CountryCallingCode,
@ -11,6 +6,11 @@ import {
getCountryCallingCode, getCountryCallingCode,
parsePhoneNumberWithError, parsePhoneNumberWithError,
} from 'libphonenumber-js'; } from 'libphonenumber-js';
import {
isDefined,
parseJson,
removeUndefinedFields,
} from 'twenty-shared/utils';
import { import {
RecordTransformerException, RecordTransformerException,
@ -165,7 +165,7 @@ const validateAndInferPhoneInput = ({
countryCode, countryCode,
}); });
if (isDefined(number)) { if (isDefined(number) && isNonEmptyString(number)) {
return validateAndInferMetadataFromPrimaryPhoneNumber({ return validateAndInferMetadataFromPrimaryPhoneNumber({
number, number,
callingCode, callingCode,

View File

@ -117,6 +117,23 @@ const SUCCESSFUL_TEST_CASES: EachTestingContext<CreatePhoneFieldMetadataTestCase
}, },
}, },
}, },
{
title: 'create primary phone field with empty strings in payload',
context: {
input: {
primaryPhoneNumber: '',
primaryPhoneCountryCode: '' as CountryCode,
primaryPhoneCallingCode: '',
additionalPhones: null,
},
expected: {
primaryPhoneNumber: '',
primaryPhoneCountryCode: '' as CountryCode,
primaryPhoneCallingCode: '',
additionalPhones: null,
},
},
},
{ {
title: 'create additional phone field with number and other information', title: 'create additional phone field with number and other information',
context: { context: {
@ -306,7 +323,7 @@ const FAILING_TEST_CASES: EachTestingContext<CreatePhoneFieldMetadataTestCase>[]
describe('Phone field metadata tests suite', () => { describe('Phone field metadata tests suite', () => {
let createdObjectMetadataId: string; let createdObjectMetadataId: string;
beforeEach(async () => { beforeAll(async () => {
const { data } = await forceCreateOneObjectMetadata({ const { data } = await forceCreateOneObjectMetadata({
input: { input: {
nameSingular: 'myTestObject', nameSingular: 'myTestObject',
@ -337,7 +354,7 @@ describe('Phone field metadata tests suite', () => {
}); });
}); });
afterEach(async () => { afterAll(async () => {
await deleteOneObjectMetadata({ await deleteOneObjectMetadata({
input: { idToDelete: createdObjectMetadataId }, input: { idToDelete: createdObjectMetadataId },
}); });