Add address to array strategy

This commit is contained in:
Aleksejs Kovalovs 2026-01-27 16:13:25 +02:00
parent a9e415ebc6
commit 862a44c426
No known key found for this signature in database
GPG key ID: EBDE72B2FD0FD95E
2 changed files with 43 additions and 0 deletions

View file

@ -109,4 +109,27 @@ describe('ArrayNamingStrategy Integration', () => {
const result = formatter.generateFrontmatter(singleContact, 'contact_');
expect(result.contact_relations).toEqual('SingleRel (partner)');
});
it('should format addresses as an array', () => {
const contactWithAddresses = {
...contact,
addresses: [
{ formattedValue: '123 Main St' },
{ formattedValue: '456 Second St' }
]
} as GoogleContact;
const result = formatter.generateFrontmatter(contactWithAddresses, 'contact_');
expect(result.contact_address).toEqual(['123 Main St', '456 Second St']);
});
it('should format single address as string', () => {
const contactWithSingleAddress = {
...contact,
addresses: [
{ formattedValue: '123 Main St' }
]
} as GoogleContact;
const result = formatter.generateFrontmatter(contactWithSingleAddress, 'contact_');
expect(result.contact_address).toEqual('123 Main St');
});
});

View file

@ -61,6 +61,26 @@ export class AddressAdapter implements FieldAdapter {
});
return results;
} else if (context?.namingStrategy === NamingStrategy.Array) {
// For Array strategy, return array of formatted values
// If only one address, return as string
const addressValues = addresses
.map((item) => item.formattedValue)
.filter((val): val is string => !!val);
if (addressValues.length === 0) {
return [];
}
const first = addressValues[0];
return [
{
value:
addressValues.length === 1 && first !== undefined
? first
: addressValues,
},
];
} else {
// For Default strategy, return formattedValue as before
return addresses