From 0ae5b07ddd7cc9ab9f166a303da0d170efd36087 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Tue, 18 Apr 2023 12:30:29 +0200 Subject: [PATCH] #Fix 9056 fixed content type for JSON content in put request (#9095) (#9108) --- web/client/api/GeoStoreDAO.js | 2 +- web/client/api/__tests__/GeoStoreDAO-test.jsx | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/web/client/api/GeoStoreDAO.js b/web/client/api/GeoStoreDAO.js index e193fae2af..9b227fcf86 100644 --- a/web/client/api/GeoStoreDAO.js +++ b/web/client/api/GeoStoreDAO.js @@ -292,7 +292,7 @@ const Api = { content, this.addBaseUrl(merge({ headers: { - 'Content-Type': typeof content === 'string' ? "text/plain; charset=utf-8" : 'application/json; charset=utf-8"' + 'Content-Type': typeof content === 'string' ? "text/plain; charset=utf-8" : 'application/json; charset=utf-8' } }, options))); }, diff --git a/web/client/api/__tests__/GeoStoreDAO-test.jsx b/web/client/api/__tests__/GeoStoreDAO-test.jsx index 71d56d91c9..396e61189d 100644 --- a/web/client/api/__tests__/GeoStoreDAO-test.jsx +++ b/web/client/api/__tests__/GeoStoreDAO-test.jsx @@ -385,4 +385,40 @@ describe('Test correctness of the GeoStore APIs', () => { done(e); }); }); + it('putResource with string data', (done) => { + // check the request contains the correct data and headers + mockAxios.onPut().reply((data) => { + expect(data.baseURL).toEqual("/rest/geostore/"); + expect(data.url).toEqual("data/1"); + expect(data.data).toEqual("data"); + expect(data.headers["Content-Type"]).toEqual("text/plain; charset=utf-8"); + return [200, "10"]; + }); + API.putResource(1, "data").then(data => { + expect(data.data).toEqual("10"); + done(); + }).catch(e => { + done(e); + }); + }); + it('putResource with json data', (done) => { + // check the request contains the correct data and headers + mockAxios.onPut().reply((data) => { + try { + expect(data.baseURL).toEqual("/rest/geostore/"); + expect(data.url).toEqual("data/1"); + expect(data.data).toEqual('{"some":"thing"}'); + expect(data.headers["Content-Type"]).toEqual("application/json; charset=utf-8"); + } catch (e) { + done(e); + } + return [200, "10"]; + }); + API.putResource(1, {"some": "thing"}).then(data => { + expect(data.data).toEqual("10"); + done(); + }).catch(e => { + done(e); + }); + }); });