Skip to content

Commit

Permalink
Merge pull request #235 from jetstreamapp/bug/getFlattenedField
Browse files Browse the repository at this point in the history
Fix getFlattenedFields with invalid data
  • Loading branch information
paustint authored Jul 25, 2023
2 parents 15475d1 + 64bfdfe commit f3f0a57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.9.2

July 24, 2023

Ensure `getFlattenedFields` does not throw exception if query does not have `fields` property.

## 4.9.1

May 29, 2023
Expand Down
3 changes: 3 additions & 0 deletions src/api/public-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export function getFlattenedFields(
}
query = isFieldSubquery(query) ? query.subquery : query;
const fields = query.fields;
if (!fields) {
return [];
}
// if a relationship field is used in a group by, then Salesforce removes the relationship portion of the field in the returned records
let groupByFields: { [field: string]: string } = {};
if (!!query.groupBy) {
Expand Down
6 changes: 6 additions & 0 deletions test/public-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,10 @@ describe('getFlattenedFields', () => {
const fields = utils.getFlattenedFields(fieldSubquery.subquery);
expect(fields).toEqual(['LastName']);
});

it(`Should not blow up with invalid input`, () => {
expect(utils.getFlattenedFields({})).toEqual([]);
expect(utils.getFlattenedFields(null as any)).toEqual([]);
expect(utils.getFlattenedFields({ fields: [] })).toEqual([]);
});
});

0 comments on commit f3f0a57

Please sign in to comment.