Skip to content

Commit

Permalink
Merge pull request #132 from paustint/bug-131
Browse files Browse the repository at this point in the history
getFlattenedFields does not correctly handle alias
  • Loading branch information
paustint authored Jan 8, 2021
2 parents 93ce0e9 + 92bd9e1 commit 41a6b55
Show file tree
Hide file tree
Showing 3 changed files with 38 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

## 3.0.1

January 7, 20201

1. `getFlattenedFields` did not properly handle the alias for an aggregate function within an aggregate query. (#131)

## 3.0.0

October 14, 2020
Expand Down
4 changes: 4 additions & 0 deletions src/api/public-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ export function getFlattenedFields(
return param;
});

if (field.alias && (field.isAggregateFn || isAggregateResult)) {
return field.alias;
}

if (field.alias) {
const firstParam = params[0];
// Include the full path and replace the field with the alias
Expand Down
28 changes: 28 additions & 0 deletions test/public-utils-test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,32 @@ export const testCases: FlattenedObjTestCase[] = [
},
},
},
{
testCase: 13,
expectedFields: ['AccountId', 'AcctCreatedDate'],
query: {
fields: [
{
type: 'Field',
field: 'AccountId',
},
{
type: 'FieldFunctionExpression',
functionName: 'MAX',
parameters: ['Account.CreatedDate'],
isAggregateFn: true,
rawValue: 'MAX(Account.CreatedDate)',
alias: 'AcctCreatedDate',
},
],
sObject: 'Contact',
groupBy: {
field: ['AccountId'],
},
},
sfdcObj: {
AccountId: '0016g00000ETu0HAAT',
AcctCreatedDate: '2020-02-28T03:00:31.000+0000',
},
},
];

0 comments on commit 41a6b55

Please sign in to comment.