Skip to content

Commit

Permalink
fix(picking): Avoid case changes on column names (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Dec 19, 2024
1 parent 7b73fe4 commit a0305d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/widget-sources/widget-base-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
},
opts: {abortController},
}).then((res: FeaturesModelResponse) => ({
rows: normalizeObjectKeys(res.rows),
}));
// Avoid `normalizeObjectKeys()`, which changes column names.
}).then(({rows}: FeaturesModelResponse) => ({rows}));
}

/****************************************************************************
Expand Down
25 changes: 20 additions & 5 deletions test/widget-sources/widget-base-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,24 @@ test('getFeatures', async () => {
});

const expectedRows = [
{_carto_feature_id: 'a', name: 'Veggie Mart', revenue: 1200},
{_carto_feature_id: 'b', name: 'EZ Drive Thru', revenue: 400},
{_carto_feature_id: 'c', name: "Buddy's Convenience", revenue: 800},
{
_carto_feature_id: 'a',
name: 'Veggie Mart',
revenue: 1200,
CaseSensitive: 1,
},
{
_carto_feature_id: 'b',
name: 'EZ Drive Thru',
revenue: 400,
CaseSensitive: 2,
},
{
_carto_feature_id: 'c',
name: "Buddy's Convenience",
revenue: 800,
CaseSensitive: 3,
},
];

const mockFetch = vi
Expand All @@ -248,7 +263,7 @@ test('getFeatures', async () => {
vi.stubGlobal('fetch', mockFetch);

const actualFeatures = await widgetSource.getFeatures({
columns: ['_carto_feature_id', 'name', 'revenue'],
columns: ['_carto_feature_id', 'name', 'revenue', 'CaseSensitive'],
featureIds: ['a', 'b', 'c'],
dataType: 'points',
});
Expand All @@ -261,7 +276,7 @@ test('getFeatures', async () => {
type: 'test',
source: 'test-data',
params: JSON.stringify({
columns: ['_carto_feature_id', 'name', 'revenue'],
columns: ['_carto_feature_id', 'name', 'revenue', 'CaseSensitive'],
dataType: 'points',
featureIds: ['a', 'b', 'c'],
limit: 1000,
Expand Down

0 comments on commit a0305d4

Please sign in to comment.