diff --git a/src/data-request/transformations/wallet-data-to-connect-button.spec.ts b/src/data-request/transformations/wallet-data-to-connect-button.spec.ts new file mode 100644 index 00000000..dfa07bee --- /dev/null +++ b/src/data-request/transformations/wallet-data-to-connect-button.spec.ts @@ -0,0 +1,32 @@ + +import { transformWalletDataToConnectButton } from './wallet-data-to-connect-button' +describe('transformWalletDataToConnectButton', () => { + describe('when persona data contain empty arrays', () => { + it('should not fail', () => { + // Arrange + const walletData = { + personaData: [ + { + entry: 'emailAddresses', + fields: [], + }, + { + entry: 'phoneNumbers', + fields: [], + }, + ], + } as any + + // Act + const result = transformWalletDataToConnectButton(walletData) + + // Assert + expect(result).toEqual({ + accounts: [], + personaLabel: '', + connected: false, + personaData: [], + }) + }) + }) +}) diff --git a/src/data-request/transformations/wallet-data-to-connect-button.ts b/src/data-request/transformations/wallet-data-to-connect-button.ts index 189ffc35..7f1b4690 100644 --- a/src/data-request/transformations/wallet-data-to-connect-button.ts +++ b/src/data-request/transformations/wallet-data-to-connect-button.ts @@ -4,8 +4,8 @@ export const transformWalletDataToConnectButton = (walletData: WalletData) => { const accounts = walletData.accounts ?? [] const personaLabel = walletData?.persona?.label ?? '' const connected = !!walletData?.persona - const personaData = walletData.personaData - .map((item) => { + const personaData = walletData?.personaData + ?.map((item) => { if (item.entry === 'fullName') { const { variant, givenNames, familyName, nickname } = item.fields const value = @@ -34,11 +34,11 @@ export const transformWalletDataToConnectButton = (walletData: WalletData) => { }) .filter( ( - item + item, ): item is { value: string field: string - } => !!item && !!item.value.trim() + } => !!item && !!item.value?.trim(), ) return { accounts, personaLabel, connected, personaData }