feat(sqllab): save query parameters in database (#21682)

This commit is contained in:
Mayur
2022-10-07 12:49:14 +05:30
committed by GitHub
parent 882bfb67ae
commit 61319fd759
11 changed files with 132 additions and 61 deletions

View File

@@ -24,7 +24,12 @@ import thunk from 'redux-thunk';
import shortid from 'shortid';
import * as featureFlags from 'src/featureFlags';
import * as actions from 'src/SqlLab/actions/sqlLab';
import { defaultQueryEditor, query, initialState } from 'src/SqlLab/fixtures';
import {
defaultQueryEditor,
query,
initialState,
queryId,
} from 'src/SqlLab/fixtures';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
@@ -59,11 +64,11 @@ describe('async actions', () => {
fetchMock.post(runQueryEndpoint, `{ "data": ${mockBigNumber} }`);
describe('saveQuery', () => {
const saveQueryEndpoint = 'glob:*/savedqueryviewapi/api/create';
const saveQueryEndpoint = 'glob:*/api/v1/saved_query/';
fetchMock.post(saveQueryEndpoint, { results: { json: {} } });
const makeRequest = () => {
const request = actions.saveQuery(query);
const request = actions.saveQuery(query, queryId);
return request(dispatch, () => initialState);
};
@@ -71,18 +76,20 @@ describe('async actions', () => {
expect.assertions(1);
const store = mockStore(initialState);
return store.dispatch(actions.saveQuery(query)).then(() => {
return store.dispatch(actions.saveQuery(query, queryId)).then(() => {
expect(fetchMock.calls(saveQueryEndpoint)).toHaveLength(1);
});
});
it('posts the correct query object', () => {
const store = mockStore(initialState);
return store.dispatch(actions.saveQuery(query)).then(() => {
return store.dispatch(actions.saveQuery(query, queryId)).then(() => {
const call = fetchMock.calls(saveQueryEndpoint)[0];
const formData = call[1].body;
Object.keys(query).forEach(key => {
expect(formData.get(key)).toBeDefined();
const formData = JSON.parse(call[1].body);
const mappedQueryToServer = actions.convertQueryToServer(query);
Object.keys(mappedQueryToServer).forEach(key => {
expect(formData[key]).toBeDefined();
});
});
});
@@ -370,12 +377,13 @@ describe('async actions', () => {
queryEditor: {
name: 'Copy of Dummy query editor',
dbId: 1,
schema: null,
schema: query.schema,
autorun: true,
sql: 'SELECT * FROM something',
queryLimit: undefined,
maxRow: undefined,
id: 'abcd',
templateParams: undefined,
},
},
];
@@ -635,7 +643,9 @@ describe('async actions', () => {
},
];
return store
.dispatch(actions.queryEditorSetTitle(queryEditor, name))
.dispatch(
actions.queryEditorSetTitle(queryEditor, name, queryEditor.id),
)
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);