Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from data-provider/v1.6.0
Browse files Browse the repository at this point in the history
V1.6.0
  • Loading branch information
javierbrea authored Jan 11, 2020
2 parents ea12489 + 457af91 commit 745acdd
Show file tree
Hide file tree
Showing 9 changed files with 1,998 additions and 784 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ addons:

script:
- npm run lint
- npm run test:mocks
- npm run test:ci
- npm run build
- npm run coveralls
- 'if [ -n "$SONAR_TOKEN" ]; then sonar-scanner -Dsonar.login=${SONAR_TOKEN}; fi'
# - 'if [ -n "$SONAR_TOKEN" ]; then sonar-scanner -Dsonar.login=${SONAR_TOKEN}; fi'

deploy:
provider: npm
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [TO BE DEPRECATED]
- apis "config" and "clean" methods. Mercury "instances" methods should be used instead.

## [1.6.0] - 2020-01-11
### Fixed
- Upgrade axios version
- Maintain trailing slash in urls with params

### Changed
- Upgrade path-to-regex dependency
- Upgrade devDependencies

## [1.5.0] - 2019-11-24
### Changed
- Upgrade @data-provider/core dependency
Expand Down
6 changes: 6 additions & 0 deletions mocks-server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
options: {
cli: false,
log: "debug"
}
};
2,677 changes: 1,918 additions & 759 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@data-provider/axios",
"version": "1.5.0",
"version": "1.6.0",
"description": "Api Data Provider using Axios",
"keywords": [
"data-provider",
Expand All @@ -26,44 +26,45 @@
"scripts": {
"lint": "eslint src test",
"lint-staged": "lint-staged",
"mocks": "mocks-server --behaviors=./mocks --port=3100 --cli false",
"mocks": "mocks-server",
"build": "rollup --config",
"test": "jest",
"test:mocks": "start-server-and-test mocks http-get://localhost:3100/mocks/behaviors jest",
"mocks-and-test": "start-server-and-test mocks tcp:3100 jest",
"test:ci": "npm run mocks-and-test",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
"peerDependencies": {
"@data-provider/core": "^1.7.0"
},
"dependencies": {
"axios": "0.18.0",
"axios": "0.19.1",
"axios-retry": "^3.1.2",
"lodash": "4.17.15",
"path-to-regexp": "^3.0.0"
"path-to-regexp": "^6.1.0"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"@data-provider/core": "^1.7.0",
"@mocks-server/main": "1.3.0",
"@mocks-server/main": "1.8.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.9.0",
"babel-polyfill": "^6.26.0",
"coveralls": "^3.0.7",
"eslint": "6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-prettier": "^3.1.1",
"husky": "3.0.9",
"coveralls": "^3.0.9",
"eslint": "6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
"husky": "4.0.6",
"jest": "24.9.0",
"lint-staged": "9.4.2",
"prettier": "^1.18.2",
"rollup": "^1.23.1",
"lint-staged": "9.5.0",
"prettier": "^1.19.1",
"rollup": "^1.29.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-uglify": "^6.0.3",
"sinon": "7.5.0",
"rollup-plugin-uglify": "^6.0.4",
"sinon": "8.0.4",
"start-server-and-test": "^1.10.6"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=data-provider
sonar.projectKey=data-provider-axios
sonar.projectVersion=1.5.0
sonar.projectVersion=1.6.0

sonar.javascript.file.suffixes=.js
sonar.sourceEncoding=UTF-8
Expand Down
12 changes: 8 additions & 4 deletions src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Unless required by applicable law or agreed to in writing, software distributed
*/

import { once } from "lodash";
import pathToRegexp from "path-to-regexp";
import { compile } from "path-to-regexp";
import axios from "axios";
import axiosRetry from "axios-retry";
import { Provider } from "@data-provider/core";
Expand Down Expand Up @@ -94,7 +94,9 @@ export class Api extends Provider {
const queryString = query.queryString || query.query;
const urlParams = query.urlParams || query.params;
if (urlParams) {
return `${this.url.base}/${this.url.segment(urlParams)}${this._getQueryString(queryString)}`;
return `${this.url.base}/${this.url.segment(urlParams)}${
this.url.trailingSlash
}${this._getQueryString(queryString)}`;
}
return `${this.url.full}${this._getQueryString(queryString)}`;
}
Expand All @@ -106,10 +108,12 @@ export class Api extends Provider {
this.url = {
base: hasProtocol ? `${splittedUrl[0]}//${splittedUrl[1]}` : "",
full: baseUrl,
segment: pathToRegexp.compile(
trailingSlash: baseUrl[baseUrl.length - 1] === "/" ? "/" : "",
segment: compile(
hasProtocol
? splittedUrl.slice(2, splittedUrl.length).join(PATH_SEP)
: splittedUrl.join(PATH_SEP)
: splittedUrl.join(PATH_SEP),
{ encode: encodeURIComponent }
)
};
}
Expand Down
12 changes: 12 additions & 0 deletions test/custom-queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ describe("Api queries", () => {
expect(axios.stubs.instance.getCall(0).args[0].url).toEqual("/books/foo");
});

it("should replace params in axios request maintaining trailing slash", async () => {
axios.stubs.instance.resetHistory();
const books = new Api("/books/:id/");
books.addCustomQuery({
byId
});

const queriedBooks = books.byId("foo");
await queriedBooks.read();
expect(axios.stubs.instance.getCall(0).args[0].url).toEqual("/books/foo/");
});

it("should replace params in axios request when url includes protocol", async () => {
axios.stubs.instance.resetHistory();
const books = new Api("http://localhost/books/:id");
Expand Down
23 changes: 23 additions & 0 deletions test/queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ describe("Api queries", () => {
expect(axios.stubs.instance.getCall(0).args[0].url).toEqual("/books/foo");
});

it("should replace params encoding them correctly", async () => {
axios.stubs.instance.resetHistory();
const books = new Api("/books/:id").query({
params: {
id: "café"
}
});
await books.read();
expect(axios.stubs.instance.getCall(0).args[0].url).toEqual("/books/caf%C3%A9");
});

it("should replace params in axios request maintaining trailing slash", async () => {
axios.stubs.instance.resetHistory();
const books = new Api("/books/:id/").query({
params: {
id: "foo"
}
});

await books.read();
expect(axios.stubs.instance.getCall(0).args[0].url).toEqual("/books/foo/");
});

it("should replace params in axios request when url includes protocol", async () => {
axios.stubs.instance.resetHistory();
const books = new Api("http://localhost/books/:id").query({
Expand Down

0 comments on commit 745acdd

Please sign in to comment.