Skip to content

Commit

Permalink
#Fix 9056 fixed content type for JSON content in put request (#9095) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Apr 18, 2023
1 parent 8466fb7 commit 0ae5b07
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
},
Expand Down
36 changes: 36 additions & 0 deletions web/client/api/__tests__/GeoStoreDAO-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 0ae5b07

Please sign in to comment.