Skip to content

Commit

Permalink
CARTO: Include aggregation and geoColumn in POST (#7404)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Nov 15, 2022
1 parent 158838f commit 2eb5140
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions modules/carto/src/api/maps-v3-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ export async function mapInstantiation({
const body = JSON.stringify({
q: source,
client: clientId || DEFAULT_CLIENT,
aggregationResLevel,
aggregationExp,
geoColumn,
queryParameters
});
return await requestJson({
Expand Down
19 changes: 17 additions & 2 deletions test/modules/carto/api/maps-api-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ test('fetchLayerData#post', async t => {
const accessToken = 'XXX';
const headers = {'Custom-Header': 'Custom-Header-Value'};

const source = `SELECT *, '${Array(2048).join('x')}' as r FROM cartobq.testtables.points_10k`;
const aggregationExp = 'avg(value) as value';
const aggregationResLevel = 4;
const geoColumn = 'customGeom';
const queryParameters = ['a', 'b'];
const props = {aggregationExp, aggregationResLevel, geoColumn, queryParameters};

setDefaultCredentials({
apiVersion: API_VERSIONS.V3,
apiBaseUrl: 'http://carto-api',
Expand All @@ -545,6 +552,13 @@ test('fetchLayerData#post', async t => {
'Custom-Header-Value',
'should include custom header in instantiation request'
);
t.ok(options.body, 'should have POST body');
const body = JSON.parse(options.body);
t.is(body.q, source, 'should have query in body');
t.is(body.client, 'deck-gl-carto', 'should have client in body');
for (const prop in props) {
t.deepEqual(body[prop], props[prop], `should have ${prop} in body`);
}

return Promise.resolve({
json: () => {
Expand Down Expand Up @@ -575,9 +589,10 @@ test('fetchLayerData#post', async t => {
await fetchLayerData({
type: MAP_TYPES.QUERY,
connection: 'connection_name',
source: `SELECT *, '${Array(2048).join('x')}' as r FROM cartobq.testtables.points_10k`,
source,
credentials: getDefaultCredentials(),
headers
headers,
...props
});
} catch (e) {
t.error(e, 'should not throw');
Expand Down

0 comments on commit 2eb5140

Please sign in to comment.