Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2023.01.xx] Fix #9056 fixed content type for JSON content in put request (#9095) #9108

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});