Skip to content

Commit

Permalink
feat: make GET request work for fetchExploreJson, closes apache#668 (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored and zhaoyongjie committed Nov 25, 2021
1 parent e753c6e commit 9034774
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export default async function fetchExploreJson({
...requestConfig,
method,
endpoint,
// TODO: Have to transform formData as query string for GET
postPayload: { form_data: formData },
searchParams:
method === 'GET' ? new URLSearchParams({ form_data: JSON.stringify(formData) }) : undefined,
postPayload: method === 'POST' ? { form_data: formData } : undefined,
});
return json as LegacyChartDataResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,38 @@ describe('fetchExploreJson()', () => {
field2: 'def',
});
});
it('uses GET when specified', () => {
fetchMock.get('glob:*/superset/explore_json/', {
it('uses GET when specified', async () => {
expect.assertions(4);
const mockUrl = 'glob:*/superset/explore_json/*';

fetchMock.get(mockUrl, {
field1: 'abc',
field2: 'def',
});

return expect(
fetchExploreJson({
method: 'GET',
formData: {
granularity: 'minute',
viz_type: 'word_cloud',
datasource: '1__table',
},
}),
).resolves.toEqual({
const result = await fetchExploreJson({
method: 'GET',
formData: {
granularity: 'minute',
viz_type: 'word_cloud',
datasource: '1__table',
},
});

expect(result).toEqual({
field1: 'abc',
field2: 'def',
});
const mockCalls = fetchMock.calls(mockUrl);
expect(mockCalls).toHaveLength(1);
expect(mockCalls[0][0]).toEqual(
'http://localhost/superset/explore_json/?form_data=%7B%22granularity%22%3A%22minute%22%2C%22viz_type%22%3A%22word_cloud%22%2C%22datasource%22%3A%221__table%22%7D',
);
expect(mockCalls[0][1]).toEqual(
expect.objectContaining({
method: 'GET',
body: undefined,
}),
);
});
});

0 comments on commit 9034774

Please sign in to comment.