Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var FakeRest = require('fakerest');
var sinon = require('sinon/lib/sinon/util/fake_server');
var restServer = new FakeRest.Server();
restServer.toggleLogging();
restServer.init(data);
sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url) {
// Do not catch webpack sync, config.js transformation but catch /upload in test env
return url.indexOf('/socket.io/') !== -1 || url.indexOf('config.js') !== -1;
});
var server = sinon.fakeServer.create();
server.autoRespond = true;
server.autoRespondAfter = 0; // answer immediately
server.respondWith(restServer.getHandler());
case `${apiRoot}/users`:
case `${apiRoot}/users/`:
if (method === 'GET') {
res = Actions.fetchAuthors();
}
}
if (res) {
// fake REST server only need expected data on response
const data = {
[ resource ]: singleResource ? [ res.payload ] : map(res.payload),
};
if (data) {
// initialize fake REST server
const restServer = new FakeRest.Server();
restServer.init(data);
// use sinon.js to monkey-patch XmlHttpRequest
const server = sinon.fakeServer.create();
server.respondWith(restServer.getHandler());
// faking a request
const url = singleResource ? `/${resource}/${res.payload.id}` : `/${resource}`;
const xhr = new XMLHttpRequest();
// always a GET (changes are already done)
xhr.open('GET', url, false);
xhr.responseType = 'json';
xhr.send(null);
// restore native XHR constructor
var FakeRest = require('fakerest');
var sinon = require('sinon/lib/sinon/util/fake_server');
var restServer = new FakeRest.Server();
restServer.toggleLogging();
restServer.init(data);
sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url) {
// Do not catch webpack sync, config.js transformation but catch /upload in test env
return url.indexOf('/socket.io/') !== -1 || url.indexOf('config.js') !== -1;
});
var server = sinon.fakeServer.create();
server.autoRespond = true;
server.autoRespondAfter = 0; // answer immediately
server.respondWith(restServer.getHandler());
export default (data, loggingEnabled = false): DataProvider => {
const restServer = new FakeRest.Server();
restServer.init(data);
if (window) {
// give way to update data in the console
(window as any).restServer = restServer;
}
function getResponse(type, resource, params) {
switch (type) {
case 'getList': {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query = {
sort: [field, order],
range: [(page - 1) * perPage, page * perPage - 1],
filter: params.filter,
};
export default (data, loggingEnabled = false) => {
const restServer = new FakeRest.Server();
restServer.init(data);
function getResponse(type, resource, params) {
switch (type) {
case GET_LIST: {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query = {
sort: [field, order],
range: [(page - 1) * perPage, (page * perPage) - 1],
filter: params.filter,
};
return {
data: restServer.getAll(resource, query),
total: restServer.getCount(resource, { filter: params.filter }),
};
export default (data, loggingEnabled = false) => {
const restServer = new FakeRest.Server();
restServer.init(data);
function getResponse(type, resource, params) {
switch (type) {
case GET_LIST: {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query = {
sort: [field, order],
range: [(page - 1) * perPage, (page * perPage) - 1],
filter: params.filter,
};
return {
data: restServer.getAll(resource, query),
total: restServer.getCount(resource, { filter: params.filter }),
};