Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept headers on import #17080

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions superset-frontend/src/components/ImportModal/ImportModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import { styledMount as mount } from 'spec/helpers/theming';
import { ReactWrapper } from 'enzyme';
import fetchMock from 'fetch-mock';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { Upload } from 'src/common/components';
import Button from 'src/components/Button';
import { ImportResourceName } from 'src/views/CRUD/types';
Expand All @@ -31,6 +33,10 @@ import Modal from 'src/components/Modal';
const mockStore = configureStore([thunk]);
const store = mockStore({});

const DATABASE_IMPORT_URL = 'glob:*/api/v1/database/import/';
fetchMock.config.overwriteRoutes = true;
fetchMock.post(DATABASE_IMPORT_URL, { result: 'OK' });

const requiredProps = {
resourceName: 'database' as ImportResourceName,
resourceLabel: 'database',
Expand Down Expand Up @@ -101,6 +107,33 @@ describe('ImportModelsModal', () => {
expect(wrapper.find(Button).at(2).prop('disabled')).toBe(false);
});

it('should POST with request header `Accept: application/json`', async () => {
const file = new File([new ArrayBuffer(1)], 'model_export.zip');
act(() => {
const handler = wrapper.find(Upload).prop('onChange');
if (handler) {
handler({
fileList: [],
file: {
name: 'model_export.zip',
originFileObj: file,
uid: '-1',
size: 0,
type: 'zip',
},
});
}
});
wrapper.update();

wrapper.find(Button).at(2).simulate('click');
await waitForComponentToPaint(wrapper);
expect(fetchMock.calls(DATABASE_IMPORT_URL)[0][1]?.headers).toStrictEqual({
Accept: 'application/json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

'X-CSRFToken': '1234',
});
});

it('should render password fields when needed for import', () => {
const wrapperWithPasswords = mount(
<ImportModelsModal
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export function useImportResource(
return SupersetClient.post({
endpoint: `/api/v1/${resourceName}/import/`,
body: formData,
headers: { Accept: 'application/json' },
})
.then(() => true)
.catch(response =>
Expand Down