Skip to content

Commit

Permalink
fix create url
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymild committed Oct 10, 2021
1 parent 5890b5c commit ceb5ab6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/CurlHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export class CurlHelper {

getUrl() {
if (this.request.baseURL) {
return this.request.baseURL + "/" + this.request.url;
let baseUrl = this.request.baseURL
let url = this.request.url
let finalUrl = baseUrl + "/" + url
return finalUrl
.replace(/\/{2,}/g, '/')
.replace("http:/", "http://")
.replace("https:/", "https://")
}
return this.request.url;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/curlirize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ describe("Testing curlirize", () => {
console.error(err);
});
});

it("cut middle slash", (done) => {
const api = axios.create({
baseURL: 'http://localhost:7500/',
})
curlirize(api)
api.post("/api/", null, {params: {test: 1, text: 'sim'}})
.then((res) => {
expect(res.config.curlCommand).toBeDefined();
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/api/?test=1&text=sim" -H "Content-Type:application/x-www-form-urlencoded"');
done();
})
.catch((err) => {
console.error(err);
});
});
});

describe("Testing curl-helper module", () => {
Expand Down

0 comments on commit ceb5ab6

Please sign in to comment.