Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import './index';
import '../../../infra-sk/modules/theme-chooser-sk';
import { $$ } from 'common-sk/modules/dom';
import fetchMock from 'fetch-mock';
import { pageSets } from '../pageset-selector-sk/test_data';
import 'elements-sk/error-toast-sk';
fetchMock.config.overwriteRoutes = false;
fetchMock.post('begin:/_/page_sets/', pageSets);
// For determining running tasks for the user we just say 2.
fetchMock.postOnce('begin:/_/get', {
data: [], ids: [], pagination: { offset: 0, size: 1, total: 2 }, permissions: [],
});
fetchMock.post('begin:/_/get', {
data: [], ids: [], pagination: { offset: 0, size: 1, total: 0 }, permissions: [],
});
const chromiumPerf = document.createElement('admin-tasks-sk');
($$('#container') as HTMLElement).appendChild(chromiumPerf);
import fetchMock from 'fetch-mock'
import realFetch from 'isomorphic-fetch'
import { endpoint as usersEndpoint, getUser, getUsers, createUser, updateUser, deleteUser } from 'mocks/endpoints/users'
if (process.env.NODE_ENV === 'development') {
// users endpoints
fetchMock.get(new RegExp(`${usersEndpoint}/\\d+/?$`), getUser)
fetchMock.get(new RegExp(`${usersEndpoint}/?`), getUsers)
fetchMock.post(new RegExp(`${usersEndpoint}/?$`), createUser)
fetchMock.put(new RegExp(`${usersEndpoint}/\\d+/?$`), updateUser)
fetchMock.delete(new RegExp(`${usersEndpoint}/\\d+/?$`), deleteUser)
// misc
fetchMock.get(new RegExp('/api/data/initial'), {data: {}})
fetchMock.get(new RegExp('/api/session'), {type: 'session', data: {user: {name: 'miguel', surname: 'martin', email: 'a@a.com', role: 'admin'}}})
fetchMock.delete(new RegExp('/api/session'), {type: 'session', data: []})
fetchMock.post(new RegExp('/api/session'), {type: 'session', data: {token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoibWlndWVsIiwic3VybmFtZSI6Im1hcnRpbiIsImVtYWlsIjoiYUBhLmNvbSIsImlhdCI6MTQ4NzcwMTEyOCwiZXhwIjoxNDg3NzI5OTI4fQ.SUUccKC13c_gdlxUf5FN1o4xeIxF9lyWSJNn3N0PNiw'}})
.catch((unmatchedUrl, options) => {
return realFetch(unmatchedUrl, options)
})
}
it('standard request', () => {
fetchMock.post(API, { pid: '45' });
return store.dispatch(addProject('name', 'descr'))
.then(() => actionExpects(store,
{
type: ADD_PROJECT,
payload: {
name: 'name',
descr: 'descr',
},
meta: { asyncAction: REQUEST_SENT },
},
{
type: ADD_PROJECT,
payload: { pid: '45', name: 'name', descr: 'descr' },
meta: { asyncAction: REPLY_RECEIVED },
}
bodySerializers: {
fake: (data, headers) => ({
body: { ...data, isFake: true },
headers,
}),
},
});
//body containing Primitives, Objects and Arrays types
const post = {
id: '1',
title: 'Love apollo',
items: [{ name: 'first' }, { name: 'second' }],
};
fetchMock.post('/api/posts/newComplexPost', post);
const createPostMutation = gql`
fragment Item on any {
name: String
}
fragment PublishablePostInput on REST {
id: String
title: String
items {
...Item
}
}
mutation publishPost(
$input: PublishablePostInput!
describe('postStopQuery', () => {
const stopQueryEndpoint = 'glob:*/superset/stop_query/*';
fetchMock.post(stopQueryEndpoint, {});
const makeRequest = () => {
const request = actions.postStopQuery(query);
return request(dispatch);
};
it('makes the fetch request', () => {
expect.assertions(1);
return makeRequest().then(() => {
expect(fetchMock.calls(stopQueryEndpoint)).toHaveLength(1);
});
});
it('calls stopQuery', () => {
expect.assertions(1);
let dispatch;
beforeEach(() => {
dispatch = sinon.spy();
});
afterEach(fetchMock.resetHistory);
const fetchQueryEndpoint = 'glob:*/superset/results/*';
fetchMock.get(
fetchQueryEndpoint,
JSON.stringify({ data: mockBigNumber, query: { sqlEditorId: 'dfsadfs' } }),
);
const runQueryEndpoint = 'glob:*/superset/sql_json/*';
fetchMock.post(runQueryEndpoint, '{ "data": ' + mockBigNumber + ' }');
describe('saveQuery', () => {
const saveQueryEndpoint = 'glob:*/savedqueryviewapi/api/create';
fetchMock.post(saveQueryEndpoint, 'ok');
it('posts to the correct url', () => {
expect.assertions(1);
const store = mockStore({});
return store.dispatch(actions.saveQuery(query)).then(() => {
expect(fetchMock.calls(saveQueryEndpoint)).toHaveLength(1);
});
});
it('posts the correct query object', () => {
const store = mockStore({});
describe('saveQuery', () => {
const saveQueryEndpoint = 'glob:*/savedqueryviewapi/api/create';
fetchMock.post(saveQueryEndpoint, 'ok');
it('posts to the correct url', () => {
expect.assertions(1);
const store = mockStore({});
return store.dispatch(actions.saveQuery(query)).then(() => {
expect(fetchMock.calls(saveQueryEndpoint)).toHaveLength(1);
});
});
it('posts the correct query object', () => {
const store = mockStore({});
return store.dispatch(actions.saveQuery(query)).then(() => {
const call = fetchMock.calls(saveQueryEndpoint)[0];
const formData = call[1].body;
Object.keys(query).forEach(key => {
before(() => {
fetchMock.get('get-200', { hello: 'world' });
fetchMock.get('get-204', 204);
fetchMock.post('post-204', 204);
fetchMock.get('get-300', 300);
});
describe('backend sync', () => {
const updateTabStateEndpoint = 'glob:*/tabstateview/*';
fetchMock.put(updateTabStateEndpoint, {});
fetchMock.delete(updateTabStateEndpoint, {});
fetchMock.post(updateTabStateEndpoint, JSON.stringify({ id: 1 }));
const updateTableSchemaEndpoint = 'glob:*/tableschemaview/*';
fetchMock.put(updateTableSchemaEndpoint, {});
fetchMock.delete(updateTableSchemaEndpoint, {});
fetchMock.post(updateTableSchemaEndpoint, JSON.stringify({ id: 1 }));
const getTableMetadataEndpoint = 'glob:*/superset/table/*';
fetchMock.get(getTableMetadataEndpoint, {});
const getExtraTableMetadataEndpoint =
'glob:*/superset/extra_table_metadata/*';
fetchMock.get(getExtraTableMetadataEndpoint, {});
let isFeatureEnabledMock;
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
feature => feature === 'SQLLAB_BACKEND_PERSISTENCE',
);
});
beforeEach(() => {
backend.restore();
backend
.post(`${APIURL}login`, { body: JSON.stringify({ success: true }) })
.post(`${APIURL}recoverpassword`, { body: JSON.stringify({ success: true }) })
.post(`${APIURL}resetpassword`, { body: JSON.stringify({ success: true }) })
.post(`${APIURL}unlockaccount`, { body: JSON.stringify({ success: true }) })
.get(`${APIURL}user`, { body: JSON.stringify({ username: 'username' }) });
});