From 4fe967631807b819c41f09684c09b11258412c1d Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Fri, 18 May 2018 14:32:18 -0300 Subject: [PATCH 1/2] Replaces JQuery ajax requests with Axios requests --- client/package.json | 2 ++ client/src/lib-core/APIUtils.js | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/client/package.json b/client/package.json index 85ed781b..d81b2575 100644 --- a/client/package.json +++ b/client/package.json @@ -55,6 +55,7 @@ }, "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", @@ -65,6 +66,7 @@ "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-core/APIUtils.js b/client/src/lib-core/APIUtils.js index e655deb4..a1de236f 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()); }; }, From a58c36c9b4d54470255ebf41a85397804566635f Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Mon, 11 Jun 2018 21:00:43 -0300 Subject: [PATCH 2/2] Replaced mockjax with axios-mock-request --- client/package.json | 3 +-- client/src/lib-app/fixtures-loader.js | 17 ++++++++--------- client/src/lib-core/APIUtils.js | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/client/package.json b/client/package.json index d81b2575..b4c6fc6c 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", @@ -61,7 +61,6 @@ "draft-js": "^0.10.0", "draft-js-export-html": "^0.5.2", "history": "^3.0.0", - "jquery": "^2.1.4", "keycode": "^2.1.4", "localStorage": "^1.0.3", "lodash": "^3.10.0", 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 a1de236f..c9c544f5 100644 --- a/client/src/lib-core/APIUtils.js +++ b/client/src/lib-core/APIUtils.js @@ -13,7 +13,7 @@ const APIUtils = { }; if(!dataAsForm){ - options.headers = {'content-type': 'application/x-www-form-urlencoded'}, + options.headers = {'content-type': 'application/x-www-form-urlencoded'}; options.data = qs.stringify(options.data); }