From ceb5ab6deb9dabb31bed5e999c3030824eaa7a98 Mon Sep 17 00:00:00 2001 From: sergeymild Date: Sun, 10 Oct 2021 15:49:04 +0300 Subject: [PATCH] fix create url --- src/lib/CurlHelper.js | 8 +++++++- tests/curlirize.spec.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/lib/CurlHelper.js b/src/lib/CurlHelper.js index 1c6a6e9..5619179 100644 --- a/src/lib/CurlHelper.js +++ b/src/lib/CurlHelper.js @@ -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; } diff --git a/tests/curlirize.spec.js b/tests/curlirize.spec.js index 7062a0d..a6a6c40 100644 --- a/tests/curlirize.spec.js +++ b/tests/curlirize.spec.js @@ -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", () => {