diff --git a/client/package.json b/client/package.json index fc459857..56ee1a98 100644 --- a/client/package.json +++ b/client/package.json @@ -16,6 +16,7 @@ "test": "export NODE_PATH=src && mocha src/lib-test/preprocessor.js --compilers js:babel-core/register --recursive src/**/**/__tests__/*-test.js" }, "devDependencies": { + "axios-mock-adapter": "^1.15.0", "babel-core": "^5.8.22", "babel-plugin-transform-class-properties": "^6.11.5", "babel-register": "^6.7.2", @@ -42,7 +43,6 @@ "gulp-uglify": "^2.1.2", "gulp-util": "^3.0.6", "humps": "^0.6.0", - "jquery-mockjax": "^2.1.0", "jsdom": "^8.4.1", "morgan": "^1.6.1", "proxyquire": "^1.7.4", @@ -55,17 +55,18 @@ }, "dependencies": { "app-module-path": "^1.0.3", + "axios": "^0.18.0", "chart.js": "^2.4.0", "classnames": "^2.2.5", "draft-js": "^0.10.0", "draft-js-export-html": "^0.5.2", "history": "^3.0.0", "html-to-text": "^4.0.0", - "jquery": "^2.1.4", "keycode": "^2.1.4", "localStorage": "^1.0.3", "lodash": "^3.10.0", "messageformat": "^0.2.2", + "qs": "^6.5.2", "react": "^15.4.2", "react-chartjs-2": "^2.0.0", "react-document-title": "^1.0.2", diff --git a/client/src/lib-app/fixtures-loader.js b/client/src/lib-app/fixtures-loader.js index dc02c382..fd725ea2 100644 --- a/client/src/lib-app/fixtures-loader.js +++ b/client/src/lib-app/fixtures-loader.js @@ -1,6 +1,8 @@ const _ = require('lodash'); -const $ = require('jquery'); -const mockjax = require('jquery-mockjax')($, window); +const axios = require('axios'); +const MockAdapter = require('axios-mock-adapter'); +const qs = require('qs'); +const mock = new MockAdapter(axios); let fixtures = (function () { let fixturesData = []; @@ -23,12 +25,9 @@ fixtures.add(require('data/fixtures/system-fixtures')); fixtures.add(require('data/fixtures/article-fixtures')); _.each(fixtures.getAll(), function (fixture) { - mockjax({ - contentType: fixture.contentType || 'application/json', - url: 'http://localhost:3000/api' + fixture.path, - responseTime: fixture.time || 500, - response: function (settings) { - this.responseText = fixture.response(settings.data); - } + mock.onAny('http://localhost:3000/api' + fixture.path).reply(function(config) { + return new Promise(function(resolve, reject) { + setTimeout(() => resolve([200, fixture.response(qs.parse(config.data))]), fixture.time || 500); + }); }); }); diff --git a/client/src/lib-core/APIUtils.js b/client/src/lib-core/APIUtils.js index e655deb4..c9c544f5 100644 --- a/client/src/lib-core/APIUtils.js +++ b/client/src/lib-core/APIUtils.js @@ -1,5 +1,6 @@ const _ = require('lodash'); -const $ = require('jquery'); +const axios = require('axios'); +const qs = require('qs'); const APIUtils = { @@ -11,21 +12,14 @@ const APIUtils = { data: data }; - if(dataAsForm) { - options = { - url: path, - type: method, - data: data, - processData: false, - contentType: false - }; + if(!dataAsForm){ + options.headers = {'content-type': 'application/x-www-form-urlencoded'}; + options.data = qs.stringify(options.data); } - $.ajax(options) - .done(resolve) - .fail((jqXHR, textStatus) => { - reject(textStatus); - }); + axios(options) + .then((result) => resolve(result.data)) + .catch(() => reject()); }; },