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 {
CountryCallingCode,
@ -11,6 +6,11 @@ import {
getCountryCallingCode,
parsePhoneNumberWithError,
} from 'libphonenumber-js';
import {
isDefined,
parseJson,
removeUndefinedFields,
} from 'twenty-shared/utils';
import {
RecordTransformerException,
@ -165,7 +165,7 @@ const validateAndInferPhoneInput = ({
countryCode,
});
if (isDefined(number)) {
if (isDefined(number) && isNonEmptyString(number)) {
return validateAndInferMetadataFromPrimaryPhoneNumber({
number,
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',
context: {
@ -306,7 +323,7 @@ const FAILING_TEST_CASES: EachTestingContext<CreatePhoneFieldMetadataTestCase>[]
describe('Phone field metadata tests suite', () => {
let createdObjectMetadataId: string;
beforeEach(async () => {
beforeAll(async () => {
const { data } = await forceCreateOneObjectMetadata({
input: {
nameSingular: 'myTestObject',
@ -337,7 +354,7 @@ describe('Phone field metadata tests suite', () => {
});
});
afterEach(async () => {
afterAll(async () => {
await deleteOneObjectMetadata({
input: { idToDelete: createdObjectMetadataId },
});