From cc7d37d6183990b7d17fbf62183a43acbb672400 Mon Sep 17 00:00:00 2001 From: cesarParra Date: Tue, 26 Nov 2024 15:34:03 -0400 Subject: [PATCH 1/2] Fixes issue when parsing a picklist custom field that has a single value option --- .../reflect-custom-field-sources.spec.ts | 69 ++++++++++++++++++- .../sobject/parse-picklist-values.ts | 14 +++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/core/reflection/sobject/__test__/reflect-custom-field-sources.spec.ts b/src/core/reflection/sobject/__test__/reflect-custom-field-sources.spec.ts index 8b1e776b..ef08100a 100644 --- a/src/core/reflection/sobject/__test__/reflect-custom-field-sources.spec.ts +++ b/src/core/reflection/sobject/__test__/reflect-custom-field-sources.spec.ts @@ -107,7 +107,7 @@ describe('when parsing custom field metadata', () => { assertEither(result, (data) => expect(data[0].type.description).toBe('A Photo URL field')); }); - test('can parse picklist values', async () => { + test('can parse picklist values when there are multiple picklist values available', async () => { const unparsed: UnparsedCustomFieldBundle = { type: 'customfield', name: 'Status__c', @@ -153,6 +153,73 @@ describe('when parsing custom field metadata', () => { assertEither(result, (data) => expect(data[0].type.pickListValues).toEqual(['Staging', 'Active', 'Inactive'])); }); + test('can parse picklist values when there is a single value available', async () => { + const unparsed: UnparsedCustomFieldBundle = { + type: 'customfield', + name: 'Status__c', + parentName: 'MyFirstObject__c', + filePath: 'src/field/Status__c.field-meta.xml', + content: ` + + + Status__c + false + + true + false + Status + Picklist + + true + + false + + Staging + false + + + + + `, + }; + + const result = await reflectCustomFieldSources([unparsed])(); + + assertEither(result, (data) => expect(data[0].type.description).toBe('Status')); + assertEither(result, (data) => expect(data[0].type.pickListValues).toEqual(['Staging'])); + }); + + test('can parse picklist values when there are no values', async () => { + const unparsed: UnparsedCustomFieldBundle = { + type: 'customfield', + name: 'Status__c', + parentName: 'MyFirstObject__c', + filePath: 'src/field/Status__c.field-meta.xml', + content: ` + + + Status__c + false + + true + false + Status + Picklist + + true + + false + + + `, + }; + + const result = await reflectCustomFieldSources([unparsed])(); + + assertEither(result, (data) => expect(data[0].type.description).toBe('Status')); + assertEither(result, (data) => expect(data[0].type.pickListValues).toEqual(undefined)); + }); + test('An error is returned when the XML is in an invalid format', async () => { const unparsed: UnparsedCustomFieldBundle = { type: 'customfield', diff --git a/src/core/reflection/sobject/parse-picklist-values.ts b/src/core/reflection/sobject/parse-picklist-values.ts index c9a47dfb..75180a1b 100644 --- a/src/core/reflection/sobject/parse-picklist-values.ts +++ b/src/core/reflection/sobject/parse-picklist-values.ts @@ -22,11 +22,21 @@ function toPickListValues(customField: MaybeTyped): string[] | undefined { if ('valueSetDefinition' in valueSet) { const valueSetDefinition = valueSet.valueSetDefinition as object; if ('value' in valueSetDefinition) { - const pickListValues = valueSetDefinition.value as Record<'fullName', string>[]; - return pickListValues.filter((each) => 'fullName' in each).map((current) => current.fullName); + const pickListValues = valueSetDefinition.value as Record<'fullName', string>[] | Record<'fullName', string>; + if (isArrayOfValues(pickListValues)) { + return pickListValues.filter((each) => 'fullName' in each).map((current) => current.fullName); + } else { + return [pickListValues.fullName]; + } } } } return undefined; } + +function isArrayOfValues( + value: Record | Record[], +): value is Record[] { + return Array.isArray(value); +} From 9e84cbcc8fc94e92ff6566e0d85a70c19123331c Mon Sep 17 00:00:00 2001 From: cesarParra Date: Tue, 26 Nov 2024 15:36:37 -0400 Subject: [PATCH 2/2] Publishing patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9928cf98..a0687908 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cparra/apexdocs", - "version": "3.7.0", + "version": "3.7.1", "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.", "keywords": [ "apex",